-
-
Save rmehner/336538 to your computer and use it in GitHub Desktop.
PHPUnit + Xpath
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
<?php | |
require_once 'PHPUnit/Framework.php'; | |
class Xml | |
{ | |
public function getNavigation() | |
{ | |
return '<ul id="navigation"> | |
<li><a href="/search">Suche</a></li> | |
<li><a href="/list">Liste</a></li> | |
<li><a href="/add">Hinzufügen</a></li> | |
</ul>'; | |
} | |
} | |
class XmlTest extends PHPUnit_Framework_TestCase | |
{ | |
public function setUp() | |
{ | |
$this->xml = new Xml(); | |
} | |
/** | |
* @test | |
*/ | |
public function It_shouldHaveTheCorrectElementCount() | |
{ | |
$this->assertSelectCount('#navigation li', 3, $this->xml->getNavigation()); | |
} | |
/** | |
* @test | |
*/ | |
public function It_shouldHaveTheCorrectElementCountByXpath() | |
{ | |
$xmlString = simplexml_load_string($this->xml->getNavigation()); | |
$this->assertEquals(3, sizeof($xmlString->xpath('/ul[@id="navigation"]/li'))); | |
} | |
/** | |
* @test | |
*/ | |
public function It_shouldHaveTheCorrectElementCountByAssertTag() | |
{ | |
$matcher = array( | |
'tag' => 'ul', | |
'attributes' => array('id' => 'navigation'), | |
'children' => array( | |
'count' => 3, | |
'only' => array('tag' => 'li') | |
) | |
); | |
$this->assertTag($matcher, $this->xml->getNavigation()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment