MDL-64506 phpunit: Update unit tests to use classic
[moodle.git] / lib / tests / mustache_template_finder_test.php
CommitLineData
fcc383db
DW
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 lib/classes/output/mustache_template_finder.php
19 *
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
24 */
25
26defined('MOODLE_INTERNAL') || die();
27
28use core\output\mustache_template_finder;
29
30/**
31 * Unit tests for the Mustache template finder class (contains logic about
32 * resolving mustache template locations.
33 */
34class core_output_mustache_template_finder_testcase extends advanced_testcase {
35
36 public function test_get_template_directories_for_component() {
37 global $CFG;
38
39 // Test a plugin.
e00f1c66 40 $dirs = mustache_template_finder::get_template_directories_for_component('mod_assign', 'classic');
fcc383db
DW
41
42 $correct = array(
e00f1c66
MM
43 'theme/classic/templates/mod_assign/',
44 'theme/boost/templates/mod_assign/',
fcc383db
DW
45 'mod/assign/templates/'
46 );
47 foreach ($dirs as $index => $dir) {
48 $this->assertSame($dir, $CFG->dirroot . '/' . $correct[$index]);
49 }
50 // Test a subsystem.
e00f1c66 51 $dirs = mustache_template_finder::get_template_directories_for_component('core_user', 'classic');
fcc383db
DW
52
53 $correct = array(
e00f1c66
MM
54 'theme/classic/templates/core_user/',
55 'theme/boost/templates/core_user/',
fcc383db
DW
56 'user/templates/'
57 );
58 foreach ($dirs as $index => $dir) {
59 $this->assertSame($dir, $CFG->dirroot . '/' . $correct[$index]);
60 }
61 // Test core.
e00f1c66 62 $dirs = mustache_template_finder::get_template_directories_for_component('core', 'classic');
fcc383db
DW
63
64 $correct = array(
e00f1c66
MM
65 'theme/classic/templates/core/',
66 'theme/boost/templates/core/',
fcc383db
DW
67 'lib/templates/'
68 );
69 foreach ($dirs as $index => $dir) {
70 $this->assertSame($dir, $CFG->dirroot . '/' . $correct[$index]);
71 }
72 return;
73 }
74
75 /**
76 * @expectedException coding_exception
77 */
78 public function test_invalid_get_template_directories_for_component() {
79 // Test something invalid.
e00f1c66 80 $dirs = mustache_template_finder::get_template_directories_for_component('octopus', 'classic');
fcc383db
DW
81 }
82
410034ee 83 public function test_get_template_filepath() {
fcc383db
DW
84 global $CFG;
85
e00f1c66 86 $filename = mustache_template_finder::get_template_filepath('core/pix_icon', 'classic');
fcc383db
DW
87 $correct = $CFG->dirroot . '/lib/templates/pix_icon.mustache';
88 $this->assertSame($correct, $filename);
89 }
90
91 /**
92 * @expectedException moodle_exception
93 */
410034ee 94 public function test_invalid_get_template_filepath() {
fcc383db 95 // Test something invalid.
e00f1c66 96 $dirs = mustache_template_finder::get_template_filepath('core/octopus', 'classic');
fcc383db
DW
97 }
98}