. namespace core\output; /** * Unit tests for the xhtml_container_stack class. * * These tests assume that developer debug mode is on which is enforced by our phpunit integration. * * @package core * @category test * @copyright 2009 Tim Hunt * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @covers \core\output\xhtml_container_stacks */ final class xhtml_container_stack_test extends \advanced_testcase { public function test_push_then_pop(): void { // Set up. $stack = new xhtml_container_stack(); // Exercise SUT. $stack->push('testtype', ''); $html = $stack->pop('testtype'); // Verify outcome. $this->assertEquals('', $html); $this->assertDebuggingNotCalled(); } public function test_mismatched_pop_prints_warning(): void { // Set up. $stack = new xhtml_container_stack(); $stack->push('testtype', ''); // Exercise SUT. $html = $stack->pop('mismatch'); // Verify outcome. $this->assertEquals('', $html); $this->assertDebuggingCalled(); } public function test_pop_when_empty_prints_warning(): void { // Set up. $stack = new xhtml_container_stack(); // Exercise SUT. $html = $stack->pop('testtype'); // Verify outcome. $this->assertEquals('', $html); $this->assertDebuggingCalled(); } public function test_correct_nesting(): void { // Set up. $stack = new xhtml_container_stack(); // Exercise SUT. $stack->push('testdiv', ''); $stack->push('testp', '

'); $html2 = $stack->pop('testp'); $html1 = $stack->pop('testdiv'); // Verify outcome. $this->assertEquals('

', $html2); $this->assertEquals('', $html1); $this->assertDebuggingNotCalled(); } public function test_pop_all_but_last(): void { // Set up. $stack = new xhtml_container_stack(); $stack->push('test1', ''); $stack->push('test2', ''); $stack->push('test3', ''); // Exercise SUT. $html = $stack->pop_all_but_last(); // Verify outcome. $this->assertEquals('', $html); $this->assertDebuggingNotCalled(); // Tear down. $stack->discard(); } public function test_pop_all_but_last_only_one(): void { // Set up. $stack = new xhtml_container_stack(); $stack->push('test1', ''); // Exercise SUT. $html = $stack->pop_all_but_last(); // Verify outcome. $this->assertEquals('', $html); $this->assertDebuggingNotCalled(); // Tear down. $stack->discard(); } public function test_pop_all_but_last_empty(): void { // Set up. $stack = new xhtml_container_stack(); // Exercise SUT. $html = $stack->pop_all_but_last(); // Verify outcome. $this->assertEquals('', $html); $this->assertDebuggingNotCalled(); } public function test_discard(): void { // Set up. $stack = new xhtml_container_stack(); $stack->push('test1', ''); $stack->discard(); // Exercise SUT. $stack = null; // Verify outcome. $this->assertDebuggingNotCalled(); } }