| | 28 | /** |
| | 29 | * Checks if an attribute xpath query matches given value for given doc. I |
| | 30 | * know the code is a bit weird, but it is as weird as the php5 DOM XML |
| | 31 | * namespace handling. |
| | 32 | * |
| | 33 | * @param csDocument $doc |
| | 34 | * @param string $xpath_query |
| | 35 | * @param mixed $value |
| | 36 | * @return boolean |
| | 37 | */ |
| | 38 | protected function assertAttrValueEquals($doc, $xpath_query, $value) |
| | 39 | { |
| | 40 | $dom = $doc->getDomDocument(); |
| | 41 | $dom = DOMDocument::loadXML($doc->toXML()); // yeah, I *must* reload the xml |
| | 42 | $xpath = new DOMXPath($dom); |
| | 43 | $xpath->registerNamespace("svg", "http://www.w3.org/2000/svg"); // uh oh |
| | 44 | $result = $xpath->query($xpath_query, $dom); |
| | 45 | $attr = $result->item(0); // First match |
| | 46 | if (!$attr) // Attribute not found |
| | 47 | { |
| | 48 | throw new PHPUnit_Framework_ExpectationFailedException( |
| | 49 | sprintf('No attribute found for query "%s". Source: %s', |
| | 50 | $xpath_query, "\n".$doc->toXML())); |
| | 51 | } |
| | 52 | $attr_value = $attr->value; |
| | 53 | if (!$attr_value or $attr_value != (string) $value) // String compare |
| | 54 | { |
| | 55 | throw new PHPUnit_Framework_ExpectationFailedException( |
| | 56 | sprintf('XPath query "%s" does not match value "%s". Source: %s', |
| | 57 | $xpath_query, $value, "\n".$doc->toXML())); |
| | 58 | } |
| | 59 | return true; |
| | 60 | } |
| | 61 | |