Source for file CSSContentParser.php
Documentation is available at CSSContentParser.php
* CSSContentParser enables parsing & assertion running of HTML content via CSS selectors.
* It works by converting the content to XHTML using tidy, rewriting the CSS selectors as XPath queries, and executing
* It was built to facilitate testing using PHPUnit and contains a number of assert methods that will throw PHPUnit
* assertion exception when applicable.
$tidy = `echo $CLI_content | tidy -n -q -utf8 -asxhtml` ;
$tidy = str_replace('xmlns="http://www.w3.org/1999/xhtml"','',$tidy);
$this->simpleXML = new SimpleXMLElement($tidy);
* Returns a number of SimpleXML elements that match the given CSS selector.
* Currently the selector engine only supports querying by tag, id, and classs
* Converts a CSS selector into an equivalent xpath expression.
* Currently the selector engine only supports querying by tag, id, and classs
foreach($parts as $part) {
if(preg_match('/^([A-Za-z][A-Za-z0-9]*)/', $part, $matches)) {
$xpath .= "//$matches[1]";
if(preg_match('/#([^#.\[]+)/', $part, $matches)) {
$xfilters[] = "@id='$matches[1]'";
if(preg_match('/\.([^#.\[]+)/', $part, $matches)) {
$xfilters[] = "contains(@class,'$matches[1]')";
if($xfilters) $xpath .= '[' . implode(',', $xfilters) . ']';
|