Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.3.x will end 7 October 2024 (12 months).
  • Bug fixes for security issues in 4.3.x will end 21 April 2025 (18 months).
  • PHP version: minimum PHP 8.0.0 Note: minimum PHP version has increased since Moodle 4.1. PHP 8.2.x is supported too.
   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.
  13  //
  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/>.
  16  
  17  namespace core\output;
  18  
  19  /**
  20   * Unit tests for the FontAwesome icon system.
  21   *
  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
  26   */
  27  class icon_system_fontawesome_test extends \advanced_testcase {
  28      /**
  29       * Returns a list of all mapped icons along with the component dir, and file name (without any suffix/extension).
  30       *
  31       * @return array
  32       */
  33      public function get_icon_name_map(): array {
  34          $instance = icon_system::instance(icon_system::FONTAWESOME);
  35          return array_map(function($key) {
  36              global $CFG;
  37              [$component, $file] = explode(':', $key);
  38  
  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);
  45              }
  46  
  47              return [
  48                  $key,
  49                  $componentdir,
  50                  $file,
  51              ];
  52          }, array_keys($instance->get_icon_name_map()));
  53      }
  54  
  55      /**
  56       * Test that the specified icon has an SVG fallback.
  57       *
  58       * @param string $key Icon key.
  59       * @param string $path Path to the component directory.
  60       * @param string $filename Icon filename.
  61       * @dataProvider get_icon_name_map
  62       */
  63      public function test_svg_fallback(string $key, string $path, string $filename): void {
  64          $this->assertTrue(file_exists("{$path}/pix/{$filename}.svg"), "No SVG equivalent found for '{$key}'");
  65      }
  66  }