diff --git a/lib/tests/accesslib_test.php b/lib/tests/accesslib_test.php index df701bc20cb5..54df0b3bd851 100644 --- a/lib/tests/accesslib_test.php +++ b/lib/tests/accesslib_test.php @@ -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']); @@ -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')); + } } /**