From 689a57fa74bf96a19c855c2c6e004fc1227d12fe Mon Sep 17 00:00:00 2001 From: Anupama Sarjoshi Date: Fri, 7 Oct 2022 11:41:48 +0100 Subject: [PATCH] MDL-75431 qbank: fix tests with CodeRunner installed --- .../update_question_version_status_test.php | 8 +++++++- .../bank/managecategories/tests/helper_test.php | 17 ++++++++++------- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/question/bank/editquestion/tests/external/update_question_version_status_test.php b/question/bank/editquestion/tests/external/update_question_version_status_test.php index b3e7185d21f..873cff6ac1a 100644 --- a/question/bank/editquestion/tests/external/update_question_version_status_test.php +++ b/question/bank/editquestion/tests/external/update_question_version_status_test.php @@ -93,12 +93,18 @@ class update_question_version_status_test extends \advanced_testcase { public function test_submit_status_does_not_create_a_new_version() { global $DB; $this->resetAfterTest(); + + // Find out the start count in 'question_versions' table. + $versioncount = $DB->count_records('question_versions'); + $questiongenerator = $this->getDataGenerator()->get_plugin_generator('core_question'); $cat = $questiongenerator->create_question_category(); $numq = $questiongenerator->create_question('essay', null, ['category' => $cat->id, 'name' => 'This is the first version']); $countcurrentrecords = $DB->count_records('question_versions'); - $this->assertEquals(1, $countcurrentrecords); + // New version count should be equal to start + 1. + $this->assertEquals($versioncount + 1, $countcurrentrecords); + $result = update_question_version_status::execute($numq->id, 'draft'); $countafterupdate = $DB->count_records('question_versions'); $this->assertEquals($countcurrentrecords, $countafterupdate); diff --git a/question/bank/managecategories/tests/helper_test.php b/question/bank/managecategories/tests/helper_test.php index 12c9cf113f7..6dd8e861954 100644 --- a/question/bank/managecategories/tests/helper_test.php +++ b/question/bank/managecategories/tests/helper_test.php @@ -65,7 +65,8 @@ class helper_test extends \advanced_testcase { $datagenerator = $this->getDataGenerator(); $this->course = $datagenerator->create_course(); - $this->quiz = $datagenerator->create_module('quiz', ['course' => $this->course->id]); + $this->quiz = $datagenerator->create_module('quiz', + ['course' => $this->course->id, 'name' => 'Quiz 1']); $this->qgenerator = $datagenerator->get_plugin_generator('core_question'); $this->context = \context_module::instance($this->quiz->cmid); @@ -232,14 +233,16 @@ class helper_test extends \advanced_testcase { // Validate that we have the array with the categories tree. $categorycontexts = helper::question_category_options($contexts->having_cap('moodle/question:add')); - foreach ($categorycontexts as $categorycontext) { - $this->assertCount(3, $categorycontext); - } + // The quiz name 'Quiz 1' is set in setUp function. + $categorycontext = $categorycontexts['Quiz: Quiz 1']; + $this->assertCount(3, $categorycontext); // Validate that we have the array with the categories tree and that top category is there. - $categorycontexts = helper::question_category_options($contexts->having_cap('moodle/question:add'), true); - foreach ($categorycontexts as $categorycontext) { - $this->assertCount(4, $categorycontext); + $newcategorycontexts = helper::question_category_options($contexts->having_cap('moodle/question:add'), true); + foreach ($newcategorycontexts as $key => $categorycontext) { + $oldcategorycontext = $categorycontexts[$key]; + $count = count($oldcategorycontext); + $this->assertCount($count + 1, $categorycontext); } } }