Show
Ignore:
Timestamp:
03/07/08 08:33:04 (4 years ago)
Author:
nperriault
Message:

Clever Svg:

  • refs #40: more elements tests
  • Removed depth management, as svg handle it natively

Warning: breaks BC from 0.5.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • cleversvg/trunk/tests/csBaseTestCase.class.php

    r335 r336  
    2727 
    2828  /** 
     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  /** 
    2971   * Checks if an attribute xpath query matches given value for given doc. 
    3072   * 
     
    5193                $xpath_query, $value, $attr_value, "\n".$doc->toXML())); 
    5294    } 
    53     return true; 
    5495  } 
    5596 
     
    5798  { 
    5899    $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    } 
    60106  } 
    61107 
    62108  protected function assertNodeDoesNotExist($doc, $xpath_query) 
    63109  { 
    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    } 
    65117  } 
    66118 
     
    74126                $xpath_query, $value, "\n".$doc->toXML())); 
    75127    } 
    76     return true; 
    77128  } 
    78129 
     
    88139  private function documentXpath(csDocument $doc, $xpath_query) 
    89140  { 
    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 
    91143    $xpath = new DOMXPath($dom); 
    92144    $xpath->registerNamespace("svg", "http://www.w3.org/2000/svg"); // uh oh 
     145    $xpath->registerNamespace("xlink", "http://www.w3.org/1999/xlink"); 
    93146    return $xpath->query($xpath_query, $dom); 
    94147  }