Merge branch 'MDL-83253-404' of https://github.com/andrewnicols/moodle into MOODLE_404_STABLE

This commit is contained in:
Jun Pataleta 2024-10-15 11:44:36 +08:00
commit b2cf67e4f5
No known key found for this signature in database
GPG Key ID: F83510526D99E2C7
2 changed files with 39 additions and 1 deletions

View File

@ -2641,7 +2641,13 @@ function get_deprecated_capability_info($capabilityname) {
foreach ($allcaps as $cap) {
if (!in_array($cap['component'], $components)) {
$components[] = $cap['component'];
$defpath = core_component::get_component_directory($cap['component']).'/db/access.php';
$componentdir = core_component::get_component_directory($cap['component']);
if ($componentdir === null) {
continue;
}
$defpath = "{$componentdir}/db/access.php";
if (file_exists($defpath)) {
$deprecatedcapabilities = [];
require($defpath);

View File

@ -2114,6 +2114,38 @@ class accesslib_test extends advanced_testcase {
];
}
/**
* Test get_deprecated_capability_info() with an invalid component.
*
* @covers get_deprecated_capability_info
*/
public function test_get_deprecated_capability_info_invalid_component(): void {
global $DB;
$this->resetAfterTest();
// Set up a fake plugin.
$this->setup_fake_plugin('access');
// Add a plugin for an unrelated fake component.
$DB->insert_record('capabilities', [
'name' => 'mod/fake:addinstance',
'captype' => 'write',
'contextlevel' => CONTEXT_COURSE,
'component' => 'mod_fake',
'riskbitmask' => 4,
]);
// Purge the cache.
cache::make('core', 'capabilities')->purge();
// For now we have deprecated fake/access:fakecapability.
$this->assertNotEmpty($DB->get_record('capabilities', ['component' => 'mod_fake']));
$info = get_deprecated_capability_info('fake/access:fakecapability');
$this->assertIsArray($info);
$this->assertDebuggingNotCalled();
}
/**
* Test that assigning a fake cap does not return.
*