diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f75a51c..0da999b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,104 +1,215 @@ name: Moodle Plugin CI -on: [push, pull_request] - +# Automatically triggered on push to main branch, on pull requests +on: ['push', 'pull_request'] jobs: test: - runs-on: ubuntu-18.04 + runs-on: ubuntu-latest services: postgres: - image: postgres:10 + image: postgres:17 env: - POSTGRES_USER: 'postgres' - POSTGRES_HOST_AUTH_METHOD: 'trust' + 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 strategy: fail-fast: false + matrix: - php: ['7.3','7.4'] - moodle-branch: ['MOODLE_39_STABLE', 'MOODLE_310_STABLE', 'MOODLE_311_STABLE', 'MOODLE_400_STABLE'] + php: ["7.4", "8.0", "8.1", "8.2", "8.3", "8.4"] + moodle_branch: + [ + "MOODLE_401_STABLE", + "MOODLE_402_STABLE", + "MOODLE_403_STABLE", + "MOODLE_404_STABLE", + "MOODLE_405_STABLE", + "MOODLE_500_STABLE", + "MOODLE_501_STABLE", + "main", + ] database: [pgsql] + browser: ["chrome", "firefox"] + exclude: + # Exclude Moodle+PHP incompatible versions + # See: https://docs.moodle.org/dev/Moodle_and_PHP + + - moodle_branch: "MOODLE_402_STABLE" + php: "7.4" + - moodle_branch: "MOODLE_403_STABLE" + php: "7.4" + - moodle_branch: "MOODLE_404_STABLE" + php: "7.4" + - moodle_branch: "MOODLE_405_STABLE" + php: "7.4" + - moodle_branch: "MOODLE_500_STABLE" + php: "7.4" + - moodle_branch: "MOODLE_501_STABLE" + php: "7.4" + + + - moodle_branch: "MOODLE_404_STABLE" + php: "8.0" + - moodle_branch: "MOODLE_405_STABLE" + php: "8.0" + - moodle_branch: "MOODLE_500_STABLE" + php: "8.0" + - moodle_branch: "MOODLE_501_STABLE" + php: "8.0" + + - moodle_branch: "MOODLE_500_STABLE" + php: "8.1" + - moodle_branch: "MOODLE_501_STABLE" + php: "8.1" + + - moodle_branch: "MOODLE_401_STABLE" + php: "8.2" + + - moodle_branch: "MOODLE_401_STABLE" + php: "8.3" + - moodle_branch: "MOODLE_402_STABLE" + php: "8.3" + - moodle_branch: "MOODLE_403_STABLE" + php: "8.3" + + - moodle_branch: "MOODLE_401_STABLE" + php: "8.4" + - moodle_branch: "MOODLE_402_STABLE" + php: "8.4" + - moodle_branch: "MOODLE_403_STABLE" + php: "8.4" + - moodle_branch: "MOODLE_404_STABLE" + php: "8.4" + - moodle_branch: "MOODLE_405_STABLE" + php: "8.4" + + - moodle_branch: "main" + + + include: + # Only test master against latest PHP until we know which + # versions are supported in the next release + - moodle_branch: "main" + php: "8.4" + database: "pgsql" + continue-on-error: ${{ matrix.branch == 'main' }} steps: - - name: Get branch name - id: branch-name - uses: tj-actions/branch-names@v7.0.7 - - name: Check out repository code - uses: actions/checkout@v2 + uses: actions/checkout@v4 with: path: plugin + # 0.1 Detect branch name based on event type. + - name: Set branch name + id: get_branch + run: | + if [ "${{ github.event_name }}" == "pull_request" ]; then + echo "BRANCH_NAME=${{ github.head_ref }}" >> $GITHUB_ENV + else + echo "BRANCH_NAME=${{ github.ref_name }}" >> $GITHUB_ENV + fi + + # 0.2 Log current matrix info. + - name: Log info + run: | + echo "PHP: ${{ matrix.php }}" + echo "Moodle: ${{ matrix.moodle_branch }}" + echo "Browser: ${{ matrix.browser }}" + echo "Branch: ${{ env.BRANCH_NAME }}" + + # 0.3 Cache Composer for faster builds. + - name: Cache Composer dependencies + uses: actions/cache@v3 + with: + path: | + ${{ github.workspace }}/.composer/cache + ${{ github.workspace }}/.npm + key: ${{ runner.os }}-composer-${{ matrix.php }}-${{ matrix.moodle_branch }} + restore-keys: ${{ runner.os }}-composer-${{ matrix.php }}-${{ matrix.moodle_branch }} + + # 1. Setup PHP for the current matrix. - name: Setup PHP ${{ matrix.php }} uses: shivammathur/setup-php@v2 with: php-version: ${{ matrix.php }} extensions: ${{ matrix.extensions }} - ini-values: max_input_vars=5000 + ini-values: max_input_vars=10000 coverage: none + # 2. Install moodle-plugin-ci tool. - name: Initialise moodle-plugin-ci run: | - composer create-project -n --no-dev --prefer-dist moodlehq/moodle-plugin-ci ci ^3 + composer create-project -n --no-dev --prefer-dist moodlehq/moodle-plugin-ci ci ^4 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 + echo NVM_DIR=$NVM_DIR >> $GITHUB_ENV + env: + IGNORE_PATHS: classes/privacy,ignore,node_modules,integration,render + COVERAGE: false + CODECHECKER_IGNORE_PATHS: classes/privacy,ignore,node_modules,integration,render + PHPUNIT_IGNORE_PATHS: classes/privacy,ignore,node_modules,integration,render - - name: Add filter & commons qtype + # 3. Install filter + - name: Add Wiris filter run: | moodle-plugin-ci add-plugin wiris/moodle-filter_wiris - moodle-plugin-ci add-plugin --branch ${{ steps.branch-name.outputs.current_branch }} wiris/moodle-qtype_wq - - name: Install moodle-plugin-ci + # 3.5. Install Wiris Quizzes plugin. + - name: Add Wiris Quizzes plugin + id: install-plugin-quizzes + if: ${{ always() }} + continue-on-error: true run: | - moodle-plugin-ci install --plugin ./plugin --db-host=127.0.0.1 + moodle-plugin-ci add-plugin --branch ${{ env.BRANCH_NAME }} wiris/moodle-qtype_wq + - name: Add Wiris Quizzes plugin using the main branch + if: ${{ steps.install-plugin-quizzes.outcome != 'success' }} + run: | + moodle-plugin-ci add-plugin --branch main wiris/moodle-qtype_wq + + + # 4. Install plugin and configure DB. + - name: Install moodle-plugin-ci + run: moodle-plugin-ci install --plugin ./plugin --db-host=127.0.0.1 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 + MOODLE_BRANCH: ${{ matrix.moodle_branch }} - - name: Moodle Code Checker + # 5. Run PHPUnit tests. + - name: PHPUnit tests if: ${{ always() }} - run: moodle-plugin-ci codechecker --max-warnings 0 + run: moodle-plugin-ci phpunit ./plugin + continue-on-error: true + # 5.1 Run Moodle code validation. - 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 + run: moodle-plugin-ci validate ./plugin + continue-on-error: true - - name: Grunt - if: ${{ always() }} - run: moodle-plugin-ci grunt --max-lint-warnings 0 - - - name: PHPUnit tests - if: ${{ always() }} - run: moodle-plugin-ci phpunit + # 6. Run Behat tests. + - name: Behat features for ( ${{ matrix.moodle_branch }} on PHP ${{ matrix.php }} ) + id: behat + run: | + case "${{ matrix.moodle_branch }}" in + "MOODLE_401_STABLE"|"MOODLE_402_STABLE"|"MOODLE_403_STABLE"|"MOODLE_404_STABLE"|"MOODLE_405_STABLE"|"MOODLE_500_STABLE"|"MOODLE_501_STABLE"|"main") + TAG="@qtype_multichoicewiris" + ;; + esac + moodle-plugin-ci behat --tags=$TAG --profile ${{ matrix.browser }} --auto-rerun=2 --verbose -vvv + + # 6.1 Upload Behat fail dumps when errors occur. + - name: Upload Behat Faildump + if: ${{ failure() && steps.behat.outcome == 'failure' }} + uses: actions/upload-artifact@v4 + with: + name: Behat Faildump (${{ matrix.php }}, ${{ matrix.moodle_branch }}, ${{ matrix.browser }}) + path: ${{ github.workspace }}/moodledata/behat_dump + retention-days: 1 + if-no-files-found: ignore - - name: Behat features - if: ${{ always() }} - run: moodle-plugin-ci behat --profile chrome \ No newline at end of file diff --git a/tests/behat/add.feature b/tests/behat/add.feature deleted file mode 100644 index 487368b..0000000 --- a/tests/behat/add.feature +++ /dev/null @@ -1,38 +0,0 @@ -@qtype @qtype_wq @qtype_multichoicewiris -Feature: Test creating a Multiple choice wiris question without template - As a teacher - In order to test my students - I need to be able to create a Multiple choice question using variables - - Background: - Given the following "users" exist: - | username | - | teacher | - And the following "courses" exist: - | fullname | shortname | category | - | Course 1 | C1 | 0 | - And the following "course enrolments" exist: - | user | course | role | - | teacher | C1 | editingteacher | - - @javascript - Scenario: Create a Multiple choice wiris question - When I am on the "Course 1" "core_question > course question bank" page logged in as teacher - And I press "Create a new question ..." - And I choose the question type "Multiple choice - science" - Then I set the following fields to these values: - | Question name | multichoiceanswer-wiris-001 | - | Question text | This is a multichoice wiris question | - And I open Wiris Quizzes Studio - And I click on "Random variables" "text" - And I add the variable "a" with value "10" - And I add the variable "b" with value "-15/171" - And I go back in Wiris Quizzes Studio - And I save Wiris Quizzes Studio - Then I set the following fields to these values: - | Choice 1 | #a | - | id_fraction_0 | 100% | - | Choice 2 | #b | - | id_fraction_1 | None | - And I press "id_submitbutton" - Then I should see "multichoiceanswer-wiris-001" diff --git a/tests/behat/edit.feature b/tests/behat/edit.feature deleted file mode 100644 index 962c8a0..0000000 --- a/tests/behat/edit.feature +++ /dev/null @@ -1,49 +0,0 @@ -@qtype @qtype_wq @qtype_multichoicewiris -Feature: Test editing a Multichoice wiris question - As a teacher - In order to be able to update my Multichoice wiris question - I need to edit them - - Background: - Given the following "users" exist: - | username | - | teacher | - And the following "courses" exist: - | fullname | shortname | category | - | Course 1 | C1 | 0 | - And the following "course enrolments" exist: - | user | course | role | - | teacher | C1 | editingteacher | - And the following "question categories" exist: - | contextlevel | reference | name | - | Course | C1 | Test questions | - And the following "questions" exist: - | questioncategory | qtype | name | template | - | Test questions | multichoicewiris | multichoice-wiris-001 | four_of_five_science | - - @javascript @_switch_window - Scenario: Edit a multichoice wiris question - When I am on the "multichoice-wiris-001" "core_question > edit" page logged in as teacher - And I set the following fields to these values: - | Question name | Edited multichoice-wiris-001 name | - And I press "id_submitbutton" - Then I should see "Edited multichoice-wiris-001 name" - When I choose "Edit question" action for "Edited multichoice-wiris-001" in the question bank - And I press "Blanks for 3 more choices" - And I set the following fields to these values: - | id_answer_5 | 57 | - | id_fraction_5 | 20% | - | id_feedback_5 | 57 is odd | - | id_answer_6 | 6 | - | id_fraction_6 | None | - | id_feedback_6 | 6 is even | - | id_answer_7 | 88 | - | id_fraction_7 | None | - | id_feedback_7 | 88 is even | - | id_fraction_0 | 20% | - | id_fraction_1 | 20% | - | id_fraction_2 | 20% | - | id_fraction_3 | 20% | - | General feedback | The odd numbers are 57, #t1, #t2 and #t4. | - And I press "id_submitbutton" - Then I should see "Edited multichoice-wiris-001" diff --git a/tests/behat/preview.feature b/tests/behat/preview.feature deleted file mode 100644 index 0a977bf..0000000 --- a/tests/behat/preview.feature +++ /dev/null @@ -1,33 +0,0 @@ -@qtype @qtype_wq @qtype_multichoicewiris -Feature: A student can answer a Wiris Multi Choice question type - In order to answer the question - As a student - I need to answer the multi choice wiris question - - Background: - Given the "wiris" filter is "on" - Given the "mathjaxloader" filter is "disabled" - Given the following "users" exist: - | username | - | teacher | - And the following "courses" exist: - | fullname | shortname | format | - | Course 1 | C1 | weeks | - And the following "course enrolments" exist: - | user | course | role | - | teacher | C1 | editingteacher | - And the following "question categories" exist: - | contextlevel | reference | name | - | Course | C1 | Default for C1 | - And the following "questions" exist: - | questioncategory | qtype | name | template | - | Default for C1 | multichoicewiris | Multi choice wiris | four_of_five_science | - - @javascript - Scenario: A student executes a wiris multichoice question type - When I am on the "Multi choice wiris" "core_question > preview" page logged in as teacher - Then Wirisformula should exist - When I click on "1. " "text" - And I press "Submit and finish" - Then Feedback should exist - And Generalfeedback should exist diff --git a/tests/behat/student.feature b/tests/behat/student.feature new file mode 100644 index 0000000..39160cc --- /dev/null +++ b/tests/behat/student.feature @@ -0,0 +1,37 @@ +@javascript @qtype_multichoicewiris @studentwiris @wqmdl-272 +Feature: Student answers a quiz with a Multiple choice (WIRIS) question + + Background: + Given the following "users" exist: + | username | firstname | lastname | email | + | student1 | Student | One | student1@example.com | + And the following "courses" exist: + | fullname | shortname | + | Course 1 | C1 | + And the following "course enrolments" exist: + | user | course | role | + | student1 | C1 | student | + + And the following "activities" exist: + | activity | name | course | idnumber | + | quiz | WIRIS MC Quiz | C1 | quiz_mc | + + And the following "question categories" exist: + | contextlevel | reference | name | + | Course | C1 | WIRIS bank | + + # Single-answer MC with 3 choices; "2" is correct + And the following "questions" exist: + | questioncategory | qtype | name | questiontext | defaultmark | single | answers[1] | fraction[1] | answers[2] | fraction[2] | answers[3] | fraction[3] | + | WIRIS bank | multichoicewiris | MC WIRIS – 1+1 |

What is 1 + 1?

| 1.0 | 1 | 2 | 1.0 | 3 | 0.0 | 1 | 0.0 | + + And quiz "WIRIS MC Quiz" contains the following questions: + | question | page | + | MC WIRIS – 1+1 | 1 | + + Scenario: Student attempts and submits the Multiple choice (WIRIS) quiz + Given I am on the "WIRIS MC Quiz" "mod_quiz > View" page logged in as "student1" + When I press "Attempt quiz" + And I click on "Finish attempt ..." "link" + And I press "Submit all and finish" + And I click on "Submit all and finish" "button" in the "Submit all your answers and finish?" "dialogue"