MDL-81063 core: Add option to get core in list of components
This commit is contained in:
+13
-10
@@ -1407,18 +1407,16 @@ $cache = ' . var_export($cache, true) . ';
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of frankenstyle component names.
|
||||
* Returns a list of frankenstyle component names, including all plugins, subplugins, and subsystems.
|
||||
*
|
||||
* E.g.
|
||||
* [
|
||||
* 'core_course',
|
||||
* 'core_message',
|
||||
* 'mod_assign',
|
||||
* ...
|
||||
* ]
|
||||
* @return array the list of frankenstyle component names.
|
||||
* Note: By default the 'core' subsystem is not included.
|
||||
*
|
||||
* @param bool $includecore Whether to include the 'core' subsystem
|
||||
* @return string[] the list of frankenstyle component names.
|
||||
*/
|
||||
public static function get_component_names(): array {
|
||||
public static function get_component_names(
|
||||
bool $includecore = false,
|
||||
): array {
|
||||
$componentnames = [];
|
||||
// Get all plugins.
|
||||
foreach (self::get_plugin_types() as $plugintype => $typedir) {
|
||||
@@ -1430,6 +1428,11 @@ $cache = ' . var_export($cache, true) . ';
|
||||
foreach (self::get_core_subsystems() as $subsystemname => $subsystempath) {
|
||||
$componentnames[] = 'core_' . $subsystemname;
|
||||
}
|
||||
|
||||
if ($includecore) {
|
||||
$componentnames[] = 'core';
|
||||
}
|
||||
|
||||
return $componentnames;
|
||||
}
|
||||
|
||||
|
||||
@@ -873,22 +873,31 @@ class component_test extends advanced_testcase {
|
||||
|
||||
/**
|
||||
* Test the get_component_names() method.
|
||||
*
|
||||
* @dataProvider get_component_names_provider
|
||||
* @param bool $includecore Whether to include core in the list.
|
||||
* @param bool $coreexpected Whether core is expected to be in the list.
|
||||
*/
|
||||
public function test_get_component_names(): void {
|
||||
public function test_get_component_names(
|
||||
bool $includecore,
|
||||
bool $coreexpected,
|
||||
): void {
|
||||
global $CFG;
|
||||
$componentnames = \core_component::get_component_names();
|
||||
$componentnames = \core_component::get_component_names($includecore);
|
||||
|
||||
// We should have an entry for each plugin type.
|
||||
$plugintypes = \core_component::get_plugin_types();
|
||||
$numplugintypes = 0;
|
||||
foreach ($plugintypes as $type => $typedir) {
|
||||
foreach (\core_component::get_plugin_list($type) as $plugin) {
|
||||
$numplugintypes++;
|
||||
}
|
||||
foreach (array_keys($plugintypes) as $type) {
|
||||
$numplugintypes += count(\core_component::get_plugin_list($type));
|
||||
}
|
||||
// And an entry for each core subsystem.
|
||||
$numcomponents = $numplugintypes + count(\core_component::get_core_subsystems());
|
||||
|
||||
if ($coreexpected) {
|
||||
// Add one for core.
|
||||
$numcomponents++;
|
||||
}
|
||||
$this->assertEquals($numcomponents, count($componentnames));
|
||||
|
||||
// Check a few of the known plugin types to confirm their presence at their respective type index.
|
||||
@@ -896,6 +905,23 @@ class component_test extends advanced_testcase {
|
||||
$this->assertContains('mod_forum', $componentnames);
|
||||
$this->assertContains('tool_usertours', $componentnames);
|
||||
$this->assertContains('core_favourites', $componentnames);
|
||||
if ($coreexpected) {
|
||||
$this->assertContains('core', $componentnames);
|
||||
} else {
|
||||
$this->assertNotContains('core', $componentnames);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider for get_component_names() test.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function get_component_names_provider(): array {
|
||||
return [
|
||||
[false, false],
|
||||
[true, true],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user