From 0e248ed76eaf67977f7a9e41e7bbe32b87facadb Mon Sep 17 00:00:00 2001 From: Edmund Farrow Date: Wed, 6 Mar 2024 09:59:23 +0000 Subject: [PATCH 01/12] github-workflow - First pass of CI --- .github/workflows/moodle-ci.yml | 145 ++++++++++++++++++++++++++++++++ 1 file changed, 145 insertions(+) create mode 100644 .github/workflows/moodle-ci.yml diff --git a/.github/workflows/moodle-ci.yml b/.github/workflows/moodle-ci.yml new file mode 100644 index 0000000..b32adaf --- /dev/null +++ b/.github/workflows/moodle-ci.yml @@ -0,0 +1,145 @@ +name: Moodle Plugin CI + +on: [push, pull_request] + +jobs: + test: + runs-on: ubuntu-22.04 + + services: + postgres: + image: postgres:13 + env: + POSTGRES_USER: 'postgres' + POSTGRES_HOST_AUTH_METHOD: 'trust' + ports: + - 5432:5432 + options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 3 + mariadb: + image: mariadb:10.6 + env: + MYSQL_USER: 'root' + MYSQL_ALLOW_EMPTY_PASSWORD: "true" + MYSQL_CHARACTER_SET_SERVER: "utf8mb4" + MYSQL_COLLATION_SERVER: "utf8mb4_unicode_ci" + + ports: + - 3306:3306 + options: --health-cmd="mysqladmin ping" --health-interval 10s --health-timeout 5s --health-retries 3 + + strategy: + fail-fast: false + matrix: # I don't know why, but mariadb is much slower, so mostly use pgsql. + # We use a mix of SBCL and GCL, but mostly prefer SBCL as it is faster. + include: + - php: '8.2' + moodle-branch: 'master' + database: 'pgsql' + maxima: 'SBCL' + - php: '8.1' + moodle-branch: 'MOODLE_402_STABLE' + database: 'pgsql' + maxima: 'GCL' + - php: '8.0' + moodle-branch: 'MOODLE_402_STABLE' + database: 'pgsql' + maxima: 'SBCL' + # Edinburgh is planning to run the setup below for 2023-24. + - php: '7.4' + moodle-branch: 'MOODLE_401_STABLE' + database: 'mariadb' + maxima: 'GCL' + - php: '7.4' + moodle-branch: 'MOODLE_400_STABLE' + database: 'pgsql' + maxima: 'SBCL' + - php: '7.3' + moodle-branch: 'MOODLE_311_STABLE' + database: 'pgsql' + maxima: 'SBCL' + - php: '7.2' + moodle-branch: 'MOODLE_39_STABLE' + database: 'pgsql' + maxima: 'SBCL' + + steps: + - name: Check out repository code + uses: actions/checkout@v3 + with: + path: plugin + + - name: Setup PHP ${{ matrix.php }} + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php }} + extensions: ${{ matrix.extensions }} + ini-values: max_input_vars=5000 + coverage: none + + - name: Initialise moodle-plugin-ci + run: | + composer create-project -n --no-dev --prefer-dist moodlehq/moodle-plugin-ci ci ^3 + echo $(cd ci/bin; pwd) >> $GITHUB_PATH + echo $(cd ci/vendor/bin; pwd) >> $GITHUB_PATH + sudo locale-gen en_AU.UTF-8 + echo "NVM_DIR=$HOME/.nvm" >> $GITHUB_ENV + + - name: Install moodle-plugin-ci + run: | + moodle-plugin-ci add-plugin maths/moodle-qbehaviour_dfexplicitvaildate + moodle-plugin-ci add-plugin maths/moodle-qbehaviour_dfcbmexplicitvaildate + moodle-plugin-ci add-plugin maths/moodle-qbehaviour_adaptivemultipart + moodle-plugin-ci add-plugin maths/moodle-qformat_stack + moodle-plugin-ci add-plugin maths/moodle-qbank_importasversion + + moodle-plugin-ci install --plugin ./plugin --db-host=127.0.0.1 + + #cat ${{ github.workspace }}/moodle/config.php + + env: + DB: ${{ matrix.database }} + MOODLE_BRANCH: ${{ matrix.moodle-branch }} + + - name: PHP Lint + if: ${{ always() }} + run: moodle-plugin-ci phplint + + - name: PHP Copy/Paste Detector + continue-on-error: true # This step will show errors but will not fail. + if: ${{ always() }} + run: moodle-plugin-ci phpcpd + + - name: PHP Mess Detector + continue-on-error: true # This step will show errors but will not fail. + if: ${{ always() }} + run: moodle-plugin-ci phpmd + + - name: Moodle Code Checker + continue-on-error: true # Currently fails. We really ought to get this passing. + if: ${{ always() }} + run: moodle-plugin-ci codechecker --max-warnings 0 + + - name: Moodle PHPDoc Checker + continue-on-error: true # Currently fails. We really ought to get this passing. + if: ${{ always() }} + run: moodle-plugin-ci phpdoc + + - name: Validating + if: ${{ always() }} + run: moodle-plugin-ci validate + + - name: Check upgrade savepoints + if: ${{ always() }} + run: moodle-plugin-ci savepoints + + - name: Mustache Lint + if: ${{ always() }} + run: moodle-plugin-ci mustache + + - name: Grunt + if: ${{ matrix.moodle-branch == 'MOODLE_401_STABLE' }} + run: moodle-plugin-ci grunt + + - name: PHPUnit tests + if: ${{ always() }} + run: moodle-plugin-ci phpunit From 91534db584fa907080fd58c2ced447775fa372aa Mon Sep 17 00:00:00 2001 From: Edmund Farrow Date: Wed, 6 Mar 2024 10:13:55 +0000 Subject: [PATCH 02/12] github-workflow - remove importasversion --- .github/workflows/moodle-ci.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/moodle-ci.yml b/.github/workflows/moodle-ci.yml index b32adaf..2880c2b 100644 --- a/.github/workflows/moodle-ci.yml +++ b/.github/workflows/moodle-ci.yml @@ -90,7 +90,6 @@ jobs: moodle-plugin-ci add-plugin maths/moodle-qbehaviour_dfcbmexplicitvaildate moodle-plugin-ci add-plugin maths/moodle-qbehaviour_adaptivemultipart moodle-plugin-ci add-plugin maths/moodle-qformat_stack - moodle-plugin-ci add-plugin maths/moodle-qbank_importasversion moodle-plugin-ci install --plugin ./plugin --db-host=127.0.0.1 From 42deeaec708c4360bde6bdce1370a5e4acbef26b Mon Sep 17 00:00:00 2001 From: Edmund Farrow Date: Wed, 6 Mar 2024 10:34:04 +0000 Subject: [PATCH 03/12] github-workflow - Remove Moodle 3, add back import, try stack fix --- .github/workflows/moodle-ci.yml | 14 +------------- tests/external/delete_question_test.php | 2 +- 2 files changed, 2 insertions(+), 14 deletions(-) diff --git a/.github/workflows/moodle-ci.yml b/.github/workflows/moodle-ci.yml index 2880c2b..c203fd9 100644 --- a/.github/workflows/moodle-ci.yml +++ b/.github/workflows/moodle-ci.yml @@ -35,32 +35,19 @@ jobs: - php: '8.2' moodle-branch: 'master' database: 'pgsql' - maxima: 'SBCL' - php: '8.1' moodle-branch: 'MOODLE_402_STABLE' database: 'pgsql' - maxima: 'GCL' - php: '8.0' moodle-branch: 'MOODLE_402_STABLE' database: 'pgsql' - maxima: 'SBCL' # Edinburgh is planning to run the setup below for 2023-24. - php: '7.4' moodle-branch: 'MOODLE_401_STABLE' database: 'mariadb' - maxima: 'GCL' - php: '7.4' moodle-branch: 'MOODLE_400_STABLE' database: 'pgsql' - maxima: 'SBCL' - - php: '7.3' - moodle-branch: 'MOODLE_311_STABLE' - database: 'pgsql' - maxima: 'SBCL' - - php: '7.2' - moodle-branch: 'MOODLE_39_STABLE' - database: 'pgsql' - maxima: 'SBCL' steps: - name: Check out repository code @@ -90,6 +77,7 @@ jobs: moodle-plugin-ci add-plugin maths/moodle-qbehaviour_dfcbmexplicitvaildate moodle-plugin-ci add-plugin maths/moodle-qbehaviour_adaptivemultipart moodle-plugin-ci add-plugin maths/moodle-qformat_stack + moodle-plugin-ci add-plugin maths/moodle-qbank_importasversion moodle-plugin-ci install --plugin ./plugin --db-host=127.0.0.1 diff --git a/tests/external/delete_question_test.php b/tests/external/delete_question_test.php index 2b5c793..a81cc71 100644 --- a/tests/external/delete_question_test.php +++ b/tests/external/delete_question_test.php @@ -69,7 +69,7 @@ public function setUp(): void { $user = $this->getDataGenerator()->create_user(); $this->user = $user; $this->setUser($user); - $this->q = $this->generator->create_question('stack', 'test3', + $this->q = $this->generator->create_question('shortanswer', null, ['name' => self::QNAME, 'category' => $this->qcategory->id]); $this->qbankentryid = $DB->get_field('question_versions', 'questionbankentryid', ['questionid' => $this->q->id], $strictness = MUST_EXIST); From 4d8ec956afdb2a1fc8e395e3984cdbd0a405e228 Mon Sep 17 00:00:00 2001 From: Edmund Farrow Date: Wed, 6 Mar 2024 11:03:15 +0000 Subject: [PATCH 04/12] github-workflow - remove STACK from tests Users might not have STACK! --- .github/workflows/moodle-ci.yml | 4 - testrepo/top/cat-1/First-Question.xml | 102 +------- testrepo/top/cat-2/Second-Question.xml | 231 +----------------- .../top/cat-2/subcat-2_1/Fourth-Question.xml | 181 +------------- .../top/cat-2/subcat-2_1/Third-Question.xml | 181 +------------- tests/external/delete_question_test.php | 3 +- tests/external/export_question_test.php | 4 +- tests/external/get_question_list_test.php | 14 +- tests/external/import_question_test.php | 4 +- 9 files changed, 51 insertions(+), 673 deletions(-) diff --git a/.github/workflows/moodle-ci.yml b/.github/workflows/moodle-ci.yml index c203fd9..80b3d4e 100644 --- a/.github/workflows/moodle-ci.yml +++ b/.github/workflows/moodle-ci.yml @@ -73,10 +73,6 @@ jobs: - name: Install moodle-plugin-ci run: | - moodle-plugin-ci add-plugin maths/moodle-qbehaviour_dfexplicitvaildate - moodle-plugin-ci add-plugin maths/moodle-qbehaviour_dfcbmexplicitvaildate - moodle-plugin-ci add-plugin maths/moodle-qbehaviour_adaptivemultipart - moodle-plugin-ci add-plugin maths/moodle-qformat_stack moodle-plugin-ci add-plugin maths/moodle-qbank_importasversion moodle-plugin-ci install --plugin ./plugin --db-host=127.0.0.1 diff --git a/testrepo/top/cat-1/First-Question.xml b/testrepo/top/cat-1/First-Question.xml index ae6c7c3..6dc5625 100644 --- a/testrepo/top/cat-1/First-Question.xml +++ b/testrepo/top/cat-1/First-Question.xml @@ -1,109 +1,25 @@ - - + First Question -

Differentiate \((x-1)^3\) with respect to x.

[[input:ans1]] [[validation:ans1]]

]]>
+ This is a test question.

]]>
1 - 0.1 + 0.3333333 0 - - 2023072101 - - - - - - [[feedback:prt1]] - - - - - - - - 1 - 0 - 0 - - Correct answer, well done.]]> - - - Your answer is partially correct.]]> - - - Incorrect answer.]]> - - dot - 1 - i - cos-1 - lang - [ - - - ans1 - algebraic - 3*(x-1)^2 - 15 - 1 - 0 - - 0 - - - 1 - 0 - 0 - 1 - 1 - - - - prt1 - 1.0000000 - 1 - 1 - + 0 + + This is a test answer. + - - - 0 - - AlgEquiv - ans1 - 3*(x-1)^2 - - 0 - = - 1 - - -1 - prt1-1-T - - - - = - 0 - - -1 - prt1-1-F - - - - - - - tag1 - tag2 - + +
\ No newline at end of file diff --git a/testrepo/top/cat-2/Second-Question.xml b/testrepo/top/cat-2/Second-Question.xml index d829859..e8c73b0 100644 --- a/testrepo/top/cat-2/Second-Question.xml +++ b/testrepo/top/cat-2/Second-Question.xml @@ -1,238 +1,25 @@ - - + Second Question -

Find the equation of the line tangent to {@exp@} at the point \(x={@pt@}\).

1. Differentiate {@exp@} with respect to \(x\). [[input:ans1]] [[validation:ans1]] [[feedback:prt1]]

2. Evaluate your derivative at \(x={@pt@}\). [[input:ans2]] [[validation:ans2]] [[feedback:prt2]]

3. Hence, find the equation of the tangent line. \(y=\)[[input:ans3]] [[validation:ans3]] [[feedback:prt3]]

]]>
+ This is a test question.

]]>
1 - 0.1 + 0.3333333 0 - - 2023060600 - - - exp:x^3-2*x^2+x; - pt:2; - ta1:diff(exp,x); - ta2:subst(x=pt,ta1); - ta3:remainder(exp,(x-pt)^2); - - - - - - - - - - - 1 - 0 - 0 - - Correct answer, well done.]]> - - - Your answer is partially correct.]]> - - - Incorrect answer.]]> - - dot - 1 - i - cos-1 - lang - [ - - - ans1 - algebraic - ta1 - 15 - 1 - 0 - - 0 - - - 1 - 0 - 0 - 1 - 1 - - - - ans2 - algebraic - ta2 - 15 - 1 - 0 - - 0 - - - 1 - 0 - 0 - 1 - 1 - - - - ans3 - algebraic - ta3 - 15 - 1 - 0 - - 0 - - - 1 - 0 - 0 - 1 - 1 - - - - prt1 - 1.0000000 - 1 - 1 - - - - - 0 - - AlgEquiv - ans1 - ta1 - - 0 - = - 1 - - -1 - prt1-1-T - - - - = - 0 - - -1 - prt1-1-F - - - - - - - prt2 - 1.0000000 - 1 - 1 - - - - - 0 - - AlgEquiv - ans2 - subst(x=pt,ans1) - - 0 - = - 0 - - 1 - prt2-1-T - - - - = - 0 - - -1 - prt2-1-F - - - - - - 1 - - AlgEquiv - ans1 - ta1 - - 0 - + - 1 - - -1 - prt2-2-T - - - - - - 0 - - -1 - prt2-2-F - - You have correctly evaluated your answer to part 1 at the given point, but your answer to part 1 is wrong. Please try both parts again.

]]>
-
-
-
- - prt3 - 1.0000000 - 1 - 1 - + 0 + + This is a test answer. + - - - 0 - - AlgEquiv - ans3 - ta3 - - 0 - = - 1 - - -1 - prt3-1-T - - - - = - 0 - - -1 - prt3-1-F - - - - - + +
\ No newline at end of file diff --git a/testrepo/top/cat-2/subcat-2_1/Fourth-Question.xml b/testrepo/top/cat-2/subcat-2_1/Fourth-Question.xml index cff375f..3dc2420 100644 --- a/testrepo/top/cat-2/subcat-2_1/Fourth-Question.xml +++ b/testrepo/top/cat-2/subcat-2_1/Fourth-Question.xml @@ -1,186 +1,25 @@ - - + Fourth Question -

Find \(\int{@exp@} \mathrm{d}x\)

[[input:ans1]] [[validation:ans1]]

]]>
+ This is a test question.

]]>
- This is some general feedback!

]]>
+
1 - 0.1 + 0.3333333 0 - - 2023060600 - - - a1 : 1+rand(6); -a2 : 1+rand(6); -nn : 3+rand(4); -exp : a1*(x-a2)^(-nn); -ta: int(exp, x)+c; - - - [[feedback:prt1]] - - - \[ \int {@exp@} \mathrm{d}x = {@ta@}.\] - - - - - 1 - 0 - 0 - - Correct answer, well done.]]> - - - Your answer is partially correct.]]> - - - Incorrect answer.]]> - - dot - 1 - i - cos-1 - lang - [ - - - ans1 - algebraic - ta - 15 - 1 - 0 - - 0 - int - - 1 - 0 - 0 - 1 - 1 - - - - prt1 - 1.0000000 - 1 - 1 - + 0 + + This is a test answer. + - - - 0 - - Int - ans1 - ta - x - 0 - = - 1 - - 1 - prt1-1-T - - - - = - 0 - - -1 - prt1-1-F - - - - - - 1 - - FacForm - strip_int_const(ans1,x) - strip_int_const(ans1,x) - x - 1 - + - 0 - - -1 - prt1-2-T - - - - - - 0 - - -1 - prt1-2-F - - Your answer is not factored. Well done for getting the correct answer, but remember that there is no need to expand out the brackets.

]]>
-
-
-
- 114580660 - 799651125 - 1546415685 - 399724897 - 1347328446 - 1982854717 - 1847432841 - 247588230 - 116688922 - 1300343313 - - 1 - Test case assuming the teacher's input gets full marks. - - ans1 - ta - - - prt1 - 1.0000000 - 0.0000000 - prt1-2-T - - - - 2 - No constant - - ans1 - int(exp,x) - - - prt1 - 0.0000000 - 0.1000000 - prt1-1-F - - - - 3 - - - ans1 - (a1*(-nn+1))*(x-a2)^(-nn+1)+c - - - prt1 - 0.0000000 - 0.1000000 - prt1-1-F - - + +
\ No newline at end of file diff --git a/testrepo/top/cat-2/subcat-2_1/Third-Question.xml b/testrepo/top/cat-2/subcat-2_1/Third-Question.xml index 997b055..8fb6011 100644 --- a/testrepo/top/cat-2/subcat-2_1/Third-Question.xml +++ b/testrepo/top/cat-2/subcat-2_1/Third-Question.xml @@ -1,186 +1,25 @@ - - + Third Question -

Find \(\int{@exp@} \mathrm{d}x\)

[[input:ans1]] [[validation:ans1]]

]]>
+ This is a test question.

]]>
- This is some general feedback!

]]>
+
1 - 0.1 + 0.3333333 0 - - 2023060600 - - - a1 : 1+rand(6); -a2 : 1+rand(6); -nn : 3+rand(4); -exp : a1*(x-a2)^(-nn); -ta: int(exp, x)+c; - - - [[feedback:prt1]] - - - \[ \int {@exp@} \mathrm{d}x = {@ta@}.\] - - - - - 1 - 0 - 0 - - Correct answer, well done.]]> - - - Your answer is partially correct.]]> - - - Incorrect answer.]]> - - dot - 1 - i - cos-1 - lang - [ - - - ans1 - algebraic - ta - 15 - 1 - 0 - - 0 - int - - 1 - 0 - 0 - 1 - 1 - - - - prt1 - 1.0000000 - 1 - 1 - + 0 + + This is a test answer. + - - - 0 - - Int - ans1 - ta - x - 0 - = - 1 - - 1 - prt1-1-T - - - - = - 0 - - -1 - prt1-1-F - - - - - - 1 - - FacForm - strip_int_const(ans1,x) - strip_int_const(ans1,x) - x - 1 - + - 0 - - -1 - prt1-2-T - - - - - - 0 - - -1 - prt1-2-F - - Your answer is not factored. Well done for getting the correct answer, but remember that there is no need to expand out the brackets.

]]>
-
-
-
- 114580660 - 799651125 - 1546415685 - 399724897 - 1347328446 - 1982854717 - 1847432841 - 247588230 - 116688922 - 1300343313 - - 1 - Test case assuming the teacher's input gets full marks. - - ans1 - ta - - - prt1 - 1.0000000 - 0.0000000 - prt1-2-T - - - - 2 - No constant - - ans1 - int(exp,x) - - - prt1 - 0.0000000 - 0.1000000 - prt1-1-F - - - - 3 - - - ans1 - (a1*(-nn+1))*(x-a2)^(-nn+1)+c - - - prt1 - 0.0000000 - 0.1000000 - prt1-1-F - - + +
\ No newline at end of file diff --git a/tests/external/delete_question_test.php b/tests/external/delete_question_test.php index a81cc71..2a93564 100644 --- a/tests/external/delete_question_test.php +++ b/tests/external/delete_question_test.php @@ -57,7 +57,7 @@ class delete_question_test extends externallib_advanced_testcase { /** @var \stdClass generated user object */ protected \stdClass $user; /** Name of question to be generated and deleted. */ - const QNAME = 'Example STACK question'; + const QNAME = 'Example short answer question'; public function setUp(): void { global $DB; @@ -78,6 +78,7 @@ public function setUp(): void { /** * Test the execute function when capabilities are present. + * @runInSeparateProcess */ public function test_capabilities(): void { global $DB; diff --git a/tests/external/export_question_test.php b/tests/external/export_question_test.php index a359b5b..752c364 100644 --- a/tests/external/export_question_test.php +++ b/tests/external/export_question_test.php @@ -57,7 +57,7 @@ class export_question_test extends externallib_advanced_testcase { /** @var \stdClass generated user object */ protected \stdClass $user; /** Name of question to be generated and exported. */ - const QNAME = 'Example STACK question'; + const QNAME = 'Example short answer question'; public function setUp(): void { global $DB; @@ -69,7 +69,7 @@ public function setUp(): void { $user = $this->getDataGenerator()->create_user(); $this->user = $user; $this->setUser($user); - $this->q = $this->generator->create_question('stack', 'test3', + $this->q = $this->generator->create_question('shortanswer', null, ['name' => self::QNAME, 'category' => $this->qcategory->id]); $this->qbankentryid = $DB->get_field('question_versions', 'questionbankentryid', ['questionid' => $this->q->id], $strictness = MUST_EXIST); diff --git a/tests/external/get_question_list_test.php b/tests/external/get_question_list_test.php index ccfee91..bae55f7 100644 --- a/tests/external/get_question_list_test.php +++ b/tests/external/get_question_list_test.php @@ -57,7 +57,7 @@ class get_question_list_test extends externallib_advanced_testcase { /** @var \stdClass generated user object */ protected \stdClass $user; /** Name of question to be generated and listed. */ - const QNAME = 'Example STACK question'; + const QNAME = 'Example short answer question'; public function setUp(): void { global $DB; @@ -69,7 +69,7 @@ public function setUp(): void { $user = $this->getDataGenerator()->create_user(); $this->user = $user; $this->setUser($user); - $this->q = $this->generator->create_question('stack', 'test3', + $this->q = $this->generator->create_question('shortanswer', null, ['name' => self::QNAME, 'category' => $this->qcategory->id]); $this->qbankentryid = $DB->get_field('question_versions', 'questionbankentryid', ['questionid' => $this->q->id], $strictness = MUST_EXIST); @@ -173,7 +173,7 @@ public function test_list(): void { role_assign($managerroleid, $this->user->id, $context->id); $qcategory2 = $this->generator->create_question_category( ['contextid' => \context_course::instance($this->course->id)->id]); - $q2 = $this->generator->create_question('stack', 'test3', + $q2 = $this->generator->create_question('shortanswer', null, ['name' => self::QNAME . '2', 'category' => $qcategory2->id]); $qbankentryid2 = $DB->get_field('question_versions', 'questionbankentryid', ['questionid' => $q2->id], $strictness = MUST_EXIST); @@ -222,7 +222,7 @@ public function test_list_instanceid(): void { role_assign($managerroleid, $this->user->id, $context->id); $qcategory2 = $this->generator->create_question_category( ['contextid' => \context_course::instance($this->course->id)->id]); - $q2 = $this->generator->create_question('stack', 'test3', + $q2 = $this->generator->create_question('shortanswer', null, ['name' => self::QNAME . '2', 'category' => $qcategory2->id]); $qbankentryid2 = $DB->get_field('question_versions', 'questionbankentryid', ['questionid' => $q2->id], $strictness = MUST_EXIST); @@ -271,7 +271,7 @@ public function test_list_with_array(): void { role_assign($managerroleid, $this->user->id, $context->id); $qcategory2 = $this->generator->create_question_category( ['contextid' => \context_course::instance($this->course->id)->id]); - $q2 = $this->generator->create_question('stack', 'test3', + $q2 = $this->generator->create_question('shortanswer', null, ['name' => self::QNAME . '2', 'category' => $qcategory2->id]); $qbankentryid2 = $DB->get_field('question_versions', 'questionbankentryid', ['questionid' => $q2->id], $strictness = MUST_EXIST); @@ -379,7 +379,7 @@ public function test_list_with_subcategory_name(): void { role_assign($managerroleid, $this->user->id, $context->id); $qcategory2 = $this->generator->create_question_category( ['contextid' => \context_course::instance($this->course->id)->id]); - $q2 = $this->generator->create_question('stack', 'test3', + $q2 = $this->generator->create_question('shortanswer', null, ['name' => self::QNAME . '2', 'category' => $qcategory2->id]); $qbankentryid2 = $DB->get_field('question_versions', 'questionbankentryid', ['questionid' => $q2->id], $strictness = MUST_EXIST); @@ -423,7 +423,7 @@ public function test_list_with_subcategory_id(): void { role_assign($managerroleid, $this->user->id, $context->id); $qcategory2 = $this->generator->create_question_category( ['contextid' => \context_course::instance($this->course->id)->id]); - $q2 = $this->generator->create_question('stack', 'test3', + $q2 = $this->generator->create_question('shortanswer', null, ['name' => self::QNAME . '2', 'category' => $qcategory2->id]); $qbankentryid2 = $DB->get_field('question_versions', 'questionbankentryid', ['questionid' => $q2->id], $strictness = MUST_EXIST); diff --git a/tests/external/import_question_test.php b/tests/external/import_question_test.php index 536b481..54fcb4f 100644 --- a/tests/external/import_question_test.php +++ b/tests/external/import_question_test.php @@ -322,7 +322,7 @@ public function test_question_update(): void { global $DB; $this->give_capabilities(); // Generate question and obtain its QBE id. - $question = $this->generator->create_question('stack', 'test3', + $question = $this->generator->create_question('shortanswer', null, ['name' => self::QNAME, 'category' => $this->qcategory->id]); $qbankentryid = $DB->get_field('question_versions', 'questionbankentryid', ['questionid' => $question->id], $strictness = MUST_EXIST); @@ -359,7 +359,7 @@ public function test_version_check(): void { global $DB; $this->give_capabilities(); // Generate question and obtain its QBE id. - $question = $this->generator->create_question('stack', 'test3', + $question = $this->generator->create_question('shortanswer', null, ['name' => self::QNAME, 'category' => $this->qcategory->id]); $qbankentryid = $DB->get_field('question_versions', 'questionbankentryid', ['questionid' => $question->id], $strictness = MUST_EXIST); From 16ad8ae33e4232e312337177b899021a6ac00f2a Mon Sep 17 00:00:00 2001 From: Edmund Farrow Date: Wed, 6 Mar 2024 11:40:01 +0000 Subject: [PATCH 05/12] github-workflow - Up Moodle version -We need a version of Moodle where the delete all versions of a question bug is fixed. -Use external_api alias for 4.2+ --- .github/workflows/moodle-ci.yml | 3 --- classes/external/delete_question.php | 2 +- classes/external/export_question.php | 2 +- classes/external/get_question_list.php | 2 +- classes/external/import_question.php | 2 +- tests/external/import_question_test.php | 2 +- version.php | 5 +++-- 7 files changed, 8 insertions(+), 10 deletions(-) diff --git a/.github/workflows/moodle-ci.yml b/.github/workflows/moodle-ci.yml index 80b3d4e..2d0baa2 100644 --- a/.github/workflows/moodle-ci.yml +++ b/.github/workflows/moodle-ci.yml @@ -45,9 +45,6 @@ jobs: - php: '7.4' moodle-branch: 'MOODLE_401_STABLE' database: 'mariadb' - - php: '7.4' - moodle-branch: 'MOODLE_400_STABLE' - database: 'pgsql' steps: - name: Check out repository code diff --git a/classes/external/delete_question.php b/classes/external/delete_question.php index d5b2178..ce8f8b3 100644 --- a/classes/external/delete_question.php +++ b/classes/external/delete_question.php @@ -26,7 +26,7 @@ defined('MOODLE_INTERNAL') || die(); -require_once($CFG->libdir . '/externallib.php'); +require_once($CFG->dirroot . '/lib/externallib.php'); require_once($CFG->libdir . '/questionlib.php'); require_once($CFG->dirroot. '/question/bank/gitsync/lib.php'); diff --git a/classes/external/export_question.php b/classes/external/export_question.php index 0ca69dc..928fdf2 100644 --- a/classes/external/export_question.php +++ b/classes/external/export_question.php @@ -26,7 +26,7 @@ defined('MOODLE_INTERNAL') || die(); -require_once($CFG->libdir . '/externallib.php'); +require_once($CFG->dirroot . '/lib/externallib.php'); require_once($CFG->libdir . '/questionlib.php'); require_once($CFG->dirroot . '/question/format/xml/format.php'); require_once($CFG->dirroot. '/question/bank/gitsync/lib.php'); diff --git a/classes/external/get_question_list.php b/classes/external/get_question_list.php index f795643..1d4e28c 100644 --- a/classes/external/get_question_list.php +++ b/classes/external/get_question_list.php @@ -26,7 +26,7 @@ defined('MOODLE_INTERNAL') || die(); -require_once($CFG->libdir . '/externallib.php'); +require_once($CFG->dirroot . '/lib/externallib.php'); require_once($CFG->libdir . '/questionlib.php'); require_once($CFG->dirroot. '/question/bank/gitsync/lib.php'); diff --git a/classes/external/import_question.php b/classes/external/import_question.php index 5cdaec9..e22f755 100644 --- a/classes/external/import_question.php +++ b/classes/external/import_question.php @@ -26,7 +26,7 @@ defined('MOODLE_INTERNAL') || die(); -require_once($CFG->libdir . '/externallib.php'); +require_once($CFG->dirroot . '/lib/externallib.php'); require_once($CFG->libdir . '/questionlib.php'); require_once($CFG->dirroot . '/question/format/xml/format.php'); require_once($CFG->dirroot. '/question/bank/gitsync/lib.php'); diff --git a/tests/external/import_question_test.php b/tests/external/import_question_test.php index 54fcb4f..599043b 100644 --- a/tests/external/import_question_test.php +++ b/tests/external/import_question_test.php @@ -29,7 +29,7 @@ global $CFG; require_once($CFG->dirroot . '/question/engine/tests/helpers.php'); require_once($CFG->dirroot . '/webservice/tests/helpers.php'); -require_once($CFG->dirroot . '/files/externallib.php'); +require_once($CFG->dirroot . '/lib/externallib.php'); require_once($CFG->dirroot. '/question/bank/gitsync/lib.php'); use context_course; diff --git a/version.php b/version.php index 4ab2429..c7fa2b0 100644 --- a/version.php +++ b/version.php @@ -26,10 +26,11 @@ $plugin->version = 2023120400; // Question versions functionality of Moodle 4 required. -$plugin->requires = 2022041900; +// Question delete fix for Moodle 4.1.5 required. +$plugin->requires = 2022112805; $plugin->component = 'qbank_gitsync'; $plugin->maturity = MATURITY_BETA; -$plugin->release = '0.9.0 for Moodle 4.0+'; +$plugin->release = '0.9.0 for Moodle 4.1+'; $plugin->dependencies = [ 'qbank_importasversion' => 2023102700, From 1bc2b0878d32ccac1a1471cf27876ff167abd9e5 Mon Sep 17 00:00:00 2001 From: Edmund Farrow Date: Wed, 6 Mar 2024 11:53:04 +0000 Subject: [PATCH 06/12] github-workflow - Run tests in separate processes --- tests/external/delete_question_test.php | 4 ++-- tests/external/export_question_test.php | 1 + tests/external/get_question_list_test.php | 1 + tests/external/import_question_test.php | 3 ++- 4 files changed, 6 insertions(+), 3 deletions(-) diff --git a/tests/external/delete_question_test.php b/tests/external/delete_question_test.php index 2a93564..9186869 100644 --- a/tests/external/delete_question_test.php +++ b/tests/external/delete_question_test.php @@ -39,9 +39,10 @@ /** * Test the delete_question webservice function. - * + * @runTestsInSeparateProcesses * @covers \gitsync\external\delete_question::execute * @group qbank_gitsync + * */ class delete_question_test extends externallib_advanced_testcase { /** @var \core_question_generator plugin generator */ @@ -78,7 +79,6 @@ public function setUp(): void { /** * Test the execute function when capabilities are present. - * @runInSeparateProcess */ public function test_capabilities(): void { global $DB; diff --git a/tests/external/export_question_test.php b/tests/external/export_question_test.php index 752c364..152cea5 100644 --- a/tests/external/export_question_test.php +++ b/tests/external/export_question_test.php @@ -39,6 +39,7 @@ /** * Test the export_question webservice function. + * @runTestsInSeparateProcesses * @group qbank_gitsync * * @covers \gitsync\external\export_question::execute diff --git a/tests/external/get_question_list_test.php b/tests/external/get_question_list_test.php index bae55f7..27ec743 100644 --- a/tests/external/get_question_list_test.php +++ b/tests/external/get_question_list_test.php @@ -39,6 +39,7 @@ /** * Test the get_question_list webservice function. + * @runTestsInSeparateProcesses * @group qbank_gitsync * * @covers \gitsync\external\get_question_list::execute diff --git a/tests/external/import_question_test.php b/tests/external/import_question_test.php index 599043b..75b8661 100644 --- a/tests/external/import_question_test.php +++ b/tests/external/import_question_test.php @@ -29,7 +29,7 @@ global $CFG; require_once($CFG->dirroot . '/question/engine/tests/helpers.php'); require_once($CFG->dirroot . '/webservice/tests/helpers.php'); -require_once($CFG->dirroot . '/lib/externallib.php'); +require_once($CFG->dirroot . '/files/externallib.php'); require_once($CFG->dirroot. '/question/bank/gitsync/lib.php'); use context_course; @@ -41,6 +41,7 @@ /** * Test the export_question webservice function. + * @runTestsInSeparateProcesses * @group qbank_gitsync * * @covers \gitsync\external\import_question::execute From 82649cdd774005ad5ac07ab050571efb66ee689b Mon Sep 17 00:00:00 2001 From: Edmund Farrow Date: Wed, 6 Mar 2024 12:12:44 +0000 Subject: [PATCH 07/12] github-workflow - Add extra require for 8.1 --- tests/external/import_question_test.php | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/external/import_question_test.php b/tests/external/import_question_test.php index 75b8661..b759a88 100644 --- a/tests/external/import_question_test.php +++ b/tests/external/import_question_test.php @@ -29,6 +29,7 @@ global $CFG; require_once($CFG->dirroot . '/question/engine/tests/helpers.php'); require_once($CFG->dirroot . '/webservice/tests/helpers.php'); +require_once($CFG->dirroot . '/lib/externallib.php'); require_once($CFG->dirroot . '/files/externallib.php'); require_once($CFG->dirroot. '/question/bank/gitsync/lib.php'); From 1d9807faa274c17e4619ecc73f3c6d00b1861d38 Mon Sep 17 00:00:00 2001 From: Edmund Farrow Date: Wed, 6 Mar 2024 12:18:39 +0000 Subject: [PATCH 08/12] github-workflow - Fix dynamic property creation --- tests/export_repo_test.php | 2 ++ tests/export_trait_test.php | 2 ++ 2 files changed, 4 insertions(+) diff --git a/tests/export_repo_test.php b/tests/export_repo_test.php index 7dd280c..a572ae9 100644 --- a/tests/export_repo_test.php +++ b/tests/export_repo_test.php @@ -70,6 +70,8 @@ class export_repo_test extends advanced_testcase { public curl_request $curl; /** @var export_repo mocked export_repo */ public export_repo $exportrepo; + /** @var curl_request mocked curl_request for question list */ + public curl_request $listcurl; /** @var string root of virtual file system */ public string $rootpath; /** @var string used to store output of multiple calls to a function */ diff --git a/tests/export_trait_test.php b/tests/export_trait_test.php index 61b8e1c..e981971 100644 --- a/tests/export_trait_test.php +++ b/tests/export_trait_test.php @@ -46,6 +46,8 @@ class export_trait_test extends advanced_testcase { public curl_request $curl; /** @var export_repo mocked curl_request for doc upload */ public export_repo $exportrepo; + /** @var curl_request mocked curl_request for question list */ + public curl_request $listcurl; /** @var string root of virtual file system */ public string $rootpath; /** @var string used to store output of multiple calls to a function */ From a38d7fc6dac4d55a4951f4cce38b25bb23b237a6 Mon Sep 17 00:00:00 2001 From: Edmund Farrow Date: Wed, 6 Mar 2024 12:30:32 +0000 Subject: [PATCH 09/12] github-workflow - separate process for all tests --- tests/cli_helper_test.php | 1 + tests/create_repo_test.php | 1 + tests/export_repo_test.php | 1 + tests/export_trait_test.php | 1 + tests/import_repo_test.php | 1 + tests/lib_test.php | 1 + tests/tidy_trait_test.php | 2 ++ 7 files changed, 8 insertions(+) diff --git a/tests/cli_helper_test.php b/tests/cli_helper_test.php index 262013c..1ad3a04 100644 --- a/tests/cli_helper_test.php +++ b/tests/cli_helper_test.php @@ -49,6 +49,7 @@ public static function call_exit():void { * * Some tests are also done in import_repo_test where mocking has * already been set up. + * @runTestsInSeparateProcesses * * @covers \gitsync\cli_helper::class */ diff --git a/tests/create_repo_test.php b/tests/create_repo_test.php index 73d34c3..b43f7cd 100644 --- a/tests/create_repo_test.php +++ b/tests/create_repo_test.php @@ -32,6 +32,7 @@ /** * Test the CLI script for creating a repo from questions in Moodle. * @group qbank_gitsync + * @runTestsInSeparateProcesses * * @covers \gitsync\create_repo::class */ diff --git a/tests/export_repo_test.php b/tests/export_repo_test.php index a572ae9..4ca342d 100644 --- a/tests/export_repo_test.php +++ b/tests/export_repo_test.php @@ -56,6 +56,7 @@ public static function handle_abort():void { /** * Test the CLI script for exporting a repo from Moodle. * @group qbank_gitsync + * @runTestsInSeparateProcesses * * @covers \gitsync\export_repo::class */ diff --git a/tests/export_trait_test.php b/tests/export_trait_test.php index e981971..aa485ef 100644 --- a/tests/export_trait_test.php +++ b/tests/export_trait_test.php @@ -32,6 +32,7 @@ /** * Test the CLI script for exporting a repo from Moodle. * @group qbank_gitsync + * @runTestsInSeparateProcesses * * @covers \gitsync\export_repo::class */ diff --git a/tests/import_repo_test.php b/tests/import_repo_test.php index ac7037e..9ffd010 100644 --- a/tests/import_repo_test.php +++ b/tests/import_repo_test.php @@ -56,6 +56,7 @@ public static function handle_abort():void { /** * Test the CLI script for importing a repo to Moodle. * @group qbank_gitsync + * @runTestsInSeparateProcesses * * @covers \gitsync\import_repo::class */ diff --git a/tests/lib_test.php b/tests/lib_test.php index 9c422ae..53dee7a 100644 --- a/tests/lib_test.php +++ b/tests/lib_test.php @@ -35,6 +35,7 @@ /** * Tests for library function in lib.php + * @runTestsInSeparateProcesses * @group qbank_gitsync */ class lib_test extends \advanced_testcase { diff --git a/tests/tidy_trait_test.php b/tests/tidy_trait_test.php index 80c9817..f9d35e5 100644 --- a/tests/tidy_trait_test.php +++ b/tests/tidy_trait_test.php @@ -33,6 +33,8 @@ * Test the CLI script for exporting a repo from Moodle. * @group qbank_gitsync * + * @runTestsInSeparateProcesses + * * @covers \gitsync\export_repo::class */ class tidy_trait_test extends advanced_testcase { From 5d4b70d56d42585d289ace5423732f1a0d4ec7bf Mon Sep 17 00:00:00 2001 From: Edmund Farrow Date: Wed, 6 Mar 2024 13:17:02 +0000 Subject: [PATCH 10/12] github-workflow - remove require --- tests/external/import_question_test.php | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/external/import_question_test.php b/tests/external/import_question_test.php index b759a88..75b8661 100644 --- a/tests/external/import_question_test.php +++ b/tests/external/import_question_test.php @@ -29,7 +29,6 @@ global $CFG; require_once($CFG->dirroot . '/question/engine/tests/helpers.php'); require_once($CFG->dirroot . '/webservice/tests/helpers.php'); -require_once($CFG->dirroot . '/lib/externallib.php'); require_once($CFG->dirroot . '/files/externallib.php'); require_once($CFG->dirroot. '/question/bank/gitsync/lib.php'); From 3bcb4957418a907615858972a4c3aa91b74301ff Mon Sep 17 00:00:00 2001 From: Edmund Farrow Date: Wed, 6 Mar 2024 13:29:00 +0000 Subject: [PATCH 11/12] github-workflow - More dynamic creation fixes, fix wrong call --- tests/external/import_question_test.php | 2 +- tests/lib_test.php | 1 - tests/tidy_trait_test.php | 2 ++ 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/external/import_question_test.php b/tests/external/import_question_test.php index 75b8661..a2cc443 100644 --- a/tests/external/import_question_test.php +++ b/tests/external/import_question_test.php @@ -102,7 +102,7 @@ public function upload_file(string $contentpath):void { $fileinfo = core_files_external::upload($contextid, $component, $filearea, $itemid, $filepath, $filename, $filecontent, $contextlevel, $instanceid); - $fileinfo = \external_api::clean_returnvalue(core_files_external::upload_returns(), $fileinfo); + $fileinfo = core_files_external::clean_returnvalue(core_files_external::upload_returns(), $fileinfo); $this->fileinfo = $fileinfo; unset($this->fileinfo['url']); diff --git a/tests/lib_test.php b/tests/lib_test.php index 53dee7a..28ff967 100644 --- a/tests/lib_test.php +++ b/tests/lib_test.php @@ -153,7 +153,6 @@ public function test_get_question_data() { $qcategory = $generator->create_question_category( ['contextid' => \context_course::instance($course->id)->id]); $user = $this->getDataGenerator()->create_user(); - $this->user = $user; $this->setUser($user); $q = $generator->create_question('shortanswer', null, ['name' => 'This is the first version', 'category' => $qcategory->id]); diff --git a/tests/tidy_trait_test.php b/tests/tidy_trait_test.php index f9d35e5..48dd082 100644 --- a/tests/tidy_trait_test.php +++ b/tests/tidy_trait_test.php @@ -46,6 +46,8 @@ class tidy_trait_test extends advanced_testcase { public cli_helper $clihelper; /** @var curl_request mocked curl_request */ public curl_request $curl; + /** @var curl_request mocked curl_request for question list */ + public curl_request $listcurl; /** @var export_repo mocked curl_request for doc upload */ public export_repo $exportrepo; /** @var string root of virtual file system */ From 79b2cdb64a7f8ed261c42658ecb82ee469031bcc Mon Sep 17 00:00:00 2001 From: Edmund Farrow Date: Wed, 6 Mar 2024 13:36:02 +0000 Subject: [PATCH 12/12] github-workflow - Tidy up --- .github/workflows/moodle-ci.yml | 5 ++--- classes/cli_helper.php | 2 +- tests/cli_helper_test.php | 1 - tests/create_repo_test.php | 1 - tests/export_repo_test.php | 1 - tests/export_trait_test.php | 1 - tests/import_repo_test.php | 1 - tests/lib_test.php | 1 - tests/tidy_trait_test.php | 2 -- 9 files changed, 3 insertions(+), 12 deletions(-) diff --git a/.github/workflows/moodle-ci.yml b/.github/workflows/moodle-ci.yml index 2d0baa2..afbce1b 100644 --- a/.github/workflows/moodle-ci.yml +++ b/.github/workflows/moodle-ci.yml @@ -30,7 +30,6 @@ jobs: strategy: fail-fast: false matrix: # I don't know why, but mariadb is much slower, so mostly use pgsql. - # We use a mix of SBCL and GCL, but mostly prefer SBCL as it is faster. include: - php: '8.2' moodle-branch: 'master' @@ -95,12 +94,12 @@ jobs: run: moodle-plugin-ci phpmd - name: Moodle Code Checker - continue-on-error: true # Currently fails. We really ought to get this passing. + continue-on-error: true if: ${{ always() }} run: moodle-plugin-ci codechecker --max-warnings 0 - name: Moodle PHPDoc Checker - continue-on-error: true # Currently fails. We really ought to get this passing. + continue-on-error: true if: ${{ always() }} run: moodle-plugin-ci phpdoc diff --git a/classes/cli_helper.php b/classes/cli_helper.php index cda89d6..9a00e13 100644 --- a/classes/cli_helper.php +++ b/classes/cli_helper.php @@ -589,7 +589,7 @@ public function create_gitignore(string $manifestpath):void { /** * Check if the repository has been initialised * - * @param string $manifestpath + * @param string $fullmanifestpath * @return void */ public function check_repo_initialised(string $fullmanifestpath):void { diff --git a/tests/cli_helper_test.php b/tests/cli_helper_test.php index 1ad3a04..262013c 100644 --- a/tests/cli_helper_test.php +++ b/tests/cli_helper_test.php @@ -49,7 +49,6 @@ public static function call_exit():void { * * Some tests are also done in import_repo_test where mocking has * already been set up. - * @runTestsInSeparateProcesses * * @covers \gitsync\cli_helper::class */ diff --git a/tests/create_repo_test.php b/tests/create_repo_test.php index b43f7cd..73d34c3 100644 --- a/tests/create_repo_test.php +++ b/tests/create_repo_test.php @@ -32,7 +32,6 @@ /** * Test the CLI script for creating a repo from questions in Moodle. * @group qbank_gitsync - * @runTestsInSeparateProcesses * * @covers \gitsync\create_repo::class */ diff --git a/tests/export_repo_test.php b/tests/export_repo_test.php index 4ca342d..a572ae9 100644 --- a/tests/export_repo_test.php +++ b/tests/export_repo_test.php @@ -56,7 +56,6 @@ public static function handle_abort():void { /** * Test the CLI script for exporting a repo from Moodle. * @group qbank_gitsync - * @runTestsInSeparateProcesses * * @covers \gitsync\export_repo::class */ diff --git a/tests/export_trait_test.php b/tests/export_trait_test.php index aa485ef..e981971 100644 --- a/tests/export_trait_test.php +++ b/tests/export_trait_test.php @@ -32,7 +32,6 @@ /** * Test the CLI script for exporting a repo from Moodle. * @group qbank_gitsync - * @runTestsInSeparateProcesses * * @covers \gitsync\export_repo::class */ diff --git a/tests/import_repo_test.php b/tests/import_repo_test.php index 9ffd010..ac7037e 100644 --- a/tests/import_repo_test.php +++ b/tests/import_repo_test.php @@ -56,7 +56,6 @@ public static function handle_abort():void { /** * Test the CLI script for importing a repo to Moodle. * @group qbank_gitsync - * @runTestsInSeparateProcesses * * @covers \gitsync\import_repo::class */ diff --git a/tests/lib_test.php b/tests/lib_test.php index 28ff967..641ab06 100644 --- a/tests/lib_test.php +++ b/tests/lib_test.php @@ -35,7 +35,6 @@ /** * Tests for library function in lib.php - * @runTestsInSeparateProcesses * @group qbank_gitsync */ class lib_test extends \advanced_testcase { diff --git a/tests/tidy_trait_test.php b/tests/tidy_trait_test.php index 48dd082..8717bae 100644 --- a/tests/tidy_trait_test.php +++ b/tests/tidy_trait_test.php @@ -33,8 +33,6 @@ * Test the CLI script for exporting a repo from Moodle. * @group qbank_gitsync * - * @runTestsInSeparateProcesses - * * @covers \gitsync\export_repo::class */ class tidy_trait_test extends advanced_testcase {