MDL-67271 core: Add test to find missing SVG icons
[moodle.git] / lib / tests / xhtml_container_stack_test.php
blobee1373195ef95b4731dcc0d3500b0c61dd611283
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.
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/>.
17 namespace core;
19 use xhtml_container_stack;
21 defined('MOODLE_INTERNAL') || die();
23 global $CFG;
24 require_once($CFG->libdir . '/outputlib.php');
26 /**
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.
31 * @package core
32 * @category test
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() {
38 // Set up.
39 $stack = new xhtml_container_stack();
40 // Exercise SUT.
41 $stack->push('testtype', '</div>');
42 $html = $stack->pop('testtype');
43 // Verify outcome.
44 $this->assertEquals('</div>', $html);
45 $this->assertDebuggingNotCalled();
48 public function test_mismatched_pop_prints_warning() {
49 // Set up.
50 $stack = new xhtml_container_stack();
51 $stack->push('testtype', '</div>');
52 // Exercise SUT.
53 $html = $stack->pop('mismatch');
54 // Verify outcome.
55 $this->assertEquals('</div>', $html);
56 $this->assertDebuggingCalled();
59 public function test_pop_when_empty_prints_warning() {
60 // Set up.
61 $stack = new xhtml_container_stack();
62 // Exercise SUT.
63 $html = $stack->pop('testtype');
64 // Verify outcome.
65 $this->assertEquals('', $html);
66 $this->assertDebuggingCalled();
69 public function test_correct_nesting() {
70 // Set up.
71 $stack = new xhtml_container_stack();
72 // Exercise SUT.
73 $stack->push('testdiv', '</div>');
74 $stack->push('testp', '</p>');
75 $html2 = $stack->pop('testp');
76 $html1 = $stack->pop('testdiv');
77 // Verify outcome.
78 $this->assertEquals('</p>', $html2);
79 $this->assertEquals('</div>', $html1);
80 $this->assertDebuggingNotCalled();
83 public function test_pop_all_but_last() {
84 // Set up.
85 $stack = new xhtml_container_stack();
86 $stack->push('test1', '</h1>');
87 $stack->push('test2', '</h2>');
88 $stack->push('test3', '</h3>');
89 // Exercise SUT.
90 $html = $stack->pop_all_but_last();
91 // Verify outcome.
92 $this->assertEquals('</h3></h2>', $html);
93 $this->assertDebuggingNotCalled();
94 // Tear down.
95 $stack->discard();
98 public function test_pop_all_but_last_only_one() {
99 // Set up.
100 $stack = new xhtml_container_stack();
101 $stack->push('test1', '</h1>');
102 // Exercise SUT.
103 $html = $stack->pop_all_but_last();
104 // Verify outcome.
105 $this->assertEquals('', $html);
106 $this->assertDebuggingNotCalled();
107 // Tear down.
108 $stack->discard();
111 public function test_pop_all_but_last_empty() {
112 // Set up.
113 $stack = new xhtml_container_stack();
114 // Exercise SUT.
115 $html = $stack->pop_all_but_last();
116 // Verify outcome.
117 $this->assertEquals('', $html);
118 $this->assertDebuggingNotCalled();
121 public function test_discard() {
122 // Set up.
123 $stack = new xhtml_container_stack();
124 $stack->push('test1', '</somethingdistinctive>');
125 $stack->discard();
126 // Exercise SUT.
127 $stack = null;
128 // Verify outcome.
129 $this->assertDebuggingNotCalled();