Merge branch 'wip-MDL-62796-master' of git://github.com/marinaglancy/moodle
[moodle.git] / lib / tests / mustache_template_finder_test.php
blobdf3237e9ed50a79fb5e2cc244a3943b72c9a8a47
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 /**
18 * Unit tests for lib/classes/output/mustache_template_finder.php
20 * @package core
21 * @category phpunit
22 * @copyright 2015 Damyon Wiese
23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
26 defined('MOODLE_INTERNAL') || die();
28 use core\output\mustache_template_finder;
30 /**
31 * Unit tests for the Mustache template finder class (contains logic about
32 * resolving mustache template locations.
34 class core_output_mustache_template_finder_testcase extends advanced_testcase {
36 public function test_get_template_directories_for_component() {
37 global $CFG;
39 // Test a plugin.
40 $dirs = mustache_template_finder::get_template_directories_for_component('mod_assign', 'clean');
42 $correct = array(
43 'theme/clean/templates/mod_assign/',
44 'theme/bootstrapbase/templates/mod_assign/',
45 'mod/assign/templates/'
47 foreach ($dirs as $index => $dir) {
48 $this->assertSame($dir, $CFG->dirroot . '/' . $correct[$index]);
50 // Test a subsystem.
51 $dirs = mustache_template_finder::get_template_directories_for_component('core_user', 'clean');
53 $correct = array(
54 'theme/clean/templates/core_user/',
55 'theme/bootstrapbase/templates/core_user/',
56 'user/templates/'
58 foreach ($dirs as $index => $dir) {
59 $this->assertSame($dir, $CFG->dirroot . '/' . $correct[$index]);
61 // Test core.
62 $dirs = mustache_template_finder::get_template_directories_for_component('core', 'clean');
64 $correct = array(
65 'theme/clean/templates/core/',
66 'theme/bootstrapbase/templates/core/',
67 'lib/templates/'
69 foreach ($dirs as $index => $dir) {
70 $this->assertSame($dir, $CFG->dirroot . '/' . $correct[$index]);
72 return;
75 /**
76 * @expectedException coding_exception
78 public function test_invalid_get_template_directories_for_component() {
79 // Test something invalid.
80 $dirs = mustache_template_finder::get_template_directories_for_component('octopus', 'clean');
83 public function test_get_template_filepath() {
84 global $CFG;
86 $filename = mustache_template_finder::get_template_filepath('core/pix_icon', 'clean');
87 $correct = $CFG->dirroot . '/lib/templates/pix_icon.mustache';
88 $this->assertSame($correct, $filename);
91 /**
92 * @expectedException moodle_exception
94 public function test_invalid_get_template_filepath() {
95 // Test something invalid.
96 $dirs = mustache_template_finder::get_template_filepath('core/octopus', 'clean');