Author: kn
Date: Tue Oct 30 10:35:01 2007
New Revision: 6629

Log:
- Better check for font min/max size values

Modified:
    trunk/Graph/src/options/font.php
    trunk/Graph/tests/font_test.php

Modified: trunk/Graph/src/options/font.php
==============================================================================
--- trunk/Graph/src/options/font.php [iso-8859-1] (original)
+++ trunk/Graph/src/options/font.php [iso-8859-1] Tue Oct 30 10:35:01 2007
@@ -132,11 +132,32 @@
         switch ( $propertyName )
         {
             case 'minFontSize':
+                if ( !is_numeric( $propertyValue ) ||
+                     ( $propertyValue < 1 ) )
+                {
+                    throw new ezcBaseValueException( $propertyName, 
$propertyValue, 'float > 1' );
+                }
+
+                // Ensure min font size is smaller or equal max font size.
+                if ( $propertyValue > $this->properties['maxFontSize'] )
+                {
+                    throw new ezcBaseValueException( $propertyName, 
$propertyValue, 'float <= ' . $this->properties['maxFontSize'] );
+                }
+
+                $this->properties[$propertyName] = (float) $propertyValue;
+                break;
+
             case 'maxFontSize':
                 if ( !is_numeric( $propertyValue ) ||
                      ( $propertyValue < 1 ) )
                 {
                     throw new ezcBaseValueException( $propertyName, 
$propertyValue, 'float > 1' );
+                }
+
+                // Ensure max font size is greater or equal min font size.
+                if ( $propertyValue < $this->properties['minFontSize'] )
+                {
+                    throw new ezcBaseValueException( $propertyName, 
$propertyValue, 'float >= ' . $this->properties['minFontSize'] );
                 }
 
                 $this->properties[$propertyName] = (float) $propertyValue;

Modified: trunk/Graph/tests/font_test.php
==============================================================================
--- trunk/Graph/tests/font_test.php [iso-8859-1] (original)
+++ trunk/Graph/tests/font_test.php [iso-8859-1] Tue Oct 30 10:35:01 2007
@@ -346,6 +346,28 @@
         $this->fail( 'Expected ezcBaseValueException.' );
     }
 
+    public function testFontOptionsPropertyMaxFontSizeLowerThenMinFonSize()
+    {
+        $options = new ezcGraphFontOptions();
+
+        $this->assertSame(
+            96,
+            $options->maxFontSize,
+            'Wrong default value for property maxFontSize in class 
ezcGraphFontOptions'
+        );
+
+        try
+        {
+            $options->maxFontSize = 1;
+        }
+        catch ( ezcBaseValueException $e )
+        {
+            return true;
+        }
+
+        $this->fail( 'Expected ezcBaseValueException.' );
+    }
+
     public function testFontOptionsPropertyMinimalUsedFont()
     {
         $options = new ezcGraphFontOptions();
@@ -369,6 +391,28 @@
             $options->minimalUsedFont,
             'Setting property value did not work for property minimalUsedFont 
in class ezcGraphFontOptions'
         );
+    }
+
+    public function testFontOptionsPropertyMinFontSizeGreaterThenMaxFonSize()
+    {
+        $options = new ezcGraphFontOptions();
+
+        $this->assertSame(
+            6,
+            $options->minFontSize,
+            'Wrong default value for property minFontSize in class 
ezcGraphFontOptions'
+        );
+
+        try
+        {
+            $options->minFontSize = 100;
+        }
+        catch ( ezcBaseValueException $e )
+        {
+            return true;
+        }
+
+        $this->fail( 'Expected ezcBaseValueException.' );
     }
 
     public function testFontOptionsPropertyColor()


-- 
svn-components mailing list
svn-components@lists.ez.no
http://lists.ez.no/mailman/listinfo/svn-components

Reply via email to