/** * @param string $css CSS selector to convert to XML and test * @param string $test_sxml A test XML document, in serialized form * @param string $expected_sxml Serialized representation of the [expected] result of the XPath query */ public static function assertCSS2XPathSerializedXMLEquals($css, $test_sxml, $expected_sxml) { //convert the serialised XML into a proper XML document tree $document = DOMDocumentSerialize::deserialize($test_sxml); //do the CSS to XPath translation $xpath = static::$Translator->translateQuery($css); //apply the XPath; this will give us a list of nodes it selected $xquery = new DOMXPath($document); $nodes = $xquery->query('//DOMDocumentSerialize' . $xpath, $document->documentElement); //re-serialize the XPath result $result_sxml = DOMDocumentSerialize::serializeDOMNodeList($nodes); //clean-up unset($nodes, $xquery, $document); self::assertEquals($expected_sxml, $result_sxml, "Failed to assert that the CSS to XPath translation produced the expected behaviour\n" . "xpath : {$xpath}"); }