Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-85556

restore_move_module_questions_categories changes existing question references

XMLWordPrintable

    • MOODLE_500_STABLE
    • MOODLE_500_STABLE
    • MDL-85556_500_STABLE
    • MDL-85556_main
    • Hide

      This is a bit complicated to test. The key thing to understand is that the expected behaviour is for the unit test repeated_restore_test::test_restore_course_with_same_stamp_questions should fail for the attached qtype_formulas plugin, as it does not use the standard question_answers table. Specifically, it should fail when checking the question ID in the restored course, not the backed-up course. It should pass or skip for all core qtypes.

      1. Create a new moodle site from the `main` branch, and unpack the attached qtype_formulas.zip in /question/type/formulas and (ii) qbehaviour_adaptivemultipart.zip in /question/behaviour/adaptivemultipart.
      2. Run `php admin/tool/phpunit/init.php`
      3. Run `php vendor/bin/phpunit --filter '/test_restore_course_with_same_stamp_questions with data set "formulas"/' mod/quiz/tests/backup/repeated_restore_test.php` to execute the test for qtype_formulas.
      4. Confirm that the test passes (this is incorrect behaviour).
      5. Apply the first commit from the branch, "MDL-85556 questions: Fix repeated_restore unit test"
      6. Run `php vendor/bin/phpunit --filter '/test_restore_course_with_same_stamp_questions with data set "formulas"/' mod/quiz/tests/backup/repeated_restore_test.php` to execute the test for qtype_formulas.
      7. Confirm that the test fails. This is correct, however it fails with the following message:
        "Failed asserting that 'xxx000' matches expected xxx001.
        /var/www/moodlecore/mod/quiz/tests/backup/repeated_restore_test.php:594"
        This is incorrect. It is showing that the question ID in the backed-up course has changed since the assertion on line 563, which should not have happened.
      8. Apply the second commit from the branch, "MDL-85556 backup: Only update question refs in restored course"
      9. Run `php vendor/bin/phpunit --filter '/test_restore_course_with_same_stamp_questions with data set "formulas"/' mod/quiz/tests/backup/repeated_restore_test.php` to execute the test for qtype_formulas.
      10. Confirm that the test fails again, with the following message:
        "Failed asserting that 'xxx000' matches expected xxx001.
        /var/www/moodlecore/mod/quiz/tests/backup/repeated_restore_test.php:595"
        This shows it is now failing because the question ID on the restored course is incorrect, which is the expected behaviour.
      11. Remove the question/type/formulas directory and re-initialise phpunit:
        `php admin/tool/phpunit/init.php`
      12. Run the whole test file: `php vendor/bin/phpunit mod/quiz/tests/backup/repeated_restore_test.php`
      13. Confirm that all tests pass or skip for the core question types.
      Show
      This is a bit complicated to test. The key thing to understand is that the expected behaviour is for the unit test repeated_restore_test::test_restore_course_with_same_stamp_questions should fail for the attached qtype_formulas plugin, as it does not use the standard question_answers table. Specifically, it should fail when checking the question ID in the restored course, not the backed-up course. It should pass or skip for all core qtypes. Create a new moodle site from the `main` branch, and unpack the attached qtype_formulas.zip in /question/type/formulas and (ii) qbehaviour_adaptivemultipart.zip in /question/behaviour/adaptivemultipart. Run `php admin/tool/phpunit/init.php` Run `php vendor/bin/phpunit --filter '/test_restore_course_with_same_stamp_questions with data set "formulas"/' mod/quiz/tests/backup/repeated_restore_test.php` to execute the test for qtype_formulas. Confirm that the test passes (this is incorrect behaviour). Apply the first commit from the branch, " MDL-85556 questions: Fix repeated_restore unit test" Run `php vendor/bin/phpunit --filter '/test_restore_course_with_same_stamp_questions with data set "formulas"/' mod/quiz/tests/backup/repeated_restore_test.php` to execute the test for qtype_formulas. Confirm that the test fails. This is correct, however it fails with the following message: "Failed asserting that 'xxx000' matches expected xxx001. /var/www/moodlecore/mod/quiz/tests/backup/repeated_restore_test.php: 594 " This is incorrect. It is showing that the question ID in the backed-up course has changed since the assertion on line 563, which should not have happened. Apply the second commit from the branch, " MDL-85556 backup: Only update question refs in restored course" Run `php vendor/bin/phpunit --filter '/test_restore_course_with_same_stamp_questions with data set "formulas"/' mod/quiz/tests/backup/repeated_restore_test.php` to execute the test for qtype_formulas. Confirm that the test fails again, with the following message: "Failed asserting that 'xxx000' matches expected xxx001. /var/www/moodlecore/mod/quiz/tests/backup/repeated_restore_test.php: 595 " This shows it is now failing because the question ID on the restored course is incorrect, which is the expected behaviour. Remove the question/type/formulas directory and re-initialise phpunit: `php admin/tool/phpunit/init.php` Run the whole test file: `php vendor/bin/phpunit mod/quiz/tests/backup/repeated_restore_test.php` Confirm that all tests pass or skip for the core question types.
    • Hide

      Code verified against automated checks.

      Checked MDL-85556 using repository: https://github.com/marxjohnson/moodle.git

      More information about this report

      Built on: Mon Jun 2 15:10:53 UTC 2025

      Show
      Code verified against automated checks. Checked MDL-85556 using repository: https://github.com/marxjohnson/moodle.git MOODLE_500_STABLE (0 errors / 0 warnings) [branch: MDL-85556_500_STABLE | CI Job ] main (0 errors / 0 warnings) [branch: MDL-85556_main | CI Job ] More information about this report Built on: Mon Jun 2 15:10:53 UTC 2025
    • Show
      Launching automatic jobs for branch MDL-85556 _500_STABLE https://ci.moodle.org/view/Testing/job/DEV.02%20-%20Developer-requested%20PHPUnit/19468/ PHPUnit (sqlsrv) https://ci.moodle.org/view/Testing/job/DEV.01%20-%20Developer-requested%20Behat/66607/ Behat (NonJS - boost and classic) https://ci.moodle.org/view/Testing/job/DEV.01%20-%20Developer-requested%20Behat/66608/ Behat (Firefox - boost) Launching automatic jobs for branch MDL-85556 _main https://ci.moodle.org/view/Testing/job/DEV.02%20-%20Developer-requested%20PHPUnit/19469/ PHPUnit (sqlsrv) https://ci.moodle.org/view/Testing/job/DEV.01%20-%20Developer-requested%20Behat/66609/ Behat (NonJS - boost and classic) https://ci.moodle.org/view/Testing/job/DEV.01%20-%20Developer-requested%20Behat/66610/ Behat (Firefox - boost) https://ci.moodle.org/view/Testing/job/DEV.01%20-%20Developer-requested%20Behat/66611/ Behat (Firefox - classic) https://ci.moodle.org/view/Testing/job/DEV.01%20-%20Developer-requested%20Behat/66612/ App tests (stable app version) Built on: Tue May 27 10:25:33 UTC 2025

      During a restore, restore_move_module_questions_categories is supposed to find new question references that point to questions in an existing question bank, and point them back to the original questions. However the current query will find all questions using those question bank entires, not just those in the restored course. In certain circumstances, this could result in the course a backup was taken from having its quiz questions changed during a restore.

      This isn't easy to give straightforward reproduction steps for, as I believe it will only happen if you have a duplicate question with a qtype that hasn't been updated to take MDL-83541 into account. However, it breaks the unit test that is meant to check qtypes for compatibility, so it is worth fixing, and we can use the unit test to show it is resolved.

            marxjohnson Mark Johnson
            marxjohnson Mark Johnson
            Philipp Imhof Philipp Imhof
            Tim Hunt Tim Hunt
            Kim Jared Lucas Kim Jared Lucas
            Votes:
            1 Vote for this issue
            Watchers:
            12 Start watching this issue

              Created:
              Updated:
              Resolved:

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 1 hour, 15 minutes
                1h 15m

                  Error rendering 'clockify-timesheets-time-tracking-reports:timer-sidebar'. Please contact your Jira administrators.