Changeset 326

Show
Ignore:
Timestamp:
02/27/08 22:52:17 (6 months ago)
Author:
nperriault
Message:

refs #40 - More tests + bug fixes

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • cleversvg/trunk/base/csBaseElement.class.php

    r323 r326  
    11<?php 
    22/** 
    3  * SVG Base Element abstract class. Shapes and Groups all herit from this class. 
     3 * SVG Base Element abstract class. Shapes and Groups inherit from this class. 
    44 * 
    55 * @author     Nicolas Perriault <nperriault@gmail.com> 
     
    77 * @subpackage elements 
    88 */ 
    9 abstract class csBaseElement 
     9class csBaseElement 
    1010{ 
    1111 
     
    5555   * @return DOMElement 
    5656   */ 
    57   public function compile($embedded=false) 
     57  protected function compile($embedded=false) 
    5858  { 
    5959    $dom = $this->getDomDocument(); 
     
    251251   * @param  string  $default  Default value 
    252252   */ 
    253   public function setAttribute($name, $value, $default=null) 
     253  protected function setAttribute($name, $value, $default=null) 
    254254  { 
    255255    if (!is_null($default) && is_null($value)) 
     
    272272    if (!is_null($depth) && is_int($depth)) 
    273273    { 
    274       $this->styles['z-index'] = (string) $depth; 
     274      $this->attributes['style']['z-index'] = (string) $depth; 
    275275    } 
    276276  } 
  • cleversvg/trunk/base/csBaseGradient.class.php

    r323 r326  
    77 * @subpackage gradients 
    88 */ 
    9 abstract class csBaseGradient extends csBaseElement 
     9class csBaseGradient extends csBaseElement 
    1010{ 
    1111 
  • cleversvg/trunk/base/csBaseShape.class.php

    r318 r326  
    11<?php 
    22/** 
    3  * SVG Base Shape abstract class. All shapes heritates from this base class. 
    4  *  
     3 * SVG Base Shape abstract class. All shapes inherit from this base class. 
     4 * 
    55 * @author     Nicolas Perriault <nperriault@gmail.com> 
    66 * @package    cleversvg 
    77 * @subpackage elements 
    88 */ 
    9 abstract class csBaseShape extends csBaseElement 
     9class csBaseShape extends csBaseElement 
    1010{ 
    1111 
    1212  /** 
    1313   * Computes DOMXML Node 
    14    *  
     14   * 
    1515   * @param  boolean  $embedded  Is SVG element embedded ? 
    1616   * @return DOMElement 
     
    1919  { 
    2020    $element_node = parent::compile($embedded); 
    21      
     21 
    2222    // Transformations, if any 
    2323    if (count($this->transforms) > 0) 
     
    2626      foreach ($this->transforms as $transform_name => $transform_params) 
    2727      { 
    28         $transforms[] = sprintf('%s(%s)',  
    29                                 $transform_name,  
     28        $transforms[] = sprintf('%s(%s)', 
     29                                $transform_name, 
    3030                                implode(',', $transform_params)); 
    31          
     31 
    3232      } 
    3333      $element_node->setAttribute('transform', implode(' ', $transforms)); 
    3434    } 
    35      
     35 
    3636    return $element_node; 
    3737  } 
    38    
     38 
    3939  /** 
    4040   * Sets the class name of element 
    41    *  
     41   * 
    4242   * @param  mixed  $class 
    4343   */ 
     
    4949  /** 
    5050   * Sets the fill color of shape 
    51    *  
     51   * 
    5252   * @param  mixed  $color 
    5353   */ 
     
    5656    $this->setAttribute('fill', $color, 'none'); 
    5757  } 
    58    
     58 
    5959  /** 
    6060   * Sets the fill opacity of shape 
    61    *  
     61   * 
    6262   * @param  mixed  $fill_opacity 
    6363   */ 
     
    6666    $this->setAttribute('fill-opacity', $fill_opacity, '0'); 
    6767  } 
    68    
     68 
    6969  /** 
    7070   * Sets the global opacity of shape 
    71    *  
     71   * 
    7272   * @param  mixed  $opacity 
    7373   */ 
     
    7676    $this->setAttribute('opacity', $opacity, '0'); 
    7777  } 
    78    
     78 
    7979  /** 
    8080   * Sets the color of shape stroke 
    81    *  
     81   * 
    8282   * @param  string  $color 
    8383   */ 
     
    8686    $this->setAttribute('stroke', $color, 'none'); 
    8787  } 
    88    
     88 
    8989  /** 
    9090   * Sets the width of shape stroke 
    91    *  
     91   * 
    9292   * @param  mixed  $width 
    9393   */ 
  • cleversvg/trunk/document/csDocument.class.php

    r322 r326  
    5757        $depth = ++$this->maxdepth; 
    5858      } 
    59       $element->setDepth($depth); 
    6059    } 
    6160    else 
  • cleversvg/trunk/tests/csDocumentTest.php

    r325 r326  
    11<?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  
    72require_once 'PHPUnit/Framework.php'; 
    83require_once dirname(__FILE__).'/../cleversvg.php'; 
     4require_once dirname(__FILE__).'/csBaseTestCase.class.php'; 
    95 
    106/** 
     
    128 * 
    139 */ 
    14 class csDocumentTest extends PHPUnit_Framework_TestCase 
     10class csDocumentTest extends csBaseTestCase 
    1511{ 
    1612 
    17   /** 
    18    * csDocument instance 
    19    * @var csDocument 
    20    */ 
    21   protected $doc; 
    22  
    23   public static function main() 
     13  public function testSetDescription() 
    2414  { 
    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); 
    3919  } 
    4020 
    4121  public function testSetTitle() 
    4222  { 
    43     $this->doc->setTitle('Changed title'); 
    44     $xml = $this->doc->toXML(); 
     23    $doc = $this->generateTestDoc(); 
     24    $doc->setTitle('Changed title'); 
     25    $xml = $doc->toXML(); 
    4526    $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); 
    5327  } 
    5428 
    5529  public function testToXml() 
    5630  { 
    57     $xml = $this->doc->toXML(); 
     31    $doc = $this->generateTestDoc(); 
     32    $xml = $doc->toXML(); 
    5833    $this->assertEquals(preg_match('#<\?xml version="1.0" encoding="UTF-8".*?\?>#s', $xml), 1, $xml); 
    5934  } 
     35 
    6036} 
    61  
    62 // Call csDocumentTest::main() if this source file is executed directly. 
    63 if (PHPUnit_MAIN_METHOD == 'csDocumentTest::main') { 
    64     csDocumentTest::main(); 
    65 }