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 xhtml stack.
22 * @copyright 2009 Tim Hunt
23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later (5)
26 defined('MOODLE_INTERNAL') ||
die();
29 require_once($CFG->libdir
. '/outputlib.php');
33 * Unit tests for the xhtml_container_stack class.
35 * These tests assume that developer debug mode is on which is enforced by our phpunit integration.
37 * @copyright 2009 Tim Hunt
38 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
40 class core_xhtml_container_stack_testcase
extends advanced_testcase
{
41 public function test_push_then_pop() {
43 $stack = new xhtml_container_stack();
45 $stack->push('testtype', '</div>');
46 $html = $stack->pop('testtype');
48 $this->assertEquals('</div>', $html);
49 $this->assertDebuggingNotCalled();
52 public function test_mismatched_pop_prints_warning() {
54 $stack = new xhtml_container_stack();
55 $stack->push('testtype', '</div>');
57 $html = $stack->pop('mismatch');
59 $this->assertEquals('</div>', $html);
60 $this->assertDebuggingCalled();
63 public function test_pop_when_empty_prints_warning() {
65 $stack = new xhtml_container_stack();
67 $html = $stack->pop('testtype');
69 $this->assertEquals('', $html);
70 $this->assertDebuggingCalled();
73 public function test_correct_nesting() {
75 $stack = new xhtml_container_stack();
77 $stack->push('testdiv', '</div>');
78 $stack->push('testp', '</p>');
79 $html2 = $stack->pop('testp');
80 $html1 = $stack->pop('testdiv');
82 $this->assertEquals('</p>', $html2);
83 $this->assertEquals('</div>', $html1);
84 $this->assertDebuggingNotCalled();
87 public function test_pop_all_but_last() {
89 $stack = new xhtml_container_stack();
90 $stack->push('test1', '</h1>');
91 $stack->push('test2', '</h2>');
92 $stack->push('test3', '</h3>');
94 $html = $stack->pop_all_but_last();
96 $this->assertEquals('</h3></h2>', $html);
97 $this->assertDebuggingNotCalled();
102 public function test_pop_all_but_last_only_one() {
104 $stack = new xhtml_container_stack();
105 $stack->push('test1', '</h1>');
107 $html = $stack->pop_all_but_last();
109 $this->assertEquals('', $html);
110 $this->assertDebuggingNotCalled();
115 public function test_pop_all_but_last_empty() {
117 $stack = new xhtml_container_stack();
119 $html = $stack->pop_all_but_last();
121 $this->assertEquals('', $html);
122 $this->assertDebuggingNotCalled();
125 public function test_discard() {
127 $stack = new xhtml_container_stack();
128 $stack->push('test1', '</somethingdistinctive>');
133 $this->assertDebuggingNotCalled();