Skip to content

Commit

Permalink
MDL-77105 core: Method to determine whether a plugin has monolog icons
Browse files Browse the repository at this point in the history
  • Loading branch information
junpataleta committed Mar 27, 2023
1 parent 09fd614 commit cd0afd5
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
18 changes: 18 additions & 0 deletions lib/classes/component.php
Expand Up @@ -1337,4 +1337,22 @@ public static function get_component_names() : array {
public static function get_core_api_names(): array {
return array_keys(self::get_core_apis());
}

/**
* Checks for the presence of monologo icons within a plugin.
*
* Only checks monologo icons in PNG and SVG formats as they are
* formats that can have transparent background.
*
* @param string $plugintype The plugin type.
* @param string $pluginname The plugin name.
* @return bool True if the plugin has a monologo icon
*/
public static function has_monologo_icon(string $plugintype, string $pluginname): bool {
$plugindir = core_component::get_plugin_directory($plugintype, $pluginname);
if ($plugindir === null) {
return false;
}
return file_exists("$plugindir/pix/monologo.svg") || file_exists("$plugindir/pix/monologo.png");
}
}
15 changes: 15 additions & 0 deletions lib/tests/component_test.php
Expand Up @@ -931,4 +931,19 @@ public function test_apis_json_validation() {
$this->assertLessThanOrEqual($attributes->allowedlevel2, $attributes->allowedspread, $message);
}
}

/**
* Test for monologo icons check in plugins.
*
* @covers core_component::has_monologo_icon
* @return void
*/
public function test_has_monologo_icon(): void {
// The Forum activity plugin has monologo icons.
$this->assertTrue(core_component::has_monologo_icon('mod', 'forum'));
// The core H5P subsystem doesn't have monologo icons.
$this->assertFalse(core_component::has_monologo_icon('core', 'h5p'));
// The function will return false for a non-existent component.
$this->assertFalse(core_component::has_monologo_icon('randomcomponent', 'h5p'));
}
}

0 comments on commit cd0afd5

Please sign in to comment.