MDL-79843 core: support mocking of deprecated plugins and subplugins

This adds support to the existing, shallow fakeplugin mocks provided by:
- advanced_testcase::add_mocked_plugintype() and
- advanced_testcase::add_mocked_plugin()
and adds new methods for deep mocking fakeplugins:
- advanced_testcase::add_full_mocked_plugintype()
- advanced_testcase::deprecate_full_mocked_plugintype()
- advanced_testcase::delete_full_mock_plugintype()
Deep mocking is required to test \core\component itself.
This commit is contained in:
Jake Dallimore
2025-01-28 14:42:19 +08:00
parent 6b1a63189b
commit a644d26c5e
2 changed files with 179 additions and 2 deletions
+5 -2
View File
@@ -772,22 +772,25 @@ abstract class advanced_testcase extends base_testcase {
*
* @param string $plugintype The name of the plugintype
* @param string $path The path to the plugintype's root
* @param bool $deprecated whether to add the plugintype as a deprecated plugin type.
*/
protected function add_mocked_plugintype(
string $plugintype,
string $path,
bool $deprecated = false,
): void {
require_phpunit_isolation();
$mockedcomponent = new \ReflectionClass(\core_component::class);
$plugintypes = $mockedcomponent->getStaticPropertyValue('plugintypes');
$propertyname = $deprecated ? 'deprecatedplugintypes' : 'plugintypes';
$plugintypes = $mockedcomponent->getStaticPropertyValue($propertyname);
if (array_key_exists($plugintype, $plugintypes)) {
throw new \coding_exception("The plugintype '{$plugintype}' already exists.");
}
$plugintypes[$plugintype] = $path;
$mockedcomponent->setStaticPropertyValue('plugintypes', $plugintypes);
$mockedcomponent->setStaticPropertyValue($propertyname, $plugintypes);
$this->resetDebugging();
}