Differences Between: [Versions 310 and 311] [Versions 310 and 400] [Versions 310 and 401] [Versions 310 and 402] [Versions 310 and 403] [Versions 39 and 310]
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 * Unit tests for requirejs loader. 19 * 20 * @package core 21 * @author Damyon Wiese <damyon@moodle.com> 22 * @copyright 2016 Damyon Wiese 23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 24 */ 25 26 defined('MOODLE_INTERNAL') || die(); 27 28 /** 29 * Unit tests for requirejs. 30 * 31 * @package core 32 * @author Damyon Wiese <damyon@moodle.com> 33 * @copyright 2016 Damyon Wiese 34 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 35 */ 36 class core_requirejs_testcase extends advanced_testcase { 37 38 /** 39 * Test requirejs loader 40 */ 41 public function test_requirejs() { 42 global $CFG; 43 44 // Find a core module. 45 $result = core_requirejs::find_one_amd_module('core', 'templates', false); 46 $expected = ['core/templates' => $CFG->dirroot . '/lib/amd/build/templates.min.js']; 47 $this->assertEquals($expected, $result); 48 49 $result = core_requirejs::find_one_amd_module('core', 'templates', true); 50 $expected = ['core/templates' => $CFG->dirroot . '/lib/amd/src/templates.js']; 51 $this->assertEquals($expected, $result); 52 53 // Find a subsystem module (none exist yet). 54 $result = core_requirejs::find_one_amd_module('core_group', 'doesnotexist', false); 55 $expected = []; 56 $this->assertEquals($expected, $result); 57 58 // Find a plugin module. 59 $result = core_requirejs::find_one_amd_module('mod_assign', 'grading_panel', true); 60 $expected = ['mod_assign/grading_panel' => $CFG->dirroot . '/mod/assign/amd/src/grading_panel.js']; 61 $this->assertEquals($expected, $result); 62 63 // Find all modules - no debugging. 64 $result = core_requirejs::find_all_amd_modules(true); 65 foreach ($result as $key => $path) { 66 // Lets verify the first part of the key is a valid component name and the second part correctly contains "min" or not. 67 list($component, $template) = explode('/', $key, 2); 68 // Can we resolve it to a valid dir? 69 $dir = core_component::get_component_directory($component); 70 $this->assertNotEmpty($dir); 71 72 // Only "core" is allowed to have no _ in component names. 73 if (strpos($component, '_') === false) { 74 $this->assertEquals('core', $component); 75 } 76 $this->assertStringNotContainsString('.min', $path); 77 } 78 79 // Find all modules - debugging. 80 $result = core_requirejs::find_all_amd_modules(false); 81 foreach ($result as $key => $path) { 82 // Lets verify the first part of the key is a valid component name and the second part correctly contains "min" or not. 83 list($component, $template) = explode('/', $key, 2); 84 $dir = core_component::get_component_directory($component); 85 $this->assertNotEmpty($dir); 86 // Only "core" is allowed to have no _ in component names. 87 if (strpos($component, '_') === false) { 88 $this->assertEquals('core', $component); 89 } 90 91 $this->assertStringContainsString('.min', $path); 92 } 93 94 } 95 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body