Changeset 334
- Timestamp:
- 03/01/08 22:38:45 (4 years ago)
- Location:
- cleversvg/trunk/tests
- Files:
-
- 2 modified
-
csBaseTestCase.class.php (modified) (3 diffs)
-
csDocumentTest.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
cleversvg/trunk/tests/csBaseTestCase.class.php
r333 r334 27 27 28 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. 29 * Checks if an attribute xpath query matches given value for given doc. 32 30 * 33 31 * @param csDocument $doc … … 38 36 protected function assertAttrValueEquals($doc, $xpath_query, $value) 39 37 { 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); 38 $result = $this->documentXpath($doc, $xpath_query); 45 39 $attr = $result->item(0); // First match 46 40 if (!$attr) // Attribute not found … … 60 54 } 61 55 56 protected function assertTextNodeEquals($doc, $xpath_query, $value) 57 { 58 $result = $this->documentXpath($doc, $xpath_query); 59 if ($result->item(0)->nodeValue != $value) 60 { 61 throw new PHPUnit_Framework_ExpectationFailedException( 62 sprintf('XPath query "%s" does not match value "%s". Source: %s', 63 $xpath_query, $value, "\n".$doc->toXML())); 64 } 65 return true; 66 } 67 68 /** 69 * Run an xpath query on csDocument resulting XML. I 70 * know the code is a bit weird, but it is as weird as the php5 DOM XML 71 * namespace handling. 72 * 73 * @param csDocument $doc 74 * @param string $xpath_query 75 * @return mixed 76 */ 77 private function documentXpath(csDocument $doc, $xpath_query) 78 { 79 $dom = DOMDocument::loadXML($doc->toXML()); // yeah, I *must* reload the xml 80 $xpath = new DOMXPath($dom); 81 $xpath->registerNamespace("svg", "http://www.w3.org/2000/svg"); // uh oh 82 return $xpath->query($xpath_query, $dom); 83 } 84 62 85 } -
cleversvg/trunk/tests/csDocumentTest.php
r326 r334 15 15 $doc = $this->generateTestDoc(); 16 16 $doc->setDescription('Added description'); 17 $xml = $doc->toXML(); 18 $this->assertEquals(preg_match('#<desc>Added description</desc>#si', $xml), 1, $xml); 17 $this->assertTextNodeEquals($doc, '/svg:svg/svg:desc', 'Added description'); 18 $doc->setDescription('Changed description'); 19 $this->assertTextNodeEquals($doc, '/svg:svg/svg:desc', 'Changed description'); 19 20 } 20 21 … … 22 23 { 23 24 $doc = $this->generateTestDoc(); 25 $doc->setTitle('Added title'); 26 $this->assertTextNodeEquals($doc, '/svg:svg/svg:title', 'Added title'); 24 27 $doc->setTitle('Changed title'); 25 $xml = $doc->toXML(); 26 $this->assertEquals(preg_match('#<title>Changed title</title>#si', $xml), 1, $xml); 28 $this->assertTextNodeEquals($doc, '/svg:svg/svg:title', 'Changed title'); 27 29 } 28 30
