MDL-78233 accesslib: remove unreliable test

Co-authored-by: Marina Glancy <[email protected]>
This commit is contained in:
Tasio
2025-06-17 10:32:14 +02:00
co-authored by Marina Glancy
parent a46fde054a
commit 007449c03f
-64
View File
@@ -4317,70 +4317,6 @@ final class accesslib_test extends advanced_testcase {
$this->assertEquals($perms1, $perms2);
}
/**
* Checks install performance in update_capabilities.
*
* @covers ::update_capabilities()
*/
public function test_update_capabilities_install_performance(): void {
global $DB;
$this->resetAfterTest();
// Get rid of all the capabilities for forum.
$testmodule = 'forum';
$DB->delete_records_select('capabilities', 'name LIKE ?', ['mod/' . $testmodule . ':%']);
$beforeq = $DB->perf_get_queries();
update_capabilities('mod_' . $testmodule);
$afterq = $DB->perf_get_queries();
// In my testing there are currently 237 queries; there were 373 before a performance
// fix. This test confirms performance doesn't degrade to near the previous level.
$this->assertLessThan(300, $afterq - $beforeq);
}
/**
* Checks install performance in update_capabilities when a new capability is cloned.
*
* This only has impact if there are a significant number of overrides of the existing
* capability.
*
* @covers ::update_capabilities()
*/
public function test_update_capabilities_clone_performance(): void {
global $DB;
$this->resetAfterTest();
// Create a bunch of activities in a course. In each one, override so manager doesn't have
// moodle/course:manageactivities.
$generator = $this->getDataGenerator();
$course = $generator->create_course();
$roleid = $DB->get_field('role', 'id', ['shortname' => 'manager']);
for ($i = 0; $i < 100; $i++) {
$page = $generator->create_module('page', ['course' => $course->id]);
$contextid = context_module::instance($page->cmid)->id;
assign_capability('moodle/course:manageactivities', CAP_PREVENT, $roleid, $contextid);
}
// Get rid of one of the capabilities for forum, which clones moodle/course:manageactivities.
$DB->delete_records('capabilities', ['name' => 'mod/forum:addinstance']);
// Clear the context cache to simulate a realistic situation where we don't already have
// all those contexts in the cache.
accesslib_clear_all_caches_for_unit_testing();
$beforeq = $DB->perf_get_queries();
update_capabilities('mod_forum');
$afterq = $DB->perf_get_queries();
// In my testing there are currently 214 queries after performance was improved for cloning,
// compared to 414 before. This test confirms performance doesn't degrade to near the
// previous level.
$this->assertLessThan(300, $afterq - $beforeq);
}
/**
* Tests update_capabilities when a capability is cloned, but there are existing settings
* for that capability.