Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1441 ariadna 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.
13
//
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/>.
16
 
17
namespace core\output;
18
 
19
/**
20
 * Unit tests for the xhtml_container_stack class.
21
 *
22
 * These tests assume that developer debug mode is on which is enforced by our phpunit integration.
23
 *
24
 * @package   core
25
 * @category  test
26
 * @copyright 2009 Tim Hunt
27
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
28
 * @covers \core\output\xhtml_container_stacks
29
 */
30
final class xhtml_container_stack_test extends \advanced_testcase {
31
    public function test_push_then_pop(): void {
32
        // Set up.
33
        $stack = new xhtml_container_stack();
34
        // Exercise SUT.
35
        $stack->push('testtype', '</div>');
36
        $html = $stack->pop('testtype');
37
        // Verify outcome.
38
        $this->assertEquals('</div>', $html);
39
        $this->assertDebuggingNotCalled();
40
    }
41
 
42
    public function test_mismatched_pop_prints_warning(): void {
43
        // Set up.
44
        $stack = new xhtml_container_stack();
45
        $stack->push('testtype', '</div>');
46
        // Exercise SUT.
47
        $html = $stack->pop('mismatch');
48
        // Verify outcome.
49
        $this->assertEquals('</div>', $html);
50
        $this->assertDebuggingCalled();
51
    }
52
 
53
    public function test_pop_when_empty_prints_warning(): void {
54
        // Set up.
55
        $stack = new xhtml_container_stack();
56
        // Exercise SUT.
57
        $html = $stack->pop('testtype');
58
        // Verify outcome.
59
        $this->assertEquals('', $html);
60
        $this->assertDebuggingCalled();
61
    }
62
 
63
    public function test_correct_nesting(): void {
64
        // Set up.
65
        $stack = new xhtml_container_stack();
66
        // Exercise SUT.
67
        $stack->push('testdiv', '</div>');
68
        $stack->push('testp', '</p>');
69
        $html2 = $stack->pop('testp');
70
        $html1 = $stack->pop('testdiv');
71
        // Verify outcome.
72
        $this->assertEquals('</p>', $html2);
73
        $this->assertEquals('</div>', $html1);
74
        $this->assertDebuggingNotCalled();
75
    }
76
 
77
    public function test_pop_all_but_last(): void {
78
        // Set up.
79
        $stack = new xhtml_container_stack();
80
        $stack->push('test1', '</h1>');
81
        $stack->push('test2', '</h2>');
82
        $stack->push('test3', '</h3>');
83
        // Exercise SUT.
84
        $html = $stack->pop_all_but_last();
85
        // Verify outcome.
86
        $this->assertEquals('</h3></h2>', $html);
87
        $this->assertDebuggingNotCalled();
88
        // Tear down.
89
        $stack->discard();
90
    }
91
 
92
    public function test_pop_all_but_last_only_one(): void {
93
        // Set up.
94
        $stack = new xhtml_container_stack();
95
        $stack->push('test1', '</h1>');
96
        // Exercise SUT.
97
        $html = $stack->pop_all_but_last();
98
        // Verify outcome.
99
        $this->assertEquals('', $html);
100
        $this->assertDebuggingNotCalled();
101
        // Tear down.
102
        $stack->discard();
103
    }
104
 
105
    public function test_pop_all_but_last_empty(): void {
106
        // Set up.
107
        $stack = new xhtml_container_stack();
108
        // Exercise SUT.
109
        $html = $stack->pop_all_but_last();
110
        // Verify outcome.
111
        $this->assertEquals('', $html);
112
        $this->assertDebuggingNotCalled();
113
    }
114
 
115
    public function test_discard(): void {
116
        // Set up.
117
        $stack = new xhtml_container_stack();
118
        $stack->push('test1', '</somethingdistinctive>');
119
        $stack->discard();
120
        // Exercise SUT.
121
        $stack = null;
122
        // Verify outcome.
123
        $this->assertDebuggingNotCalled();
124
    }
125
}