Skip to content

Commit

Permalink
Merge pull request #35 from fdubost/master
Browse files Browse the repository at this point in the history
Add an assertion on Element
  • Loading branch information
FlorianLB committed May 19, 2013
2 parents a0cec5f + 1e9535b commit ba0b123
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
16 changes: 16 additions & 0 deletions Test/Asserters/Element.php
Expand Up @@ -92,6 +92,22 @@ public function getContent()
return $this->content;
}

public function hasContent()
{
$value = $this->valueIsSet()->value;

$nodes = $value->reduce(
function(\DOMNode $node) {
return ($node->nodeValue != '');
}
);

$this->assertCount($nodes, $this->getLocale()->_('Expected any content, found an empty value.'));

return $this;
}


protected function filterContent(DomCrawler $value)
{
$content = $this->content;
Expand Down
23 changes: 23 additions & 0 deletions tests/units/Test/Asserters/Element.php
Expand Up @@ -76,6 +76,29 @@ public function testHasNoContent()
;
}

public function testHasContent()
{
$this
->if($generator = new asserter\generator())
->and($parent = new \mock\atoum\AtoumBundle\Test\Asserters\Crawler($generator))
->and($object = new TestedClass($generator, $parent))
->and($elem = new \mock\DOMElement(uniqid('_'), 'a value'))
->and($crawler = new \mock\Symfony\Component\DomCrawler\Crawler(array($elem)))
->and($object->setWith($crawler))
->then
->object($object->hasContent())->isIdenticalTo($object)
->if($emptyElem = new \mock\DOMElement(uniqid('_'), ''))
->and($crawler = new \mock\Symfony\Component\DomCrawler\Crawler(array($emptyElem)))
->and($object->setWith($crawler))
->then
->exception(function() use($object) {
$object->hasContent();
})
->isInstanceOf('mageekguy\atoum\asserter\exception')
->hasMessage(sprintf($generator->getLocale()->_('Expected any content, found an empty value.')))
;
}

public function testWithAttibute()
{
$this
Expand Down

0 comments on commit ba0b123

Please sign in to comment.