MDL-81386 output: Fix failure in PHPUnit when running filtered tests
[moodle.git] / lib / tests / output / icon_system_fontawesome_test.php
blob1aeed075aa3fad260f75b051f090d620d513af6e
1 <?php
2 // This file is part of Moodle - http://moodle.org/
3 //
4 // Moodle is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // Moodle is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
17 namespace core\output;
19 /**
20 * Unit tests for the FontAwesome icon system.
22 * @package core
23 * @copyright 2023 Andrew Nicols <andrew@nicols.co.uk>
24 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25 * @covers \core\output\icon_system_fontawesome
27 class icon_system_fontawesome_test extends \advanced_testcase {
29 /**
30 * Test that the specified icon has an SVG fallback.
32 public function test_svg_fallback(): void {
33 // This can't be tested using data provider because it initializes the theme system when running filtered tests.
34 $instance = icon_system::instance(icon_system::FONTAWESOME);
35 $icons = array_map(function($key) {
36 global $CFG;
37 [$component, $file] = explode(':', $key);
39 if ($component === 'core') {
40 $componentdir = $CFG->dirroot;
41 } else if ($component === 'theme') {
42 $componentdir = \core_component::get_component_directory('theme_' . \theme_config::DEFAULT_THEME);
43 } else {
44 $componentdir = \core_component::get_component_directory($component);
47 return [
48 'key' => $key,
49 'path' => $componentdir,
50 'filename' => $file,
52 }, array_keys($instance->get_icon_name_map()));
54 foreach ($icons as $icon) {
55 $this->assertTrue(
56 file_exists("{$icon['path']}/pix/{$icon['filename']}.svg"), "No SVG equivalent found for '{$icon['key']}'",