summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/chart_test.php30
-rw-r--r--tests/data/compare/ezcGraphRenderer2dTest_testRenderPieChartWithBackgroundBottomRight.pngbin0 -> 87091 bytes
-rw-r--r--tests/data/compare/ezcGraphRenderer2dTest_testRenderPieChartWithTextureBackground.pngbin0 -> 77027 bytes
-rw-r--r--tests/data/compare/ezcGraphRenderer3dTest_testRenderPieChartWithBackgroundBottomCenter.pngbin0 -> 87097 bytes
-rw-r--r--tests/data/compare/ezcGraphRenderer3dTest_testRenderPieChartWithHorizontalTextureBackground.pngbin0 -> 83769 bytes
-rw-r--r--tests/data/ez.pngbin0 -> 1291 bytes
-rw-r--r--tests/data/texture.pngbin0 -> 277 bytes
-rw-r--r--tests/palette_test.php2
-rw-r--r--tests/renderer_2d_test.php58
-rw-r--r--tests/renderer_3d_test.php302
10 files changed, 369 insertions, 23 deletions
diff --git a/tests/chart_test.php b/tests/chart_test.php
index 10a9183..a906eeb 100644
--- a/tests/chart_test.php
+++ b/tests/chart_test.php
@@ -64,26 +64,12 @@ class ezcGraphChartTest extends ezcTestCase
);
}
- public function testSetOptionsValidBackgroundImage()
- {
- $pieChart = new ezcGraphPieChart();
- $pieChart->options->backgroundImage = $this->basePath . $this->testFiles['jpeg'];
-
- $background = $this->getNonPublicProperty( $pieChart->options, 'backgroundImage' );
- $this->assertTrue(
- $background instanceof ezcGraphChartElementBackgroundImage,
- 'Background is not an ezcGraphChartElementBackgroundImage.'
- );
-
- $this->assertSame( $this->basePath . $this->testFiles['jpeg'], $this->getNonPublicProperty( $background, 'source' ) );
- }
-
public function testSetOptionsInvalidBackgroundImage()
{
try
{
$pieChart = new ezcGraphPieChart();
- $pieChart->options->backgroundImage = $this->basePath . $this->testFiles['invalid'];
+ $pieChart->background->image = $this->basePath . $this->testFiles['invalid'];
}
catch ( ezcGraphInvalidImageFileException $e )
{
@@ -98,7 +84,7 @@ class ezcGraphChartTest extends ezcTestCase
try
{
$pieChart = new ezcGraphPieChart();
- $pieChart->options->backgroundImage = $this->basePath . $this->testFiles['nonexistant'];
+ $pieChart->background->image = $this->basePath . $this->testFiles['nonexistant'];
}
catch ( ezcBaseFileNotFoundException $e )
{
@@ -111,31 +97,31 @@ class ezcGraphChartTest extends ezcTestCase
public function testSetOptionsBackground()
{
$pieChart = new ezcGraphPieChart();
- $pieChart->options->background = '#FF0000';
+ $pieChart->background->color = '#FF0000';
$this->assertEquals(
ezcGraphColor::fromHex( 'FF0000' ),
- $this->getNonPublicProperty( $pieChart->options, 'background' )
+ $this->getNonPublicProperty( $pieChart->background, 'background' )
);
}
public function testSetOptionsBorder()
{
$pieChart = new ezcGraphPieChart();
- $pieChart->options->border = '#FF0000';
+ $pieChart->background->border = '#FF0000';
$this->assertEquals(
ezcGraphColor::fromHex( 'FF0000' ),
- $this->getNonPublicProperty( $pieChart->options, 'border' )
+ $this->getNonPublicProperty( $pieChart->background, 'border' )
);
}
public function testSetOptionsBorderWidth()
{
$pieChart = new ezcGraphPieChart();
- $pieChart->options->borderWidth = 3;
+ $pieChart->background->borderWidth = 3;
- $this->assertSame( 3, $this->getNonPublicProperty( $pieChart->options, 'borderWidth' ) );
+ $this->assertSame( 3, $this->getNonPublicProperty( $pieChart->background, 'borderWidth' ) );
}
public function testSetOptionsUnknown()
diff --git a/tests/data/compare/ezcGraphRenderer2dTest_testRenderPieChartWithBackgroundBottomRight.png b/tests/data/compare/ezcGraphRenderer2dTest_testRenderPieChartWithBackgroundBottomRight.png
new file mode 100644
index 0000000..b57b378
--- /dev/null
+++ b/tests/data/compare/ezcGraphRenderer2dTest_testRenderPieChartWithBackgroundBottomRight.png
Binary files differ
diff --git a/tests/data/compare/ezcGraphRenderer2dTest_testRenderPieChartWithTextureBackground.png b/tests/data/compare/ezcGraphRenderer2dTest_testRenderPieChartWithTextureBackground.png
new file mode 100644
index 0000000..91c1b66
--- /dev/null
+++ b/tests/data/compare/ezcGraphRenderer2dTest_testRenderPieChartWithTextureBackground.png
Binary files differ
diff --git a/tests/data/compare/ezcGraphRenderer3dTest_testRenderPieChartWithBackgroundBottomCenter.png b/tests/data/compare/ezcGraphRenderer3dTest_testRenderPieChartWithBackgroundBottomCenter.png
new file mode 100644
index 0000000..6744087
--- /dev/null
+++ b/tests/data/compare/ezcGraphRenderer3dTest_testRenderPieChartWithBackgroundBottomCenter.png
Binary files differ
diff --git a/tests/data/compare/ezcGraphRenderer3dTest_testRenderPieChartWithHorizontalTextureBackground.png b/tests/data/compare/ezcGraphRenderer3dTest_testRenderPieChartWithHorizontalTextureBackground.png
new file mode 100644
index 0000000..923830f
--- /dev/null
+++ b/tests/data/compare/ezcGraphRenderer3dTest_testRenderPieChartWithHorizontalTextureBackground.png
Binary files differ
diff --git a/tests/data/ez.png b/tests/data/ez.png
new file mode 100644
index 0000000..42f4799
--- /dev/null
+++ b/tests/data/ez.png
Binary files differ
diff --git a/tests/data/texture.png b/tests/data/texture.png
new file mode 100644
index 0000000..13edfe8
--- /dev/null
+++ b/tests/data/texture.png
Binary files differ
diff --git a/tests/palette_test.php b/tests/palette_test.php
index 1223653..59e6c8d 100644
--- a/tests/palette_test.php
+++ b/tests/palette_test.php
@@ -313,7 +313,7 @@ class ezcGraphPaletteTest extends ezcTestCase
$this->assertEquals(
ezcGraphColor::fromHex( '#EEEEEC' ),
- $chart->options->background,
+ $chart->background->background,
'Chart background not set from pallet.'
);
}
diff --git a/tests/renderer_2d_test.php b/tests/renderer_2d_test.php
index cc2da38..81f4b96 100644
--- a/tests/renderer_2d_test.php
+++ b/tests/renderer_2d_test.php
@@ -1570,6 +1570,64 @@ class ezcGraphRenderer2dTest extends ezcImageTestCase
10
);
}
+
+ public function testRenderPieChartWithBackgroundBottomRight()
+ {
+ $filename = $this->tempDir . __FUNCTION__ . '.png';
+
+ $chart = new ezcGraphPieChart();
+ $chart['sample'] = array(
+ 'Mozilla' => 4375,
+ 'IE' => 345,
+ 'Opera' => 1204,
+ 'wget' => 231,
+ 'Safari' => 987,
+ );
+
+ $chart->background->color = '#FFFFFFDD';
+ $chart->background->image = dirname( __FILE__ ) . '/data/ez.png';
+ $chart->background->position = ezcGraph::BOTTOM | ezcGraph::RIGHT;
+
+ $chart->driver = new ezcGraphGdDriver();
+ $chart->options->font = $this->basePath . 'font.ttf';
+ $chart->render( 500, 200, $filename );
+
+ $this->assertImageSimilar(
+ $filename,
+ $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.png',
+ 'Image does not look as expected.',
+ 10
+ );
+ }
+
+ public function testRenderPieChartWithTextureBackground()
+ {
+ $filename = $this->tempDir . __FUNCTION__ . '.png';
+
+ $chart = new ezcGraphPieChart();
+ $chart['sample'] = array(
+ 'Mozilla' => 4375,
+ 'IE' => 345,
+ 'Opera' => 1204,
+ 'wget' => 231,
+ 'Safari' => 987,
+ );
+
+ $chart->background->color = '#FFFFFFDD';
+ $chart->background->image = dirname( __FILE__ ) . '/data/texture.png';
+ $chart->background->repeat = ezcGraph::HORIZONTAL | ezcGraph::VERTICAL;
+
+ $chart->driver = new ezcGraphGdDriver();
+ $chart->options->font = $this->basePath . 'font.ttf';
+ $chart->render( 500, 200, $filename );
+
+ $this->assertImageSimilar(
+ $filename,
+ $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.png',
+ 'Image does not look as expected.',
+ 10
+ );
+ }
}
?>
diff --git a/tests/renderer_3d_test.php b/tests/renderer_3d_test.php
index b9c5588..1cb25e1 100644
--- a/tests/renderer_3d_test.php
+++ b/tests/renderer_3d_test.php
@@ -49,6 +49,249 @@ class ezcGraphRenderer3dTest extends ezcImageTestCase
$this->removeTempDir();
}
+ public function testRenderBackgroundImage()
+ {
+ $driver = $this->getMock( 'ezcGraphGdDriver', array(
+ 'drawImage',
+ ) );
+
+ $driver->options->width = 400;
+ $driver->options->height = 200;
+
+ $driver
+ ->expects( $this->at( 0 ) )
+ ->method( 'drawImage' )
+ ->with(
+ $this->equalTo( dirname( __FILE__ ) . '/data/jpeg.jpg' ),
+ $this->equalTo( new ezcGraphCoordinate( 125., 43.5 ), 1. ),
+ $this->equalTo( 150., 1. ),
+ $this->equalTo( 113., 1. )
+ );
+
+ $renderer = new ezcGraphRenderer3d();
+ $renderer->setDriver( $driver );
+ $renderer->drawBackgroundImage(
+ new ezcGraphBoundings( 0, 0, 400, 200 ),
+ dirname( __FILE__ ) . '/data/jpeg.jpg'
+ );
+ }
+
+ public function testRenderTopLeftBackgroundImage()
+ {
+ $driver = $this->getMock( 'ezcGraphGdDriver', array(
+ 'drawImage',
+ ) );
+
+ $driver->options->width = 400;
+ $driver->options->height = 200;
+
+ $driver
+ ->expects( $this->at( 0 ) )
+ ->method( 'drawImage' )
+ ->with(
+ $this->equalTo( dirname( __FILE__ ) . '/data/jpeg.jpg' ),
+ $this->equalTo( new ezcGraphCoordinate( 0., 0. ), 1. ),
+ $this->equalTo( 150., 1. ),
+ $this->equalTo( 113., 1. )
+ );
+
+ $renderer = new ezcGraphRenderer3d();
+ $renderer->setDriver( $driver );
+ $renderer->drawBackgroundImage(
+ new ezcGraphBoundings( 0, 0, 400, 200 ),
+ dirname( __FILE__ ) . '/data/jpeg.jpg',
+ ezcGraph::TOP | ezcGraph::LEFT
+ );
+ }
+
+ public function testRenderBottomRightBackgroundImage()
+ {
+ $driver = $this->getMock( 'ezcGraphGdDriver', array(
+ 'drawImage',
+ ) );
+
+ $driver->options->width = 400;
+ $driver->options->height = 200;
+
+ $driver
+ ->expects( $this->at( 0 ) )
+ ->method( 'drawImage' )
+ ->with(
+ $this->equalTo( dirname( __FILE__ ) . '/data/jpeg.jpg' ),
+ $this->equalTo( new ezcGraphCoordinate( 250., 87. ), 1. ),
+ $this->equalTo( 150., 1. ),
+ $this->equalTo( 113., 1. )
+ );
+
+ $renderer = new ezcGraphRenderer3d();
+ $renderer->setDriver( $driver );
+ $renderer->drawBackgroundImage(
+ new ezcGraphBoundings( 0, 0, 400, 200 ),
+ dirname( __FILE__ ) . '/data/jpeg.jpg',
+ ezcGraph::BOTTOM | ezcGraph::RIGHT
+ );
+ }
+
+ public function testRenderToBigBackgroundImage()
+ {
+ $driver = $this->getMock( 'ezcGraphGdDriver', array(
+ 'drawImage',
+ ) );
+
+ $driver->options->width = 400;
+ $driver->options->height = 200;
+
+ $driver
+ ->expects( $this->at( 0 ) )
+ ->method( 'drawImage' )
+ ->with(
+ $this->equalTo( dirname( __FILE__ ) . '/data/jpeg.jpg' ),
+ $this->equalTo( new ezcGraphCoordinate( 0., 0. ), 1. ),
+ $this->equalTo( 100., 1. ),
+ $this->equalTo( 100., 1. )
+ );
+
+ $renderer = new ezcGraphRenderer3d();
+ $renderer->setDriver( $driver );
+ $renderer->drawBackgroundImage(
+ new ezcGraphBoundings( 0, 0, 100, 100 ),
+ dirname( __FILE__ ) . '/data/jpeg.jpg',
+ ezcGraph::BOTTOM | ezcGraph::RIGHT
+ );
+ }
+
+ public function testRenderBackgroundImageRepeatX()
+ {
+ $driver = $this->getMock( 'ezcGraphGdDriver', array(
+ 'drawImage',
+ ) );
+
+ $driver->options->width = 400;
+ $driver->options->height = 200;
+
+ $driver
+ ->expects( $this->at( 0 ) )
+ ->method( 'drawImage' )
+ ->with(
+ $this->equalTo( dirname( __FILE__ ) . '/data/jpeg.jpg' ),
+ $this->equalTo( new ezcGraphCoordinate( 0., 87. ), 1. ),
+ $this->equalTo( 150., 1. ),
+ $this->equalTo( 113., 1. )
+ );
+ $driver
+ ->expects( $this->at( 1 ) )
+ ->method( 'drawImage' )
+ ->with(
+ $this->equalTo( dirname( __FILE__ ) . '/data/jpeg.jpg' ),
+ $this->equalTo( new ezcGraphCoordinate( 150., 87. ), 1. ),
+ $this->equalTo( 150., 1. ),
+ $this->equalTo( 113., 1. )
+ );
+ $driver
+ ->expects( $this->at( 2 ) )
+ ->method( 'drawImage' )
+ ->with(
+ $this->equalTo( dirname( __FILE__ ) . '/data/jpeg.jpg' ),
+ $this->equalTo( new ezcGraphCoordinate( 300., 87. ), 1. ),
+ $this->equalTo( 150., 1. ),
+ $this->equalTo( 113., 1. )
+ );
+
+ $renderer = new ezcGraphRenderer3d();
+ $renderer->setDriver( $driver );
+ $renderer->drawBackgroundImage(
+ new ezcGraphBoundings( 0, 0, 400, 200 ),
+ dirname( __FILE__ ) . '/data/jpeg.jpg',
+ ezcGraph::BOTTOM | ezcGraph::RIGHT,
+ ezcGraph::HORIZONTAL
+ );
+ }
+
+ public function testRenderBackgroundImageRepeatY()
+ {
+ $driver = $this->getMock( 'ezcGraphGdDriver', array(
+ 'drawImage',
+ ) );
+
+ $driver->options->width = 400;
+ $driver->options->height = 200;
+
+ $driver
+ ->expects( $this->at( 0 ) )
+ ->method( 'drawImage' )
+ ->with(
+ $this->equalTo( dirname( __FILE__ ) . '/data/jpeg.jpg' ),
+ $this->equalTo( new ezcGraphCoordinate( 250., 0. ), 1. ),
+ $this->equalTo( 150., 1. ),
+ $this->equalTo( 113., 1. )
+ );
+ $driver
+ ->expects( $this->at( 1 ) )
+ ->method( 'drawImage' )
+ ->with(
+ $this->equalTo( dirname( __FILE__ ) . '/data/jpeg.jpg' ),
+ $this->equalTo( new ezcGraphCoordinate( 250., 113. ), 1. ),
+ $this->equalTo( 150., 1. ),
+ $this->equalTo( 113., 1. )
+ );
+
+ $renderer = new ezcGraphRenderer3d();
+ $renderer->setDriver( $driver );
+ $renderer->drawBackgroundImage(
+ new ezcGraphBoundings( 0, 0, 400, 200 ),
+ dirname( __FILE__ ) . '/data/jpeg.jpg',
+ ezcGraph::BOTTOM | ezcGraph::RIGHT,
+ ezcGraph::VERTICAL
+ );
+ }
+
+ public function testRenderBackgroundImageRepeatBoth()
+ {
+ $driver = $this->getMock( 'ezcGraphGdDriver', array(
+ 'drawImage',
+ ) );
+
+ $driver->options->width = 400;
+ $driver->options->height = 200;
+
+ $driver
+ ->expects( $this->at( 0 ) )
+ ->method( 'drawImage' )
+ ->with(
+ $this->equalTo( dirname( __FILE__ ) . '/data/jpeg.jpg' ),
+ $this->equalTo( new ezcGraphCoordinate( 0., 0. ), 1. ),
+ $this->equalTo( 150., 1. ),
+ $this->equalTo( 113., 1. )
+ );
+ $driver
+ ->expects( $this->at( 3 ) )
+ ->method( 'drawImage' )
+ ->with(
+ $this->equalTo( dirname( __FILE__ ) . '/data/jpeg.jpg' ),
+ $this->equalTo( new ezcGraphCoordinate( 150., 113. ), 1. ),
+ $this->equalTo( 150., 1. ),
+ $this->equalTo( 113., 1. )
+ );
+ $driver
+ ->expects( $this->at( 5 ) )
+ ->method( 'drawImage' )
+ ->with(
+ $this->equalTo( dirname( __FILE__ ) . '/data/jpeg.jpg' ),
+ $this->equalTo( new ezcGraphCoordinate( 300., 113. ), 1. ),
+ $this->equalTo( 150., 1. ),
+ $this->equalTo( 113., 1. )
+ );
+
+ $renderer = new ezcGraphRenderer3d();
+ $renderer->setDriver( $driver );
+ $renderer->drawBackgroundImage(
+ new ezcGraphBoundings( 0, 0, 400, 200 ),
+ dirname( __FILE__ ) . '/data/jpeg.jpg',
+ ezcGraph::BOTTOM | ezcGraph::RIGHT,
+ ezcGraph::VERTICAL | ezcGraph::HORIZONTAL
+ );
+ }
+
public function testRenderLabeledPieSegment()
{
$filename = $this->tempDir . __FUNCTION__ . '.png';
@@ -516,6 +759,65 @@ class ezcGraphRenderer3dTest extends ezcImageTestCase
10
);
}
+
+ public function testRenderPieChartWithBackgroundBottomCenter()
+ {
+ $filename = $this->tempDir . __FUNCTION__ . '.png';
+
+ $chart = new ezcGraphPieChart();
+ $chart['sample'] = array(
+ 'Mozilla' => 4375,
+ 'IE' => 345,
+ 'Opera' => 1204,
+ 'wget' => 231,
+ 'Safari' => 987,
+ );
+
+ $chart->background->color = '#FFFFFFDD';
+ $chart->background->image = dirname( __FILE__ ) . '/data/ez.png';
+ $chart->background->position = ezcGraph::BOTTOM | ezcGraph::CENTER;
+
+ $chart->driver = new ezcGraphGdDriver();
+ $chart->options->font = $this->basePath . 'font.ttf';
+ $chart->render( 500, 200, $filename );
+
+ $this->assertImageSimilar(
+ $filename,
+ $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.png',
+ 'Image does not look as expected.',
+ 10
+ );
+ }
+
+ public function testRenderPieChartWithHorizontalTextureBackground()
+ {
+ $filename = $this->tempDir . __FUNCTION__ . '.png';
+
+ $chart = new ezcGraphPieChart();
+ $chart['sample'] = array(
+ 'Mozilla' => 4375,
+ 'IE' => 345,
+ 'Opera' => 1204,
+ 'wget' => 231,
+ 'Safari' => 987,
+ );
+
+ $chart->background->color = '#FFFFFFDD';
+ $chart->background->image = dirname( __FILE__ ) . '/data/texture.png';
+ $chart->background->repeat = ezcGraph::HORIZONTAL;
+ $chart->background->position = ezcGraph::BOTTOM;
+
+ $chart->driver = new ezcGraphGdDriver();
+ $chart->options->font = $this->basePath . 'font.ttf';
+ $chart->render( 500, 200, $filename );
+
+ $this->assertImageSimilar(
+ $filename,
+ $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.png',
+ 'Image does not look as expected.',
+ 10
+ );
+ }
}
?>
OpenPOWER on IntegriCloud