Skip to content

Commit

Permalink
MDL-79843 core_access: test covering capabilities for deprecated plugins
Browse files Browse the repository at this point in the history
Access APIs still support the deprecated plugin during deprecation.
  • Loading branch information
snake committed Jul 31, 2024
1 parent 315d067 commit dcd2589
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions lib/tests/accesslib_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -1998,6 +1998,7 @@ public function test_get_deprecated_capability_info(): void {

// For now we have deprecated fake/access:fakecapability.
$capinfo = get_deprecated_capability_info('fake/access:fakecapability');
$this->assertNotNull(get_capability_info('fake/access:existingcapability'));
$this->assertNotEmpty($capinfo);
$this->assertEquals("The capability 'fake/access:fakecapability' is"
. " deprecated.This capability should not be used anymore.", $capinfo['fullmessage']);
Expand Down Expand Up @@ -5259,6 +5260,29 @@ public function test_get_navigation_filter_context(): void {
$filtercontext = context_helper::get_navigation_filter_context($coursecontext);
$this->assertInstanceOf('\context_system', $filtercontext);
}

/**
* Test access APIs when dealing with deprecated plugin types.
*
* Note: this injects a mocked plugin type into core_component and is a slow test that must be run in isolation.
*
* @runInSeparateProcess
*/
public function test_capabilities_deprecated_plugintype(): void {
$this->resetAfterTest();

global $CFG;
$this->add_mocked_plugintype('fake', "{$CFG->dirroot}/lib/tests/fixtures/fakeplugins/fake", true);
$this->add_mocked_plugin('fake', 'fullfeatured', "{$CFG->dirroot}/lib/tests/fixtures/fakeplugins/fake/fullfeatured");
update_capabilities('fake_fullfeatured');

$this->assertTrue(\core_component::is_deprecated_plugin_type('fake'));

$user = $this->getDataGenerator()->create_user();
$this->assertNotEmpty(get_capability_info('fake/fullfeatured:fakecapability'));
$this->assertTrue(has_capability('fake/fullfeatured:fakecapability',\core\context\system::instance(), $user));
$this->assertEquals('Fullfeatured capability description', get_capability_string('fake/fullfeatured:fakecapability'));
}
}

/**
Expand Down

0 comments on commit dcd2589

Please sign in to comment.