Skip to content

Instantly share code, notes, and snippets.

@vaclavbohac
Created May 1, 2013 15:39
Show Gist options
  • Save vaclavbohac/5496044 to your computer and use it in GitHub Desktop.
Save vaclavbohac/5496044 to your computer and use it in GitHub Desktop.
Testing whether there is element with specified text in current selection.
<?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