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/csDocumentTest.php

    r335 r336  
    1111{ 
    1212 
     13  public function testAddAsDefinition() 
     14  { 
     15    $doc = new csDocument(320, 240, 'Blah'); 
     16    $circle = new csCircle(); 
     17    $circle->setStroke('yellow'); 
     18    $circle->setStrokeWidth(2); 
     19    $circle->setFill('orange'); 
     20    $circle->setId('circle1'); 
     21    $doc->addAsDefinition($circle, 'c1'); 
     22    $this->assertNodeExists($doc, '/svg:svg/svg:defs/svg:circle[@id = "c1"]'); 
     23    $this->assertType('csCircle', $doc->getElementById('c1')); 
     24  } 
     25 
     26  /** 
     27   * @expectedException csException 
     28   * 
     29   */ 
     30  public function testAddElement() 
     31  { 
     32    $doc = new csDocument(320, 240, 'Blah'); 
     33    $c = $doc->createElement('circle'); 
     34    $c->setId('myId'); 
     35    $doc->addElement($c); 
     36    $this->assertType('csCircle', $doc->getElementById('myId')); 
     37    $rect = new csRect(100, 50, 40, 20); 
     38    $rect->setId('myId'); 
     39    $doc->addElement($rect); 
     40  } 
     41 
    1342  public function testConstructor() 
    1443  { 
     
    4170  } 
    4271 
     72  public function testGetDomDocument() 
     73  { 
     74    $doc = new csDocument(320, 240, 'Blah'); 
     75    $this->assertType('DOMDocument', $doc->getDomDocument()); 
     76  } 
     77 
     78  public function testGetElementById() 
     79  { 
     80    $doc = new csDocument(320, 240, 'Blah'); 
     81 
     82    // Testing flat level search 
     83    $c = new csCircle(); 
     84    $c->setRadius(10); 
     85    $c->setStroke('red'); 
     86    $c->setId('c1'); 
     87    $doc->addElement($c); 
     88    $this->assertType('csBaseElement', $doc->getElementById('c1')); 
     89 
     90    // Testing deep level search 
     91    $c2 = clone($c); 
     92    $c2->setId('c2'); 
     93    $g1 = new csGroup('g1'); 
     94    $g1->addElement($c2); 
     95    $doc->addElement($g1); 
     96    $this->assertType('csBaseElement', $doc->getElementById('c2')); 
     97 
     98    $c3 = clone($c); 
     99    $c3->setId('c3'); 
     100    $g2 = new csGroup('g2'); 
     101    $g2->addElement($c3); 
     102    $g3 = new csGroup('g3'); 
     103    $g3->addElement($g2); 
     104    $doc->addElement($g3); 
     105    $this->assertType('csBaseElement', $doc->getElementById('c3')); 
     106  } 
     107 
    43108  public function testHasId() 
    44109  { 
     
    55120    $this->assertTrue($doc->hasId('circle2')); 
    56121    $this->assertFalse($doc->hasId('jfhkjsdfh')); 
     122    $doc->dropElementById('circle1'); 
     123    $this->assertFalse($doc->hasId('circle1')); 
     124    $this->assertTrue($doc->hasId('circle2')); 
     125    $doc->dropElementById('circle2'); 
     126    $this->assertFalse($doc->hasId('circle2')); 
    57127  } 
    58128 
     
    106176  } 
    107177 
     178  public function testUseDefinition() 
     179  { 
     180    $doc = new csDocument(320, 240, 'Blah'); 
     181    $circle = new csCircle(); 
     182    $doc->addAsDefinition($circle, 'c1'); 
     183    $doc->useDefinition('c1', array('x' => 200, 'y' => 100)); 
     184    $this->assertAttrValueEquals($doc, '/svg:svg/svg:use/@xlink:href', '#c1'); 
     185  } 
     186 
     187  public function testValidation() 
     188  { 
     189    $doc = new csDocument(320, 240, 'Test depths'); 
     190    $c1 = new csCircle(160, 120, 40); 
     191    $c1->setDepth(20); 
     192    $c1->setId('c1'); 
     193    $c2 = new csCircle(140, 100, 40); 
     194    $c2->setDepth(40); 
     195    $c2->setId('c2'); 
     196    $doc->addElement($c1); 
     197    $doc->addElement($c2); 
     198    $doc->setStrictMode(true); 
     199    $doc->toXML(); 
     200  } 
     201 
    108202  public function testViewBox() 
    109203  {