Created
May 1, 2013 15:39
-
-
Save vaclavbohac/5496044 to your computer and use it in GitHub Desktop.
Testing whether there is element with specified text in current selection.
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 | |
namespace Analyzer\Tests; | |
use Tester; | |
class DomQuery extends Tester\DomQuery | |
{ | |
/** | |
* @return DomQuery | |
*/ | |
public static function fromHtml($html) | |
{ | |
if (strpos($html, '<') === FALSE) { | |
$html = '<body>' . $html; | |
} | |
$dom = new \DOMDocument(); | |
$dom->loadHTML($html); | |
return simplexml_import_dom($dom, __CLASS__); | |
} | |
/** | |
* @param string $selector | |
* @param string $text | |
* @return bool | |
*/ | |
public function hasText($selector, $text) | |
{ | |
foreach ($this->find($selector) as $elem) { | |
if ((string) $elem === $text) { | |
return true; | |
} | |
} | |
return false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment