From 7ca1b32808b660193e81f53860ca93360b063340 Mon Sep 17 00:00:00 2001 From: Tim Hunt Date: Fri, 22 Jun 2018 10:45:56 +0100 Subject: [PATCH] MDL-62781 question/privacy: fix tests with CodeRunner is installed The tests were assuming that no plugin ever created questions on install. Also change the tests to do the counting in the DB. That is more efficient. --- question/tests/privacy_provider_test.php | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/question/tests/privacy_provider_test.php b/question/tests/privacy_provider_test.php index 6760e7d8bc8..7b6ffca9cc2 100644 --- a/question/tests/privacy_provider_test.php +++ b/question/tests/privacy_provider_test.php @@ -261,15 +261,18 @@ class core_question_privacy_provider_testcase extends \core_privacy\tests\provid // Run the delete functions as default user. $this->setUser(); + // Find out how many questions are in the question bank to start with. + $questioncount = $DB->count_records('question'); + // The delete functions should do nothing here. - $this->assertCount(6, $DB->get_records('question')); + $this->assertEquals($questioncount, $DB->count_records('question')); // Delete for all users in context. provider::delete_data_for_all_users_in_context($expectedcontext); - $this->assertCount(6, $DB->get_records('question')); + $this->assertEquals($questioncount, $DB->count_records('question')); provider::delete_data_for_user($approvedcontextlist); - $this->assertCount(6, $DB->get_records('question')); + $this->assertEquals($questioncount, $DB->count_records('question')); } /** @@ -321,11 +324,14 @@ class core_question_privacy_provider_testcase extends \core_privacy\tests\provid [$context->id] ); + // Find out how many questions are in the question bank to start with. + $questioncount = $DB->count_records('question'); + // Delete the data and check it is removed. $this->setUser(); provider::delete_data_for_user($approvedcontextlist); - $this->assertCount(5, $DB->get_records('question')); + $this->assertEquals($questioncount, $DB->count_records('question')); $qrecord = $DB->get_record('question', ['id' => $q1->id]); $this->assertEquals(0, $qrecord->createdby); @@ -391,11 +397,14 @@ class core_question_privacy_provider_testcase extends \core_privacy\tests\provid $questiongenerator->update_question($q3); $q5 = $questiongenerator->create_question('shortanswer', null, array('category' => $othercat->id)); + // Find out how many questions are in the question bank to start with. + $questioncount = $DB->count_records('question'); + // Delete the data and check it is removed. $this->setUser(); provider::delete_data_for_all_users_in_context($context); - $this->assertCount(5, $DB->get_records('question')); + $this->assertEquals($questioncount, $DB->count_records('question')); $qrecord = $DB->get_record('question', ['id' => $q1->id]); $this->assertEquals(0, $qrecord->createdby); -- 2.43.0