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.
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user