-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from jjgrainger/feature/add-element-tests
Feature/add element tests
- Loading branch information
Showing
5 changed files
with
384 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,172 @@ | ||
|
||
<?php | ||
|
||
use HTML\Element; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class HasAttributesTest extends TestCase | ||
{ | ||
public function test_can_set_attributes() | ||
{ | ||
$element = new Element(); | ||
|
||
$attributes = [ | ||
'class' => 'container', | ||
]; | ||
|
||
$element->setAttributes($attributes); | ||
|
||
$this->assertEquals($element->getAttributes(), $attributes); | ||
} | ||
|
||
public function test_can_set_attribute() | ||
{ | ||
$element = new Element(); | ||
|
||
$attributes = [ | ||
'class' => 'container', | ||
]; | ||
|
||
$element->setAttributes($attributes); | ||
|
||
$element->setAttribute('id', 'main'); | ||
|
||
$attributes['id'] = 'main'; | ||
|
||
$this->assertEquals($element->getAttributes(), $attributes); | ||
} | ||
|
||
public function test_can_append_attribute() | ||
{ | ||
$element = new Element(); | ||
|
||
$attributes = [ | ||
'class' => 'container', | ||
]; | ||
|
||
$element->setAttributes($attributes); | ||
|
||
$element->appendAttribute('class', 'active'); | ||
|
||
$attributes['class'] .= ' active'; | ||
|
||
$this->assertEquals($element->getAttributes(), $attributes); | ||
} | ||
|
||
public function test_can_append_attributes_when_empty() | ||
{ | ||
$element = new Element(); | ||
|
||
|
||
$element->appendAttribute('class', 'active'); | ||
|
||
$this->assertEquals($element->getAttributes(), ['class' => 'active']); | ||
} | ||
|
||
public function test_can_get_attributes() | ||
{ | ||
$element = new Element(); | ||
|
||
$attributes = [ | ||
'class' => 'container', | ||
]; | ||
|
||
$element->setAttributes($attributes); | ||
|
||
$this->assertEquals($element->getAttributes(), $attributes); | ||
} | ||
|
||
public function test_can_get_attribute() | ||
{ | ||
$element = new Element(); | ||
|
||
$attributes = [ | ||
'class' => 'container', | ||
]; | ||
|
||
$element->setAttributes($attributes); | ||
|
||
$this->assertEquals($element->getAttribute('class'), 'container'); | ||
} | ||
|
||
public function test_has_attributes() | ||
{ | ||
$element = new Element(); | ||
|
||
$empty = $element->hasAttributes(); | ||
|
||
$attributes = [ | ||
'class' => 'container', | ||
]; | ||
|
||
$element->setAttributes($attributes); | ||
|
||
$this->assertTrue($element->hasAttributes()); | ||
$this->assertFalse($empty); | ||
} | ||
|
||
public function test_has_attribute_by_key() | ||
{ | ||
$element = new Element(); | ||
|
||
$attributes = [ | ||
'class' => 'container', | ||
]; | ||
|
||
$element->setAttributes($attributes); | ||
|
||
$this->assertTrue($element->hasAttribute('class')); | ||
$this->assertFalse($element->hasAttribute('id')); | ||
} | ||
|
||
public function test_can_remove_attributes() | ||
{ | ||
$element = new Element(); | ||
|
||
$attributes = [ | ||
'class' => 'container', | ||
]; | ||
|
||
$element->setAttributes($attributes); | ||
|
||
$this->assertTrue($element->hasAttributes()); | ||
|
||
$element->removeAttributes(); | ||
|
||
$this->assertFalse($element->hasAttributes()); | ||
$this->assertEquals($element->getAttributes(), []); | ||
} | ||
|
||
public function test_can_remove_attribute_by_key() | ||
{ | ||
$element = new Element(); | ||
|
||
$attributes = [ | ||
'class' => 'container', | ||
'id' => 'main', | ||
]; | ||
|
||
$element->setAttributes($attributes); | ||
|
||
$element->removeAttribute('id'); | ||
|
||
$this->assertFalse($element->hasAttribute('id')); | ||
$this->assertEquals($element->getAttributes(), ['class' => 'container']); | ||
} | ||
|
||
public function test_can_render_attributes() | ||
{ | ||
$element = new Element(); | ||
|
||
$attributes = [ | ||
'class' => 'container', | ||
'id' => 'main', | ||
]; | ||
|
||
$element->setAttributes($attributes); | ||
|
||
$this->assertEquals($element->renderAttributes(), 'class="container" id="main"'); | ||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
<?php | ||
|
||
use HTML\Element; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class HasChildrenTest extends TestCase | ||
{ | ||
public function test_can_set_children() | ||
{ | ||
$element = new Element(); | ||
|
||
$children = [ | ||
new Element(), | ||
]; | ||
|
||
$element->setChildren($children); | ||
|
||
$this->assertEquals($element->getChildren(), $children); | ||
} | ||
|
||
public function test_can_add_children() | ||
{ | ||
$element = new Element(); | ||
|
||
$child = new Element(); | ||
|
||
$element->addChild($child); | ||
|
||
$this->assertEquals($element->getChildren(), [$child]); | ||
} | ||
|
||
public function test_can_get_children() | ||
{ | ||
$element = new Element(); | ||
|
||
$children = [ | ||
new Element(), | ||
new Element(), | ||
new Element(), | ||
]; | ||
|
||
$element->setChildren($children); | ||
|
||
$this->assertEquals($element->getChildren(), $children); | ||
} | ||
|
||
public function test_has_children() | ||
{ | ||
$element = new Element(); | ||
|
||
$this->assertFalse($element->hasChildren()); | ||
|
||
$element->addChild(new Element()); | ||
|
||
$this->assertTrue($element->hasChildren()); | ||
} | ||
|
||
public function test_can_render_children() | ||
{ | ||
$element = new Element(); | ||
|
||
$children = [ | ||
(new Element('li'))->setContent('List item 1'), | ||
(new Element('li'))->setContent('List item 2'), | ||
]; | ||
|
||
$element->setChildren($children); | ||
|
||
$this->assertEquals($element->renderChildren(), '<li>List item 1</li><li>List item 2</li>'); | ||
} | ||
} |
Oops, something went wrong.