Changeset 326
- Timestamp:
- 02/27/08 22:52:17 (6 months ago)
- Files:
-
- cleversvg/trunk/base/csBaseElement.class.php (modified) (5 diffs)
- cleversvg/trunk/base/csBaseGradient.class.php (modified) (1 diff)
- cleversvg/trunk/base/csBaseShape.class.php (modified) (8 diffs)
- cleversvg/trunk/document/csDocument.class.php (modified) (1 diff)
- cleversvg/trunk/tests/csBaseTestCase.class.php (added)
- cleversvg/trunk/tests/csCircleTest.php (added)
- cleversvg/trunk/tests/csDocumentTest.php (modified) (2 diffs)
- cleversvg/trunk/tests/csTestSuite.php (added)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
cleversvg/trunk/base/csBaseElement.class.php
r323 r326 1 1 <?php 2 2 /** 3 * SVG Base Element abstract class. Shapes and Groups allherit from this class.3 * SVG Base Element abstract class. Shapes and Groups inherit from this class. 4 4 * 5 5 * @author Nicolas Perriault <nperriault@gmail.com> … … 7 7 * @subpackage elements 8 8 */ 9 abstractclass csBaseElement9 class csBaseElement 10 10 { 11 11 … … 55 55 * @return DOMElement 56 56 */ 57 p ublicfunction compile($embedded=false)57 protected function compile($embedded=false) 58 58 { 59 59 $dom = $this->getDomDocument(); … … 251 251 * @param string $default Default value 252 252 */ 253 p ublicfunction setAttribute($name, $value, $default=null)253 protected function setAttribute($name, $value, $default=null) 254 254 { 255 255 if (!is_null($default) && is_null($value)) … … 272 272 if (!is_null($depth) && is_int($depth)) 273 273 { 274 $this-> styles['z-index'] = (string) $depth;274 $this->attributes['style']['z-index'] = (string) $depth; 275 275 } 276 276 } cleversvg/trunk/base/csBaseGradient.class.php
r323 r326 7 7 * @subpackage gradients 8 8 */ 9 abstractclass csBaseGradient extends csBaseElement9 class csBaseGradient extends csBaseElement 10 10 { 11 11 cleversvg/trunk/base/csBaseShape.class.php
r318 r326 1 1 <?php 2 2 /** 3 * SVG Base Shape abstract class. All shapes heritatesfrom this base class.4 * 3 * SVG Base Shape abstract class. All shapes inherit from this base class. 4 * 5 5 * @author Nicolas Perriault <nperriault@gmail.com> 6 6 * @package cleversvg 7 7 * @subpackage elements 8 8 */ 9 abstractclass csBaseShape extends csBaseElement9 class csBaseShape extends csBaseElement 10 10 { 11 11 12 12 /** 13 13 * Computes DOMXML Node 14 * 14 * 15 15 * @param boolean $embedded Is SVG element embedded ? 16 16 * @return DOMElement … … 19 19 { 20 20 $element_node = parent::compile($embedded); 21 21 22 22 // Transformations, if any 23 23 if (count($this->transforms) > 0) … … 26 26 foreach ($this->transforms as $transform_name => $transform_params) 27 27 { 28 $transforms[] = sprintf('%s(%s)', 29 $transform_name, 28 $transforms[] = sprintf('%s(%s)', 29 $transform_name, 30 30 implode(',', $transform_params)); 31 31 32 32 } 33 33 $element_node->setAttribute('transform', implode(' ', $transforms)); 34 34 } 35 35 36 36 return $element_node; 37 37 } 38 38 39 39 /** 40 40 * Sets the class name of element 41 * 41 * 42 42 * @param mixed $class 43 43 */ … … 49 49 /** 50 50 * Sets the fill color of shape 51 * 51 * 52 52 * @param mixed $color 53 53 */ … … 56 56 $this->setAttribute('fill', $color, 'none'); 57 57 } 58 58 59 59 /** 60 60 * Sets the fill opacity of shape 61 * 61 * 62 62 * @param mixed $fill_opacity 63 63 */ … … 66 66 $this->setAttribute('fill-opacity', $fill_opacity, '0'); 67 67 } 68 68 69 69 /** 70 70 * Sets the global opacity of shape 71 * 71 * 72 72 * @param mixed $opacity 73 73 */ … … 76 76 $this->setAttribute('opacity', $opacity, '0'); 77 77 } 78 78 79 79 /** 80 80 * Sets the color of shape stroke 81 * 81 * 82 82 * @param string $color 83 83 */ … … 86 86 $this->setAttribute('stroke', $color, 'none'); 87 87 } 88 88 89 89 /** 90 90 * Sets the width of shape stroke 91 * 91 * 92 92 * @param mixed $width 93 93 */ cleversvg/trunk/document/csDocument.class.php
r322 r326 57 57 $depth = ++$this->maxdepth; 58 58 } 59 $element->setDepth($depth);60 59 } 61 60 else cleversvg/trunk/tests/csDocumentTest.php
r325 r326 1 1 <?php 2 // Call csDocumentTest::main() if this source file is executed directly.3 if (!defined('PHPUnit_MAIN_METHOD')) {4 define('PHPUnit_MAIN_METHOD', 'csDocumentTest::main');5 }6 7 2 require_once 'PHPUnit/Framework.php'; 8 3 require_once dirname(__FILE__).'/../cleversvg.php'; 4 require_once dirname(__FILE__).'/csBaseTestCase.class.php'; 9 5 10 6 /** … … 12 8 * 13 9 */ 14 class csDocumentTest extends PHPUnit_Framework_TestCase10 class csDocumentTest extends csBaseTestCase 15 11 { 16 12 17 /** 18 * csDocument instance 19 * @var csDocument 20 */ 21 protected $doc; 22 23 public static function main() 13 public function testSetDescription() 24 14 { 25 require_once 'PHPUnit/TextUI/TestRunner.php'; 26 $suite = new PHPUnit_Framework_TestSuite('csDocumentTest'); 27 $result = PHPUnit_TextUI_TestRunner::run($suite); 28 } 29 30 public function setUp() 31 { 32 $doc = new csDocument(320, 240, 'SVG test document'); 33 $rect = new csRect(60, 60, 40, 40); 34 $rect->setFill('red'); 35 $rect->setStroke('yellow'); 36 $rect->setStrokeWidth('4'); 37 $doc->addElement($rect); 38 $this->doc = $doc; 15 $doc = $this->generateTestDoc(); 16 $doc->setDescription('Added description'); 17 $xml = $doc->toXML(); 18 $this->assertEquals(preg_match('#<desc>Added description</desc>#si', $xml), 1, $xml); 39 19 } 40 20 41 21 public function testSetTitle() 42 22 { 43 $this->doc->setTitle('Changed title'); 44 $xml = $this->doc->toXML(); 23 $doc = $this->generateTestDoc(); 24 $doc->setTitle('Changed title'); 25 $xml = $doc->toXML(); 45 26 $this->assertEquals(preg_match('#<title>Changed title</title>#si', $xml), 1, $xml); 46 }47 48 public function testSetDescription()49 {50 $this->doc->setDescription('Changed description');51 $xml = $this->doc->toXML();52 $this->assertEquals(preg_match('#<desc>Changed description</desc>#si', $xml), 1, $xml);53 27 } 54 28 55 29 public function testToXml() 56 30 { 57 $xml = $this->doc->toXML(); 31 $doc = $this->generateTestDoc(); 32 $xml = $doc->toXML(); 58 33 $this->assertEquals(preg_match('#<\?xml version="1.0" encoding="UTF-8".*?\?>#s', $xml), 1, $xml); 59 34 } 35 60 36 } 61 62 // Call csDocumentTest::main() if this source file is executed directly.63 if (PHPUnit_MAIN_METHOD == 'csDocumentTest::main') {64 csDocumentTest::main();65 }
