From bf817d52f45ee8f23cbe4e94c5d2ba49bb6300b3 Mon Sep 17 00:00:00 2001 From: Joshua Sherman Date: Sat, 4 Jan 2014 10:15:56 -0500 Subject: [PATCH] HTML class tests Wrote tests and dropped the ol' XHTML "self-closing" tags. Also fixed a bug with closing tags when no content was present. --- classes/HTML.php | 14 ++---- tests/TODO | 1 - tests/classes/HTMLTest.php | 99 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 103 insertions(+), 11 deletions(-) create mode 100644 tests/classes/HTMLTest.php diff --git a/classes/HTML.php b/classes/HTML.php index 35450b1..b7bf281 100644 --- a/classes/HTML.php +++ b/classes/HTML.php @@ -132,19 +132,13 @@ class HTML extends Object $html .= ' ' . $attribute . '="' . str_replace('"', '\"', $value) . '"'; } } - else - { - throw new Exception('Attributes must be an array.'); - } } - if ($contents || !in_array($element, $this->self_closing)) + $html .= '>'; + + if (!in_array($element, $this->self_closing)) { - $html .= '>' . $contents . ''; - } - else - { - $html .= ' />'; + $html .= $contents . ''; } return $html; diff --git a/tests/TODO b/tests/TODO index 24c89ed..8ac6a3b 100644 --- a/tests/TODO +++ b/tests/TODO @@ -1,7 +1,6 @@ Cache Config Database -HTML Model Module Profiler diff --git a/tests/classes/HTMLTest.php b/tests/classes/HTMLTest.php new file mode 100644 index 0000000..d5afb4e --- /dev/null +++ b/tests/classes/HTMLTest.php @@ -0,0 +1,99 @@ +html = HTML::getInstance(); + } + + public function testGetInstance() + { + $this->assertInstanceOf('HTML', $this->html); + } + + public function testInput() + { + $this->assertEquals('', $this->html->input()); + } + + public function testInputDateTimeLocal() + { + $this->assertEquals('', $this->html->inputDateTimeLocal()); + } + + public function testInputEmail() + { + $this->assertEquals('', $this->html->inputEmail()); + } + + public function testInputWithAttributes() + { + $this->assertEquals( + '', + $this->html->input([ + 'id' => 'id', + 'class' => 'class', + 'value' => 'value', + ]) + ); + } + + public function testInputPasswordWithLabel() + { + $this->assertEquals( + '', + $this->html->inputPassword([ + 'name' => 'password', + 'label' => 'Enter Password', + ]) + ); + + } + + public function testNestedElements() + { + $this->assertEquals( + '

Nested!

', + $this->html->div( + $this->html->p('Nested!') + ) + ); + } + + public function testNestedElementsWithAttributes() + { + $this->assertEquals( + '

Nested!

', + $this->html->div( + ['class' => 'outer'], + $this->html->p( + ['class' => 'inner'], + 'Nested!' + ) + ) + ); + } + + public function testClosingTag() + { + $this->assertEquals('', $this->html->textarea()); + } + + public function testElement() + { + $this->assertEquals('
', $this->html->element('div')); + } + + public function testReversedParameters() + { + $this->assertEquals( + '
string
', + $this->html->div('string', ['class' => 'fancy']) + ); + } +} + +?>