From 32bd1137613c17a9f3a658a277dc07f8f172692e Mon Sep 17 00:00:00 2001 From: Tim Hunt Date: Tue, 24 Nov 2020 15:26:32 +0000 Subject: [PATCH] MDL-70321 question backup: fix MDL-47178 unit tests They were failing if you had CodeRunner installed --- question/tests/backup_test.php | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/question/tests/backup_test.php b/question/tests/backup_test.php index f5a4dba208f8f..91cafae780c70 100644 --- a/question/tests/backup_test.php +++ b/question/tests/backup_test.php @@ -225,7 +225,8 @@ public function test_backup_question_author_retained_when_enrolled() { // 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 @@ public function test_backup_question_author_retained_when_enrolled() { $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 @@ public function test_backup_question_author_retained_when_not_enrolled() { // 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 @@ public function test_backup_question_author_retained_when_not_enrolled() { $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 @@ public function test_backup_question_author_reset() { // 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 @@ public function test_backup_question_author_reset() { $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);