summaryrefslogtreecommitdiffstats
path: root/tests/legend_test.php
diff options
context:
space:
mode:
authorKore Nordmann <github@kore-nordmann.de>2006-09-21 13:15:57 +0000
committerKore Nordmann <github@kore-nordmann.de>2006-09-21 13:15:57 +0000
commit1dc7d8b6cb2e72105f032982b6fb2ebe60a3f64c (patch)
tree79d2f62854992787def155c41825010e6e9beaaa /tests/legend_test.php
parent17de4a56b1409003f56ae5d33b4df59924ca721a (diff)
downloadzetacomponents-graph-1dc7d8b6cb2e72105f032982b6fb2ebe60a3f64c.zip
zetacomponents-graph-1dc7d8b6cb2e72105f032982b6fb2ebe60a3f64c.tar.gz
- Added tests for legenda position
Diffstat (limited to 'tests/legend_test.php')
-rw-r--r--tests/legend_test.php135
1 files changed, 135 insertions, 0 deletions
diff --git a/tests/legend_test.php b/tests/legend_test.php
index 17f734e..9f46666 100644
--- a/tests/legend_test.php
+++ b/tests/legend_test.php
@@ -22,6 +22,49 @@ class ezcGraphLegendTest extends ezcTestCase
return new ezcTestSuite( "ezcGraphLegendTest" );
}
+ protected function setUp()
+ {
+ static $i = 0;
+
+ $this->tempDir = $this->createTempDir( __CLASS__ . sprintf( '_%03d_', ++$i ) ) . '/';
+ $this->basePath = dirname( __FILE__ ) . '/data/';
+ }
+
+ protected function tearDown()
+ {
+ if ( !$this->hasFailed() )
+ {
+ $this->removeTempDir();
+ }
+ }
+
+ /**
+ * Compares a generated image with a stored file
+ *
+ * @param string $generated Filename of generated image
+ * @param string $compare Filename of stored image
+ * @return void
+ */
+ protected function compare( $generated, $compare )
+ {
+ $this->assertTrue(
+ file_exists( $generated ),
+ 'No image file has been created.'
+ );
+
+ $this->assertTrue(
+ file_exists( $compare ),
+ 'Comparision image does not exist.'
+ );
+
+ if ( md5_file( $generated ) !== md5_file( $compare ) )
+ {
+ // Adding a diff makes no sense here, because created XML uses
+ // only two lines
+ $this->fail( 'Rendered image is not correct.');
+ }
+ }
+
protected function addSampleData( ezcGraphChart $chart )
{
$chart->data['sampleData'] = array( 'sample 1' => 234, 'sample 2' => 21, 'sample 3' => 324, 'sample 4' => 120, 'sample 5' => 1);
@@ -86,5 +129,97 @@ class ezcGraphLegendTest extends ezcTestCase
$chart->legend->position
);
}
+
+ public function testLeftLegend()
+ {
+ $filename = $this->tempDir . __FUNCTION__ . '.svg';
+
+ $chart = new ezcGraphPieChart();
+ $chart->data['sample'] = new ezcGraphArrayDataSet( array(
+ 'Mozilla' => 4375,
+ 'IE' => 345,
+ 'Opera' => 1204,
+ 'wget' => 231,
+ 'Safari' => 987,
+ ) );
+
+ $chart->legend->position = ezcGraph::LEFT;
+
+ $chart->render( 500, 200, $filename );
+
+ $this->compare(
+ $filename,
+ $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.svg'
+ );
+ }
+
+ public function testRightLegend()
+ {
+ $filename = $this->tempDir . __FUNCTION__ . '.svg';
+
+ $chart = new ezcGraphPieChart();
+ $chart->data['sample'] = new ezcGraphArrayDataSet( array(
+ 'Mozilla' => 4375,
+ 'IE' => 345,
+ 'Opera' => 1204,
+ 'wget' => 231,
+ 'Safari' => 987,
+ ) );
+
+ $chart->legend->position = ezcGraph::RIGHT;
+
+ $chart->render( 500, 200, $filename );
+
+ $this->compare(
+ $filename,
+ $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.svg'
+ );
+ }
+
+ public function testTopLegend()
+ {
+ $filename = $this->tempDir . __FUNCTION__ . '.svg';
+
+ $chart = new ezcGraphPieChart();
+ $chart->data['sample'] = new ezcGraphArrayDataSet( array(
+ 'Mozilla' => 4375,
+ 'IE' => 345,
+ 'Opera' => 1204,
+ 'wget' => 231,
+ 'Safari' => 987,
+ ) );
+
+ $chart->legend->position = ezcGraph::TOP;
+
+ $chart->render( 500, 200, $filename );
+
+ $this->compare(
+ $filename,
+ $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.svg'
+ );
+ }
+
+ public function testBottomLegend()
+ {
+ $filename = $this->tempDir . __FUNCTION__ . '.svg';
+
+ $chart = new ezcGraphPieChart();
+ $chart->data['sample'] = new ezcGraphArrayDataSet( array(
+ 'Mozilla' => 4375,
+ 'IE' => 345,
+ 'Opera' => 1204,
+ 'wget' => 231,
+ 'Safari' => 987,
+ ) );
+
+ $chart->legend->position = ezcGraph::BOTTOM;
+
+ $chart->render( 500, 200, $filename );
+
+ $this->compare(
+ $filename,
+ $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.svg'
+ );
+ }
}
?>
OpenPOWER on IntegriCloud