. /** * Unit tests for lib/classes/output/external.php * @author Guy Thomas * @copyright Copyright (c) 2017 Blackboard Inc. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ defined('MOODLE_INTERNAL') || die(); use core\output\external; require_once(__DIR__.'/../../lib/externallib.php'); require_once(__DIR__.'/../../lib/mustache/src/Mustache/Tokenizer.php'); require_once(__DIR__.'/../../lib/mustache/src/Mustache/Parser.php'); /** * Class core_output_external_testcase - test \core\output\external class. * @package core * @author Guy Thomas * @copyright Copyright (c) 2017 Blackboard Inc. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class core_output_external_testcase extends base_testcase { /** * Ensure that stripping comments from templates does not mutilate the template body. */ public function test_strip_template_comments() { $templatebody = <<<'TBD'

{{# str }} pluginname, mod_lemmings {{/ str }}

{{test}}
{{{unescapedtest}}}
{{#lemmings}}

{{name}}

{{> mod_lemmings/lemmingprofile }} {{# pix }} t/edit, core, Edit Lemming {{/ pix }}
{{/lemmings}} {{^lemmings}}Sorry, no lemmings today{{/lemmings}}
{{# tabheader }} {{/ tabheader }} {{# tabbody }}
{{# tabcontent }} {{# tabs }} {{> core/notification_info}} {{/ tabs }} {{/ tabcontent }}
{{/ tabbody }}
{{#js}} require(['jquery','core/tabs'], function($, tabs) { var container = $("#{{ uniqid }}-tab-container"); tabs.create(container); }); {{/js}} TBD; $templatewithcomment = <<. }} {{! @template mod_lemmings/lemmings Lemmings template. The purpose of this template is to render a lot of lemmings. Classes required for JS: * none Data attributes required for JS: * none Context variables required for this template: * attributes Array of name / value pairs. Example context (json): { "lemmings": [ { "name": "Lemmy Winks", "age" : 1, "size" : "big" }, { "name": "Rocky", "age" : 2, "size" : "small" } ] } }} $templatebody {{! Here's some more comment text Note, there is no need to test bracketed variables inside comments as gherkin does not support that! See this issue: https://github.com/mustache/spec/issues/8 }} TBC; // Ensure that the template when stripped of comments just includes the body. $stripped = phpunit_util::call_internal_method(null, 'strip_template_comments', [$templatewithcomment], 'core\output\external'); $this->assertEquals(trim($templatebody), trim($stripped)); $tokenizer = new Mustache_Tokenizer(); $tokens = $tokenizer->scan($templatebody); $parser = new Mustache_Parser(); $tree = $parser->parse($tokens); $this->assertNotEmpty($tree); } }