MDL-70321 question backup: fix MDL-47178 unit tests
authorTim Hunt <T.J.Hunt@open.ac.uk>
Tue, 24 Nov 2020 15:26:32 +0000 (15:26 +0000)
committerTim Hunt <T.J.Hunt@open.ac.uk>
Tue, 24 Nov 2020 15:29:41 +0000 (15:29 +0000)
They were failing if you had CodeRunner installed

question/tests/backup_test.php

index f5a4dba..91cafae 100644 (file)
@@ -225,7 +225,8 @@ class core_question_backup_testcase extends advanced_testcase {
         // Create a question.
         $questiongenerator = $this->getDataGenerator()->get_plugin_generator('core_question');
         $questioncategory = $questiongenerator->create_question_category();
-        $overrides = ['category' => $questioncategory->id, 'createdby' => $user->id, 'modifiedby' => $user->id];
+        $overrides = ['name' => 'Test question', 'category' => $questioncategory->id,
+                'createdby' => $user->id, 'modifiedby' => $user->id];
         $question = $questiongenerator->create_question('truefalse', null, $overrides);
 
         // Create a quiz and a questions.
@@ -261,7 +262,7 @@ class core_question_backup_testcase extends advanced_testcase {
         $rc->destroy();
 
         // Test the question author.
-        $questions = $DB->get_records('question');
+        $questions = $DB->get_records('question', ['name' => 'Test question']);
         $this->assertCount(1, $questions);
         $question3 = array_shift($questions);
         $this->assertEquals($user->id, $question3->createdby);
@@ -285,7 +286,8 @@ class core_question_backup_testcase extends advanced_testcase {
         // Create a question.
         $questiongenerator = $this->getDataGenerator()->get_plugin_generator('core_question');
         $questioncategory = $questiongenerator->create_question_category();
-        $overrides = ['category' => $questioncategory->id, 'createdby' => $user->id, 'modifiedby' => $user->id];
+        $overrides = ['name' => 'Test question', 'category' => $questioncategory->id,
+                'createdby' => $user->id, 'modifiedby' => $user->id];
         $question = $questiongenerator->create_question('truefalse', null, $overrides);
 
         // Create a quiz and a questions.
@@ -317,7 +319,7 @@ class core_question_backup_testcase extends advanced_testcase {
         $rc->destroy();
 
         // Test the question author.
-        $questions = $DB->get_records('question');
+        $questions = $DB->get_records('question', ['name' => 'Test question']);
         $this->assertCount(1, $questions);
         $question = array_shift($questions);
         $this->assertEquals($user->id, $question->createdby);
@@ -341,7 +343,8 @@ class core_question_backup_testcase extends advanced_testcase {
         // Create a question.
         $questiongenerator = $this->getDataGenerator()->get_plugin_generator('core_question');
         $questioncategory = $questiongenerator->create_question_category();
-        $overrides = ['category' => $questioncategory->id, 'createdby' => $user->id, 'modifiedby' => $user->id];
+        $overrides = ['name' => 'Test question', 'category' => $questioncategory->id,
+                'createdby' => $user->id, 'modifiedby' => $user->id];
         $question = $questiongenerator->create_question('truefalse', null, $overrides);
 
         // Create a quiz and a questions.
@@ -376,7 +379,7 @@ class core_question_backup_testcase extends advanced_testcase {
         $rc->destroy();
 
         // Test the question author.
-        $questions = $DB->get_records('question');
+        $questions = $DB->get_records('question', ['name' => 'Test question']);
         $this->assertCount(1, $questions);
         $question = array_shift($questions);
         $this->assertEquals($USER->id, $question->createdby);