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.
This commit is contained in:
Joshua Sherman 2014-01-04 10:15:56 -05:00
parent f0b5bfa459
commit bf817d52f4
3 changed files with 103 additions and 11 deletions

View file

@ -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 . '</' . $element . '>';
}
else
{
$html .= ' />';
$html .= $contents . '</' . $element . '>';
}
return $html;

View file

@ -1,7 +1,6 @@
Cache
Config
Database
HTML
Model
Module
Profiler

View file

@ -0,0 +1,99 @@
<?php
class HTMLTest extends PHPUnit_Framework_TestCase
{
private $html;
public function setUp()
{
$this->html = HTML::getInstance();
}
public function testGetInstance()
{
$this->assertInstanceOf('HTML', $this->html);
}
public function testInput()
{
$this->assertEquals('<input type="text">', $this->html->input());
}
public function testInputDateTimeLocal()
{
$this->assertEquals('<input type="datetime-local">', $this->html->inputDateTimeLocal());
}
public function testInputEmail()
{
$this->assertEquals('<input type="email">', $this->html->inputEmail());
}
public function testInputWithAttributes()
{
$this->assertEquals(
'<input id="id" class="class" value="value" type="text">',
$this->html->input([
'id' => 'id',
'class' => 'class',
'value' => 'value',
])
);
}
public function testInputPasswordWithLabel()
{
$this->assertEquals(
'<label for="password">Enter Password</label><input name="password" type="password">',
$this->html->inputPassword([
'name' => 'password',
'label' => 'Enter Password',
])
);
}
public function testNestedElements()
{
$this->assertEquals(
'<div><p>Nested!</p></div>',
$this->html->div(
$this->html->p('Nested!')
)
);
}
public function testNestedElementsWithAttributes()
{
$this->assertEquals(
'<div class="outer"><p class="inner">Nested!</p></div>',
$this->html->div(
['class' => 'outer'],
$this->html->p(
['class' => 'inner'],
'Nested!'
)
)
);
}
public function testClosingTag()
{
$this->assertEquals('<textarea></textarea>', $this->html->textarea());
}
public function testElement()
{
$this->assertEquals('<div></div>', $this->html->element('div'));
}
public function testReversedParameters()
{
$this->assertEquals(
'<div class="fancy">string</div>',
$this->html->div('string', ['class' => 'fancy'])
);
}
}
?>