summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKore Nordmann <github@kore-nordmann.de>2007-10-30 09:35:01 +0000
committerKore Nordmann <github@kore-nordmann.de>2007-10-30 09:35:01 +0000
commitcf584c289cd5a4743b21c0ecd5f7dddee399c60a (patch)
tree8444c06a897aefe1a6948f87cfe8d592f10d4c47
parent6f35d14da96a6276147a6d09e5ff3cdc49e65f6d (diff)
downloadzetacomponents-graph-cf584c289cd5a4743b21c0ecd5f7dddee399c60a.zip
zetacomponents-graph-cf584c289cd5a4743b21c0ecd5f7dddee399c60a.tar.gz
- Better check for font min/max size values
-rw-r--r--src/options/font.php21
-rw-r--r--tests/font_test.php44
2 files changed, 65 insertions, 0 deletions
diff --git a/src/options/font.php b/src/options/font.php
index ab700f7..d205954 100644
--- a/src/options/font.php
+++ b/src/options/font.php
@@ -132,6 +132,21 @@ class ezcGraphFontOptions extends ezcBaseOptions
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 ) )
@@ -139,6 +154,12 @@ class ezcGraphFontOptions extends ezcBaseOptions
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;
break;
diff --git a/tests/font_test.php b/tests/font_test.php
index 031533b..44de1dc 100644
--- a/tests/font_test.php
+++ b/tests/font_test.php
@@ -346,6 +346,28 @@ class ezcGraphFontTest extends ezcGraphTestCase
$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();
@@ -371,6 +393,28 @@ class ezcGraphFontTest extends ezcGraphTestCase
);
}
+ 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()
{
$options = new ezcGraphFontOptions();
OpenPOWER on IntegriCloud