Changeset 333
- Timestamp:
- 03/01/08 22:10:54 (4 years ago)
- Location:
- cleversvg/trunk/tests
- Files:
-
- 2 modified
-
csBaseTestCase.class.php (modified) (2 diffs)
-
csCircleTest.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
cleversvg/trunk/tests/csBaseTestCase.class.php
r326 r333 9 9 class csBaseTestCase extends PHPUnit_Framework_TestCase 10 10 { 11 12 /**13 * Generated sample csCircle14 *15 * @return csCircle16 */17 protected function generateTestCircle()18 {19 $doc = new csCircle();20 $doc->setCx(10);21 $doc->setCy(5);22 $doc->setRadius(12);23 $doc->setX('blue');24 $doc->setX(2);25 return $doc;26 }27 28 /**29 * Generated sample cdBaseElement30 *31 * @return csBaseElement32 */33 protected function generateTestBaseElement()34 {35 $doc = new csBaseElement();36 return $doc;37 }38 11 39 12 /** … … 53 26 } 54 27 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 55 62 } -
cleversvg/trunk/tests/csCircleTest.php
r326 r333 18 18 $doc->addElement($circle); 19 19 $xml = $doc->toXML(); 20 $this->assert Equals(preg_match('#id="testid"#s', $xml), 1, $xml);20 $this->assertAttrValueEquals($doc, '/svg:svg/svg:circle/@id', 'testid'); 21 21 } 22 22 23 public function testSetStyle() 23 public function testSetStroke() 24 { 25 $doc = new csDocument(320, 240, 'Test document'); 26 $circle = new csCircle(); 27 $circle->setStroke(2); 28 $doc->addElement($circle); 29 $this->assertAttrValueEquals($doc, '/svg:svg/svg:circle/@stroke', 2); 30 } 31 32 public function testSetStrokeByStyle() 24 33 { 25 34 $doc = new csDocument(320, 240, 'Test document'); … … 27 36 $circle->setStyle(array('stroke' => 2)); 28 37 $doc->addElement($circle); 29 $xml = $doc->toXML(); 30 $this->assertEquals(preg_match('#<circle stroke="2"/>#s', $xml), 1, $xml); 38 $this->assertAttrValueEquals($doc, '/svg:svg/svg:circle/@stroke', 2); 31 39 } 32 40
