2 // This file is part of Moodle - http://moodle.org/
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.
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/>.
18 * Unit tests for lib/classes/output/external.php
19 * @author Guy Thomas <gthomas@moodlerooms.com>
20 * @copyright Copyright (c) 2017 Blackboard Inc.
21 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24 defined('MOODLE_INTERNAL') ||
die();
26 use core\output\external
;
28 require_once(__DIR__
.'/../../lib/externallib.php');
29 require_once(__DIR__
.'/../../lib/mustache/src/Mustache/Tokenizer.php');
30 require_once(__DIR__
.'/../../lib/mustache/src/Mustache/Parser.php');
33 * Class core_output_external_testcase - test \core\output\external class.
35 * @author Guy Thomas <gthomas@moodlerooms.com>
36 * @copyright Copyright (c) 2017 Blackboard Inc.
37 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
39 class core_output_external_testcase
extends base_testcase
{
42 * Ensure that stripping comments from templates does not mutilate the template body.
44 public function test_strip_template_comments() {
46 $templatebody = <<<'TBD'
47 <h1>{{# str }} pluginname, mod_lemmings {{/ str }}</h1>
49 <div>{{{unescapedtest}}}</div>
53 {{> mod_lemmings/lemmingprofile }}
54 {{# pix }} t/edit, core, Edit Lemming {{/ pix }}
57 {{^lemmings}}Sorry, no lemmings today{{/lemmings}}
58 <div id="{{ uniqid }}-tab-container">
60 <ul role="tablist" class="nav nav-tabs">
69 <div class="tab-content">
72 {{> core/notification_info}}
79 require(['jquery','core/tabs'], function($, tabs) {
81 var container = $("#{{ uniqid }}-tab-container");
82 tabs.create(container);
86 $templatewithcomment = <<<TBC
88 This file is part of Moodle - http://moodle.org/
90 Moodle is free software: you can redistribute it and/or modify
91 it under the terms of the GNU General Public License as published by
92 the Free Software Foundation, either version 3 of the License, or
93 (at your option) any later version.
95 Moodle is distributed in the hope that it will be useful,
96 but WITHOUT ANY WARRANTY; without even the implied warranty of
97 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
98 GNU General Public License for more details.
100 You should have received a copy of the GNU General Public License
101 along with Moodle. If not, see <http://www.gnu.org/licenses/>.
104 @template mod_lemmings/lemmings
108 The purpose of this template is to render a lot of lemmings.
110 Classes required for JS:
113 Data attributes required for JS:
116 Context variables required for this template:
117 * attributes Array of name / value pairs.
119 Example context (json):
122 { "name": "Lemmy Winks", "age" : 1, "size" : "big" },
123 { "name": "Rocky", "age" : 2, "size" : "small" }
130 Here's some more comment text
131 Note, there is no need to test bracketed variables inside comments as gherkin does not support that!
132 See this issue: https://github.com/mustache/spec/issues/8
136 // Ensure that the template when stripped of comments just includes the body.
137 $stripped = phpunit_util
::call_internal_method(null, 'strip_template_comments',
138 [$templatewithcomment], 'core\output\external');
139 $this->assertEquals(trim($templatebody), trim($stripped));
141 $tokenizer = new Mustache_Tokenizer();
142 $tokens = $tokenizer->scan($templatebody);
143 $parser = new Mustache_Parser();
144 $tree = $parser->parse($tokens);
145 $this->assertNotEmpty($tree);