Changeset 336 for cleversvg/trunk/tests/csBaseTestCase.class.php
- Timestamp:
- 03/07/08 08:33:04 (4 years ago)
- Files:
-
- 1 modified
-
cleversvg/trunk/tests/csBaseTestCase.class.php (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
cleversvg/trunk/tests/csBaseTestCase.class.php
r335 r336 27 27 28 28 /** 29 * Checks if an attribute exists for given node 30 * 31 * @param csDocument $doc 32 * @param string $xpath_query 33 * @param string $attr_name 34 * @return boolean 35 */ 36 public function assertNodeAttrExists($doc, $xpath_query, $attr_name) 37 { 38 $result = $this->documentXpath($doc, $xpath_query); 39 $this->assertNodeExists($doc, $xpath_query); 40 if (!$result->item(0)->hasAttribute($attr_name)) 41 { 42 throw new PHPUnit_Framework_ExpectationFailedException( 43 sprintf('No attribute "%s" found in node retrieved by "%s". Source: %s', 44 $attr_name, $xpath_query, "\n".$doc->toXML())); 45 } 46 } 47 48 /** 49 * Checks that an attribute does not exist for given node 50 * 51 * @param csDocument $doc 52 * @param string $xpath_query 53 * @param string $attr_name 54 * @return boolean 55 */ 56 public function assertNodeAttrNotExists($doc, $xpath_query, $attr_name) 57 { 58 $result = $this->documentXpath($doc, $xpath_query); 59 $this->assertNodeExists($doc, $xpath_query); 60 if ($result->item(0)->hasAttribute($attr_name)) 61 { 62 throw new PHPUnit_Framework_ExpectationFailedException( 63 sprintf('Attribute %s="%s" retrieved by node "%s". Source: %s', 64 $attr_name, 65 $result->item(0)->getAttribute($attr_name), 66 $xpath_query, "\n".$doc->toXML())); 67 } 68 } 69 70 /** 29 71 * Checks if an attribute xpath query matches given value for given doc. 30 72 * … … 51 93 $xpath_query, $value, $attr_value, "\n".$doc->toXML())); 52 94 } 53 return true;54 95 } 55 96 … … 57 98 { 58 99 $result = $this->documentXpath($doc, $xpath_query); 59 return !is_null($result->item(0)); 100 if (is_null($result->item(0))) 101 { 102 throw new PHPUnit_Framework_ExpectationFailedException( 103 sprintf('XPath query "%s" does not return a result. Source: %s', 104 $xpath_query, "\n".$doc->toXML())); 105 } 60 106 } 61 107 62 108 protected function assertNodeDoesNotExist($doc, $xpath_query) 63 109 { 64 return !$this->assertNodeExists($doc, $xpath_query); 110 $result = $this->documentXpath($doc, $xpath_query); 111 if (!is_null($result->item(0))) 112 { 113 throw new PHPUnit_Framework_ExpectationFailedException( 114 sprintf('XPath query "%s" return a result. Source: %s', 115 $xpath_query, "\n".$doc->toXML())); 116 } 65 117 } 66 118 … … 74 126 $xpath_query, $value, "\n".$doc->toXML())); 75 127 } 76 return true;77 128 } 78 129 … … 88 139 private function documentXpath(csDocument $doc, $xpath_query) 89 140 { 90 $dom = DOMDocument::loadXML($doc->toXML()); // yeah, I *must* reload the xml 141 $dom = new DOMDocument(); 142 $dom->loadXML($doc->toXML()); // yeah, I *must* reload the xml 91 143 $xpath = new DOMXPath($dom); 92 144 $xpath->registerNamespace("svg", "http://www.w3.org/2000/svg"); // uh oh 145 $xpath->registerNamespace("xlink", "http://www.w3.org/1999/xlink"); 93 146 return $xpath->query($xpath_query, $dom); 94 147 }
