Skip to content

Commit af7776b

Browse files
author
Go MergeUpstream
committed
Merge commit '445bdae0f00d2054f683d68c4d3c2de3d7924a7c' into catalyst-main
2 parents 181efed + 445bdae commit af7776b

File tree

10 files changed

+641
-78
lines changed

10 files changed

+641
-78
lines changed

.github/workflows/ci.yml

Lines changed: 146 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
name: Moodle Plugin CI
22

3-
on: [push, pull_request]
4-
3+
# Automatically triggered on push to main branch, on pull requests
4+
on: ['push', 'pull_request']
55
jobs:
66
test:
77
runs-on: ubuntu-latest
88

99
services:
1010
postgres:
11-
image: postgres:13
11+
image: postgres:17
1212
env:
1313
POSTGRES_USER: "postgres"
1414
POSTGRES_HOST_AUTH_METHOD: "trust"
@@ -18,129 +18,205 @@ jobs:
1818

1919
strategy:
2020
fail-fast: false
21+
2122
matrix:
22-
php: ["7.4", "8.0", 8.1', "8.2", "8.3"]
23-
moodle-branch:
23+
php: ["7.4", "8.0", "8.1", "8.2", "8.3", "8.4"]
24+
moodle_branch:
2425
[
2526
"MOODLE_401_STABLE",
2627
"MOODLE_402_STABLE",
2728
"MOODLE_403_STABLE",
2829
"MOODLE_404_STABLE",
30+
"MOODLE_405_STABLE",
31+
"MOODLE_500_STABLE",
32+
"MOODLE_501_STABLE",
2933
"main",
3034
]
3135
database: [pgsql]
36+
browser: ["chrome", "firefox"]
3237
exclude:
3338
# Exclude Moodle+PHP incompatible versions
34-
# See: https://moodledev.io/general/development/policies/php
35-
- moodle-branch: "MOODLE_401_STABLE"
36-
php: "8.2"
37-
- moodle-branch: "MOODLE_401_STABLE"
38-
php: "8.3"
39-
- moodle-branch: "MOODLE_402_STABLE"
39+
# See: https://docs.moodle.org/dev/Moodle_and_PHP
40+
41+
- moodle_branch: "MOODLE_402_STABLE"
4042
php: "7.4"
41-
- moodle-branch: "MOODLE_402_STABLE"
42-
php: "8.3"
43-
- moodle-branch: "MOODLE_403_STABLE"
43+
- moodle_branch: "MOODLE_403_STABLE"
4444
php: "7.4"
45-
- moodle-branch: "MOODLE_403_STABLE"
46-
php: "8.3"
47-
- moodle-branch: "MOODLE_404_STABLE"
45+
- moodle_branch: "MOODLE_404_STABLE"
46+
php: "7.4"
47+
- moodle_branch: "MOODLE_405_STABLE"
48+
php: "7.4"
49+
- moodle_branch: "MOODLE_500_STABLE"
4850
php: "7.4"
49-
- moodle-branch: "MOODLE_404_STABLE"
51+
- moodle_branch: "MOODLE_501_STABLE"
52+
php: "7.4"
53+
54+
55+
- moodle_branch: "MOODLE_404_STABLE"
5056
php: "8.0"
51-
- moodle-branch: "main"
57+
- moodle_branch: "MOODLE_405_STABLE"
58+
php: "8.0"
59+
- moodle_branch: "MOODLE_500_STABLE"
60+
php: "8.0"
61+
- moodle_branch: "MOODLE_501_STABLE"
62+
php: "8.0"
63+
64+
- moodle_branch: "MOODLE_500_STABLE"
65+
php: "8.1"
66+
- moodle_branch: "MOODLE_501_STABLE"
67+
php: "8.1"
68+
69+
- moodle_branch: "MOODLE_401_STABLE"
70+
php: "8.2"
71+
72+
- moodle_branch: "MOODLE_401_STABLE"
73+
php: "8.3"
74+
- moodle_branch: "MOODLE_402_STABLE"
75+
php: "8.3"
76+
- moodle_branch: "MOODLE_403_STABLE"
77+
php: "8.3"
78+
79+
- moodle_branch: "MOODLE_401_STABLE"
80+
php: "8.4"
81+
- moodle_branch: "MOODLE_402_STABLE"
82+
php: "8.4"
83+
- moodle_branch: "MOODLE_403_STABLE"
84+
php: "8.4"
85+
- moodle_branch: "MOODLE_404_STABLE"
86+
php: "8.4"
87+
- moodle_branch: "MOODLE_405_STABLE"
88+
php: "8.4"
89+
90+
- moodle_branch: "main"
91+
92+
5293
include:
5394
# Only test master against latest PHP until we know which
5495
# versions are supported in the next release
55-
- moodle-branch: "main"
56-
php: "8.3"
96+
- moodle_branch: "main"
97+
php: "8.4"
5798
database: "pgsql"
99+
continue-on-error: ${{ matrix.branch == 'main' }}
58100

59101
steps:
60102
- name: Check out repository code
61103
uses: actions/checkout@v4
62104
with:
63105
path: plugin
64106

107+
# 0.1 Detect branch name based on event type.
108+
- name: Set branch name
109+
id: get_branch
110+
run: |
111+
if [ "${{ github.event_name }}" == "pull_request" ]; then
112+
echo "BRANCH_NAME=${{ github.head_ref }}" >> $GITHUB_ENV
113+
else
114+
echo "BRANCH_NAME=${{ github.ref_name }}" >> $GITHUB_ENV
115+
fi
116+
117+
# 0.2 Log current matrix info.
118+
- name: Log info
119+
run: |
120+
echo "PHP: ${{ matrix.php }}"
121+
echo "Moodle: ${{ matrix.moodle_branch }}"
122+
echo "Browser: ${{ matrix.browser }}"
123+
echo "Branch: ${{ env.BRANCH_NAME }}"
124+
125+
# 0.3 Cache Composer for faster builds.
126+
- name: Cache Composer dependencies
127+
uses: actions/cache@v3
128+
with:
129+
path: |
130+
${{ github.workspace }}/.composer/cache
131+
${{ github.workspace }}/.npm
132+
key: ${{ runner.os }}-composer-${{ matrix.php }}-${{ matrix.moodle_branch }}
133+
restore-keys: ${{ runner.os }}-composer-${{ matrix.php }}-${{ matrix.moodle_branch }}
134+
135+
# 1. Setup PHP for the current matrix.
65136
- name: Setup PHP ${{ matrix.php }}
66137
uses: shivammathur/setup-php@v2
67138
with:
68139
php-version: ${{ matrix.php }}
69140
extensions: ${{ matrix.extensions }}
70-
ini-values: max_input_vars=5000
71-
# If you are not using code coverage, keep "none". Otherwise, use "pcov" (Moodle 3.10 and up) or "xdebug".
72-
# If you try to use code coverage with "none", it will fallback to phpdbg (which has known problems).
141+
ini-values: max_input_vars=10000
73142
coverage: none
74143

144+
# 2. Install moodle-plugin-ci tool.
75145
- name: Initialise moodle-plugin-ci
76146
run: |
77147
composer create-project -n --no-dev --prefer-dist moodlehq/moodle-plugin-ci ci ^4
78148
echo $(cd ci/bin; pwd) >> $GITHUB_PATH
79149
echo $(cd ci/vendor/bin; pwd) >> $GITHUB_PATH
80150
sudo locale-gen en_AU.UTF-8
81-
echo "NVM_DIR=$HOME/.nvm" >> $GITHUB_ENV
151+
echo NVM_DIR=$NVM_DIR >> $GITHUB_ENV
152+
env:
153+
IGNORE_PATHS: classes/privacy,ignore,node_modules,integration,render
154+
COVERAGE: false
155+
CODECHECKER_IGNORE_PATHS: classes/privacy,ignore,node_modules,integration,render
156+
PHPUNIT_IGNORE_PATHS: classes/privacy,ignore,node_modules,integration,render
82157

158+
# 3. Install filter
83159
- name: Add Wiris filter
84160
run: |
85161
moodle-plugin-ci add-plugin wiris/moodle-filter_wiris
86-
162+
# 3.5. Install Wiris Quizzes plugin.
163+
- name: Add Wiris Quizzes plugin
164+
id: install-plugin-quizzes
165+
if: ${{ always() }}
166+
continue-on-error: true
167+
run: |
168+
moodle-plugin-ci add-plugin --branch test/rework-e2e-tests wiris/moodle-qtype_truefalsewiris
169+
moodle-plugin-ci add-plugin --branch test/rework-e2e-tests wiris/moodle-qtype_shortanswerwiris
170+
moodle-plugin-ci add-plugin --branch test/rework-e2e-tests wiris/moodle-qtype_multichoicewiris
171+
moodle-plugin-ci add-plugin --branch test/rework-e2e-tests wiris/moodle-qtype_multianswerwiris
172+
moodle-plugin-ci add-plugin --branch test/rework-e2e-tests wiris/moodle-qtype_matchwiris
173+
moodle-plugin-ci add-plugin --branch test/rework-e2e-tests wiris/moodle-qtype_essaywiris
174+
- name: Add Wiris Quizzes plugin using the main branch
175+
if: ${{ steps.install-plugin-quizzes.outcome != 'success' }}
176+
run: |
177+
moodle-plugin-ci add-plugin --branch main wiris/moodle-qtype_truefalsewiris
178+
moodle-plugin-ci add-plugin --branch main wiris/moodle-qtype_shortanswerwiris
179+
moodle-plugin-ci add-plugin --branch main wiris/moodle-qtype_multichoicewiris
180+
moodle-plugin-ci add-plugin --branch main wiris/moodle-qtype_multianswerwiris
181+
moodle-plugin-ci add-plugin --branch main wiris/moodle-qtype_matchwiris
182+
moodle-plugin-ci add-plugin --branch main wiris/moodle-qtype_essaywiris
183+
# 4. Install plugin and configure DB.
87184
- name: Install moodle-plugin-ci
88185
run: moodle-plugin-ci install --plugin ./plugin --db-host=127.0.0.1
89186
env:
90187
DB: ${{ matrix.database }}
91-
MOODLE_BRANCH: ${{ matrix.moodle-branch }}
188+
MOODLE_BRANCH: ${{ matrix.moodle_branch }}
92189

93-
- name: PHP Lint
94-
if: ${{ !cancelled() }}
95-
run: moodle-plugin-ci phplint
96-
97-
- name: PHP Mess Detector
98-
continue-on-error: true # This step will show errors but will not fail
99-
if: ${{ !cancelled() }}
100-
run: moodle-plugin-ci phpmd
101-
102-
- name: Moodle Code Checker
103-
if: ${{ !cancelled() }}
104-
run: moodle-plugin-ci phpcs --max-warnings 0
105-
106-
- name: Moodle PHPDoc Checker
107-
if: ${{ !cancelled() }}
108-
run: moodle-plugin-ci phpdoc --max-warnings 0
190+
# 5. Run PHPUnit tests.
191+
- name: PHPUnit tests
192+
if: ${{ always() }}
193+
run: moodle-plugin-ci phpunit ./plugin
194+
continue-on-error: true
109195

196+
# 5.1 Run Moodle code validation.
110197
- name: Validating
111-
if: ${{ !cancelled() }}
112-
run: moodle-plugin-ci validate
113-
114-
- name: Check upgrade savepoints
115-
if: ${{ !cancelled() }}
116-
run: moodle-plugin-ci savepoints
117-
118-
- name: Mustache Lint
119-
if: ${{ !cancelled() }}
120-
run: moodle-plugin-ci mustache
198+
if: ${{ always() }}
199+
run: moodle-plugin-ci validate ./plugin
200+
continue-on-error: true
121201

122-
- name: Grunt
123-
if: ${{ !cancelled() }}
124-
run: moodle-plugin-ci grunt --max-lint-warnings 0
125-
126-
- name: PHPUnit tests
127-
if: ${{ !cancelled() }}
128-
run: moodle-plugin-ci phpunit --fail-on-warning
129-
130-
- name: Behat features
202+
# 6. Run Behat tests.
203+
- name: Behat features for ( ${{ matrix.moodle_branch }} on PHP ${{ matrix.php }} )
131204
id: behat
132-
if: ${{ !cancelled() }}
133-
run: moodle-plugin-ci behat --profile chrome
134-
205+
run: |
206+
case "${{ matrix.moodle_branch }}" in
207+
"MOODLE_401_STABLE"|"MOODLE_402_STABLE"|"MOODLE_403_STABLE"|"MOODLE_404_STABLE"|"MOODLE_405_STABLE"|"MOODLE_500_STABLE"|"MOODLE_501_STABLE"|"main")
208+
TAG="@qtype_wq"
209+
;;
210+
esac
211+
moodle-plugin-ci behat --tags=$TAG --profile ${{ matrix.browser }} --auto-rerun=2 --verbose -vvv
212+
213+
# 6.1 Upload Behat fail dumps when errors occur.
135214
- name: Upload Behat Faildump
136215
if: ${{ failure() && steps.behat.outcome == 'failure' }}
137216
uses: actions/upload-artifact@v4
138217
with:
139-
name: Behat Faildump (${{ join(matrix.*, ', ') }})
218+
name: Behat Faildump (${{ matrix.php }}, ${{ matrix.moodle_branch }}, ${{ matrix.browser }})
140219
path: ${{ github.workspace }}/moodledata/behat_dump
141-
retention-days: 7
220+
retention-days: 1
142221
if-no-files-found: ignore
143222

144-
- name: Mark cancelled jobs as failed.
145-
if: ${{ cancelled() }}
146-
run: exit 1

renderer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class qtype_wq_renderer extends qtype_renderer {
2121

2222
protected $base;
2323

24-
public function __construct(?qtype_renderer $base = null, moodle_page $page, $target) {
24+
public function __construct(qtype_renderer $base, moodle_page $page, $target) {
2525
parent::__construct($page, $target);
2626
$this->base = $base;
2727
}

tests/behat/behat_qtype_wq.php

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
3+
use Behat\Behat\Context\Step\Given;
4+
use Behat\Behat\Context\Step\When;
5+
use Behat\Behat\Context\Step\Then;
6+
use Behat\Gherkin\Node\TableNode;
7+
8+
/**
9+
* Steps definitions related to qtype_wq.
10+
*/
11+
class behat_qtype_wq extends behat_base {
12+
13+
/**
14+
* @Given I open the action menu for :elementtype :identifier
15+
*/
16+
public function i_open_the_action_menu_for($elementtype, $identifier) {
17+
// Find the action menu button for the specified element
18+
$xpath = "//div[contains(@class, '{$elementtype}') and contains(., '{$identifier}')]//button[contains(@class, 'action-menu-trigger')]";
19+
20+
$this->execute('behat_general::i_click_on', [$xpath, 'xpath_element']);
21+
}
22+
23+
/**
24+
* @Then I should see :count elements matching :selector
25+
*/
26+
public function i_should_see_elements_matching($count, $selector) {
27+
// Convert count to integer
28+
$expectedcount = (int)$count;
29+
30+
// Find elements matching the selector
31+
$elements = $this->find_all('css_element', $selector);
32+
33+
if (count($elements) !== $expectedcount) {
34+
$session = $this->getSession();
35+
$currentUrl = $session->getCurrentUrl();
36+
37+
throw new Exception(
38+
"Expected {$expectedcount} elements matching '{$selector}', but found " . count($elements) .
39+
". Current URL: {$currentUrl}"
40+
);
41+
}
42+
}
43+
}

tests/behat/behat_wq_base.php

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,8 @@ public function i_should_have_a_readonly_input() {
101101
$session = $this->getSession();
102102
$readonly = $session->getPage()->find('css', '.wrsUI_readOnly');
103103
if (empty($readonly)) {
104-
throw new Exception('Readonly field not found.');
104+
$currentUrl = $session->getCurrentUrl();
105+
throw new Exception("Readonly field not found. Current URL: {$currentUrl}");
105106
}
106107
}
107108

@@ -121,9 +122,10 @@ public function i_add_the_variable_with_value($varname, $value) {
121122
*/
122123
public function feedback_should_exist() {
123124
$session = $this->getSession();
124-
$readonly = $session->getPage()->find('css', '.feedback');
125-
if (empty($readonly)) {
126-
throw new Exception('Readonly field not found.');
125+
$feedback = $session->getPage()->find('css', '.feedback');
126+
if (empty($feedback)) {
127+
$currentUrl = $session->getCurrentUrl();
128+
throw new Exception("Feedback element not found. Current URL: {$currentUrl}");
127129
}
128130
}
129131

@@ -132,9 +134,10 @@ public function feedback_should_exist() {
132134
*/
133135
public function generalfeedback_should_exist() {
134136
$session = $this->getSession();
135-
$readonly = $session->getPage()->find('css', '.generalfeedback');
136-
if (empty($readonly)) {
137-
throw new Exception('Readonly field not found.');
137+
$generalfeedback = $session->getPage()->find('css', '.generalfeedback');
138+
if (empty($generalfeedback)) {
139+
$currentUrl = $session->getCurrentUrl();
140+
throw new Exception("General feedback element not found. Current URL: {$currentUrl}");
138141
}
139142
}
140143

0 commit comments

Comments
 (0)