Show
Ignore:
Timestamp:
03/02/08 15:12:12 (4 years ago)
Author:
nperriault
Message:

Clever Svg:

  • refs #40: more tests
  • added csDocument::getElementById() and csDocument::dropElementById() methods
  • fixed csDocument::swapDepths() bug

Warning: breaks BC from 0.5.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • cleversvg/trunk/tests/csDocumentTest.php

    r334 r335  
    1111{ 
    1212 
     13  public function testConstructor() 
     14  { 
     15    $doc = new csDocument(320, 240, 'Blah', array('baseProfile' => 'foo/bar')); 
     16    $this->assertAttrValueEquals($doc, '/svg:svg/@width', 320); 
     17    $this->assertAttrValueEquals($doc, '/svg:svg/@height', 240); 
     18    $this->assertTextNodeEquals($doc, '/svg:svg/svg:title', 'Blah'); 
     19    $this->assertAttrValueEquals($doc, '/svg:svg/@baseProfile', 'foo/bar'); 
     20  } 
     21 
     22  public function testCreateElement() 
     23  { 
     24    $doc = new csDocument(320, 240, 'Blah'); 
     25    $this->assertType('csCircle', $doc->createElement('circle')); 
     26    $this->assertType('csRect', $doc->createElement('rect')); 
     27    $this->assertType('csLinearGradient', $doc->createElement('linearGradient')); 
     28  } 
     29 
     30  public function testDropElementById() 
     31  { 
     32    $doc = new csDocument(320, 240, 'Blah'); 
     33    $c = new csCircle(); 
     34    $c->setRadius(10); 
     35    $c->setStroke('red'); 
     36    $c->setId('circle1'); 
     37    $doc->addElement($c); 
     38    $this->assertNodeExists($doc, '/svg:svg/svg:circle[@id = "circle1"]'); 
     39    $doc->dropElementById('circle1'); 
     40    $this->assertNodeDoesNotExist($doc, '/svg:svg/svg:circle[@id = "circle1"]'); 
     41  } 
     42 
     43  public function testHasId() 
     44  { 
     45    $doc = new csDocument(320, 240, 'Blah'); 
     46    $c = new csCircle(); 
     47    $c->setRadius(10); 
     48    $c->setStroke('red'); 
     49    $c->setId('circle1'); 
     50    $c2 = clone($c); 
     51    $c2->setId('circle2'); 
     52    $doc->addElement($c); 
     53    $doc->addElement($c2); 
     54    $this->assertTrue($doc->hasId('circle1')); 
     55    $this->assertTrue($doc->hasId('circle2')); 
     56    $this->assertFalse($doc->hasId('jfhkjsdfh')); 
     57  } 
     58 
    1359  public function testSetDescription() 
    1460  { 
     
    1864    $doc->setDescription('Changed description'); 
    1965    $this->assertTextNodeEquals($doc, '/svg:svg/svg:desc', 'Changed description'); 
     66  } 
     67 
     68  /** 
     69   * @expectedException csException 
     70   * 
     71   */ 
     72  public function testNoDuplicateId() 
     73  { 
     74    $doc = new csDocument(320, 240, 'Blah'); 
     75    $c = new csCircle(); 
     76    $c->setId('circle1'); 
     77    $c2 = new csCircle(); 
     78    $c2->setId('circle1'); 
     79    $doc->addElement($c); 
     80    $doc->addElement($c2); 
    2081  } 
    2182 
     
    2990  } 
    3091 
     92  public function testSwapDepths() 
     93  { 
     94    $doc = new csDocument(320, 240, 'Test depths'); 
     95    $c1 = new csCircle(160, 120, 40); 
     96    $c1->setDepth(20); 
     97    $c1->setId('c1'); 
     98    $c2 = new csCircle(140, 100, 40); 
     99    $c2->setDepth(40); 
     100    $c2->setId('c2'); 
     101    $doc->addElement($c1); 
     102    $doc->addElement($c2); 
     103    $doc->swapDepths('c1', 'c2'); 
     104    $this->assertAttrValueEquals($doc, '/svg:svg/svg:circle[@id = "c1"]/@style', 'z-index: 40'); 
     105    $this->assertAttrValueEquals($doc, '/svg:svg/svg:circle[@id = "c2"]/@style', 'z-index: 20'); 
     106  } 
     107 
     108  public function testViewBox() 
     109  { 
     110    $doc = new csDocument(); 
     111    $doc->setViewBox(10, 10, 320, 240); 
     112    $this->assertAttrValueEquals($doc, '/svg:svg/@viewBox', '10 10 320 240'); 
     113  } 
     114 
    31115  public function testToXml() 
    32116  {