| 1 | efrain | 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 | /**
 | 
        
           |  |  | 18 |  * External functions test for record_feedback_action.
 | 
        
           |  |  | 19 |  *
 | 
        
           |  |  | 20 |  * @package    core
 | 
        
           |  |  | 21 |  * @category   test
 | 
        
           |  |  | 22 |  * @copyright  2020 Andrew Nicols <andrew@nicols.co.uk>
 | 
        
           |  |  | 23 |  * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 | 
        
           |  |  | 24 |  */
 | 
        
           |  |  | 25 |   | 
        
           |  |  | 26 | namespace core\external\output\icon_system;
 | 
        
           |  |  | 27 |   | 
        
           |  |  | 28 | use externallib_advanced_testcase;
 | 
        
           |  |  | 29 |   | 
        
           |  |  | 30 | defined('MOODLE_INTERNAL') || die();
 | 
        
           |  |  | 31 |   | 
        
           |  |  | 32 | global $CFG;
 | 
        
           |  |  | 33 |   | 
        
           |  |  | 34 | require_once($CFG->dirroot . '/webservice/tests/helpers.php');
 | 
        
           |  |  | 35 |   | 
        
           |  |  | 36 | /**
 | 
        
           |  |  | 37 |  * Class record_userfeedback_action_testcase
 | 
        
           |  |  | 38 |  *
 | 
        
           |  |  | 39 |  * @copyright  2020 Andrew Nicols <andrew@nicols.co.uk>
 | 
        
           |  |  | 40 |  * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 | 
        
           |  |  | 41 |  * @coversDefaultClass \core\external\output\icon_system\load_fontawesome_map
 | 
        
           |  |  | 42 |  */
 | 
        
           | 1441 | ariadna | 43 | final class load_fontawesome_map_test extends externallib_advanced_testcase {
 | 
        
           | 1 | efrain | 44 |     /**
 | 
        
           |  |  | 45 |      * Ensure that a valid theme which uses fontawesome returns a map.
 | 
        
           |  |  | 46 |      *
 | 
        
           |  |  | 47 |      * @covers ::execute_parameters
 | 
        
           |  |  | 48 |      * @covers ::execute
 | 
        
           |  |  | 49 |      * @covers ::execute_returns
 | 
        
           |  |  | 50 |      * @dataProvider valid_fontawesome_theme_provider
 | 
        
           |  |  | 51 |      * @param   string $themename
 | 
        
           |  |  | 52 |      */
 | 
        
           |  |  | 53 |     public function test_execute(string $themename): void {
 | 
        
           |  |  | 54 |         $result = load_fontawesome_map::execute($themename);
 | 
        
           |  |  | 55 |         $this->assertIsArray($result);
 | 
        
           |  |  | 56 |   | 
        
           |  |  | 57 |         foreach ($result as $value) {
 | 
        
           |  |  | 58 |             $this->assertArrayHasKey('component', $value);
 | 
        
           |  |  | 59 |             $this->assertArrayHasKey('pix', $value);
 | 
        
           |  |  | 60 |             $this->assertArrayHasKey('to', $value);
 | 
        
           |  |  | 61 |         }
 | 
        
           |  |  | 62 |     }
 | 
        
           |  |  | 63 |   | 
        
           |  |  | 64 |     /**
 | 
        
           |  |  | 65 |      * Ensure that an invalid theme cannot be loaded.
 | 
        
           |  |  | 66 |      */
 | 
        
           |  |  | 67 |     public function test_execute_invalid_themename(): void {
 | 
        
           |  |  | 68 |         $result = load_fontawesome_map::execute('invalidtheme');
 | 
        
           |  |  | 69 |         $this->assertDebuggingCalled(
 | 
        
           |  |  | 70 |             'This page should be using theme invalidtheme which cannot be initialised. Falling back to the site theme boost'
 | 
        
           |  |  | 71 |         );
 | 
        
           |  |  | 72 |         $this->assertIsArray($result);
 | 
        
           |  |  | 73 |     }
 | 
        
           |  |  | 74 |   | 
        
           |  |  | 75 |     /**
 | 
        
           |  |  | 76 |      * Data provider for valid themes to use with the execute function.
 | 
        
           |  |  | 77 |      *
 | 
        
           |  |  | 78 |      * @return  array
 | 
        
           |  |  | 79 |      */
 | 
        
           | 1441 | ariadna | 80 |     public static function valid_fontawesome_theme_provider(): array {
 | 
        
           | 1 | efrain | 81 |         return [
 | 
        
           |  |  | 82 |             'Boost theme' => ['boost'],
 | 
        
           |  |  | 83 |             'Classic theme (extends boost)' => ['classic'],
 | 
        
           |  |  | 84 |         ];
 | 
        
           |  |  | 85 |     }
 | 
        
           |  |  | 86 | }
 |