MDL-79843 core_adminpresets: skip deprecated plugin types during apply
Presets are stored in the DB and may contain config for plugins which have since been deprecated. This just makes sure these are skipped when trying to apply the preset.
This commit is contained in:
@@ -1133,6 +1133,11 @@ class manager {
|
||||
'visiblevalue' => $visiblevalue,
|
||||
];
|
||||
|
||||
if ($plugininfo && $plugininfo->is_deprecated()) {
|
||||
$skipped[] = $data;
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($pluginclass == '\core\plugininfo\orphaned') {
|
||||
$skipped[] = $data;
|
||||
continue;
|
||||
|
||||
@@ -809,4 +809,41 @@ final class manager_test extends \advanced_testcase {
|
||||
$enabledplugins = \core\plugininfo\qtype::get_enabled_plugins();
|
||||
$this->assertArrayHasKey('truefalse', $enabledplugins);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test apply_preset for a deprecated plugin type.
|
||||
*
|
||||
* @runInSeparateProcess
|
||||
*
|
||||
* @covers ::apply_preset
|
||||
* @return void
|
||||
*/
|
||||
public function test_apply_preset_deprecated_plugintype(): void {
|
||||
global $CFG;
|
||||
$this->resetAfterTest();
|
||||
|
||||
// Create a preset.
|
||||
$generator = $this->getDataGenerator()->get_plugin_generator('core_adminpresets');
|
||||
$presetid = $generator->create_preset();
|
||||
|
||||
// Add a mock plugin into the preset. This plugin will be mocked and deprecated below.
|
||||
helper::add_plugin($presetid, 'fake', 'fullfeatured', true);
|
||||
|
||||
// Inject the mock plugin type + plugin, and deprecate it.
|
||||
$this->add_mocked_plugintype('fake', "$CFG->libdir/tests/fixtures/fakeplugins/fake", true);
|
||||
$this->add_mocked_plugin('fake', 'fullfeatured', $CFG->libdir . '/tests/fixtures/fakeplugins/fake/fullfeatured');
|
||||
|
||||
// Pre-flight check to ensure that the plugin is deprecated.
|
||||
$pluginman = \core\plugin_manager::instance();
|
||||
$plugininfo = $pluginman->get_plugin_info('fake_fullfeatured');
|
||||
// Expected, unit-test-only debugging, since \core\plugin_manager isn't aware of the mock plugininfo class for this type.
|
||||
$this->assertDebuggingCalled();
|
||||
$this->assertTrue($plugininfo->is_deprecated());
|
||||
|
||||
// Finally, check apply_preset method, verifying the deprecated plugin is skipped.
|
||||
$manager = new manager();
|
||||
[$applied, $skipped] = $manager->apply_preset($presetid);
|
||||
$this->assertdebuggingcalledcount(2); // Expected unit-test-only debugging, as above.
|
||||
$this->assertContains('fake', array_column($skipped, 'plugin'));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user