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/>.
19 use xhtml_container_stack
;
21 defined('MOODLE_INTERNAL') ||
die();
24 require_once($CFG->libdir
. '/outputlib.php');
27 * Unit tests for the xhtml_container_stack class.
29 * These tests assume that developer debug mode is on which is enforced by our phpunit integration.
33 * @copyright 2009 Tim Hunt
34 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
36 class xhtml_container_stack_test
extends \advanced_testcase
{
37 public function test_push_then_pop() {
39 $stack = new xhtml_container_stack();
41 $stack->push('testtype', '</div>');
42 $html = $stack->pop('testtype');
44 $this->assertEquals('</div>', $html);
45 $this->assertDebuggingNotCalled();
48 public function test_mismatched_pop_prints_warning() {
50 $stack = new xhtml_container_stack();
51 $stack->push('testtype', '</div>');
53 $html = $stack->pop('mismatch');
55 $this->assertEquals('</div>', $html);
56 $this->assertDebuggingCalled();
59 public function test_pop_when_empty_prints_warning() {
61 $stack = new xhtml_container_stack();
63 $html = $stack->pop('testtype');
65 $this->assertEquals('', $html);
66 $this->assertDebuggingCalled();
69 public function test_correct_nesting() {
71 $stack = new xhtml_container_stack();
73 $stack->push('testdiv', '</div>');
74 $stack->push('testp', '</p>');
75 $html2 = $stack->pop('testp');
76 $html1 = $stack->pop('testdiv');
78 $this->assertEquals('</p>', $html2);
79 $this->assertEquals('</div>', $html1);
80 $this->assertDebuggingNotCalled();
83 public function test_pop_all_but_last() {
85 $stack = new xhtml_container_stack();
86 $stack->push('test1', '</h1>');
87 $stack->push('test2', '</h2>');
88 $stack->push('test3', '</h3>');
90 $html = $stack->pop_all_but_last();
92 $this->assertEquals('</h3></h2>', $html);
93 $this->assertDebuggingNotCalled();
98 public function test_pop_all_but_last_only_one() {
100 $stack = new xhtml_container_stack();
101 $stack->push('test1', '</h1>');
103 $html = $stack->pop_all_but_last();
105 $this->assertEquals('', $html);
106 $this->assertDebuggingNotCalled();
111 public function test_pop_all_but_last_empty() {
113 $stack = new xhtml_container_stack();
115 $html = $stack->pop_all_but_last();
117 $this->assertEquals('', $html);
118 $this->assertDebuggingNotCalled();
121 public function test_discard() {
123 $stack = new xhtml_container_stack();
124 $stack->push('test1', '</somethingdistinctive>');
129 $this->assertDebuggingNotCalled();