From b08ae56b53938333b051b91b0a1f912428864950 Mon Sep 17 00:00:00 2001 From: Kore Nordmann Date: Thu, 8 Mar 2007 12:01:24 +0000 Subject: - Added feature #9511: Added helper functions to create image maps an link SVG images in ezcGraphTools --- .../ezcGraphToolsTest_testLineChartImageMap.html | 10 + .../ezcGraphToolsTest_testLineChartSvgLinking.svg | 2 + .../ezcGraphToolsTest_testPieChartImageMap.html | 22 ++ ...phToolsTest_testPieChartImageMapCustomName.html | 22 ++ .../ezcGraphToolsTest_testPieChartSvgLinking.svg | 2 + tests/driver_svg_test.php | 22 +- tests/struct_test.php | 45 +++- tests/suite.php | 88 +++---- tests/tools_test.php | 266 +++++++++++++++++++++ 9 files changed, 433 insertions(+), 46 deletions(-) create mode 100644 tests/data/compare/ezcGraphToolsTest_testLineChartImageMap.html create mode 100644 tests/data/compare/ezcGraphToolsTest_testLineChartSvgLinking.svg create mode 100644 tests/data/compare/ezcGraphToolsTest_testPieChartImageMap.html create mode 100644 tests/data/compare/ezcGraphToolsTest_testPieChartImageMapCustomName.html create mode 100644 tests/data/compare/ezcGraphToolsTest_testPieChartSvgLinking.svg create mode 100644 tests/tools_test.php (limited to 'tests') diff --git a/tests/data/compare/ezcGraphToolsTest_testLineChartImageMap.html b/tests/data/compare/ezcGraphToolsTest_testLineChartImageMap.html new file mode 100644 index 0000000..67d845a --- /dev/null +++ b/tests/data/compare/ezcGraphToolsTest_testLineChartImageMap.html @@ -0,0 +1,10 @@ + + Line 1 + Line 1 + sample 1 + sample 2 + sample 3 + sample 4 + sample 5 + sample 3 + diff --git a/tests/data/compare/ezcGraphToolsTest_testLineChartSvgLinking.svg b/tests/data/compare/ezcGraphToolsTest_testLineChartSvgLinking.svg new file mode 100644 index 0000000..47255ea --- /dev/null +++ b/tests/data/compare/ezcGraphToolsTest_testLineChartSvgLinking.svg @@ -0,0 +1,2 @@ + +Line 1Line 2sample 2sample 3sample 4sample 50250500750 diff --git a/tests/data/compare/ezcGraphToolsTest_testPieChartImageMap.html b/tests/data/compare/ezcGraphToolsTest_testPieChartImageMap.html new file mode 100644 index 0000000..6c1981e --- /dev/null +++ b/tests/data/compare/ezcGraphToolsTest_testPieChartImageMap.html @@ -0,0 +1,22 @@ + + Mozilla + Mozilla + IE + IE + Opera + Opera + wget + wget + Safari + Safari + Mozilla + Mozilla + IE + IE + Opera + Opera + wget + wget + Safari + Safari + diff --git a/tests/data/compare/ezcGraphToolsTest_testPieChartImageMapCustomName.html b/tests/data/compare/ezcGraphToolsTest_testPieChartImageMapCustomName.html new file mode 100644 index 0000000..555443b --- /dev/null +++ b/tests/data/compare/ezcGraphToolsTest_testPieChartImageMapCustomName.html @@ -0,0 +1,22 @@ + + Mozilla + Mozilla + IE + IE + Opera + Opera + wget + wget + Safari + Safari + Mozilla + Mozilla + IE + IE + Opera + Opera + wget + wget + Safari + Safari + diff --git a/tests/data/compare/ezcGraphToolsTest_testPieChartSvgLinking.svg b/tests/data/compare/ezcGraphToolsTest_testPieChartSvgLinking.svg new file mode 100644 index 0000000..660e9c0 --- /dev/null +++ b/tests/data/compare/ezcGraphToolsTest_testPieChartSvgLinking.svg @@ -0,0 +1,2 @@ + +MozillaIEOperawgetSafariOpera: 1204 (16.9%)IE: 345 (4.8%)Mozilla: 4375 (61.3%)wget: 231 (3.2%)Safari: 987 (13.8%) diff --git a/tests/driver_svg_test.php b/tests/driver_svg_test.php index d797e3c..f54b1e2 100644 --- a/tests/driver_svg_test.php +++ b/tests/driver_svg_test.php @@ -1594,14 +1594,32 @@ class ezcGraphSvgDriverTest extends ezcGraphTestCase $this->assertSame( null, $options->encoding, - 'Wrong default value for property idPrefix in class ezcGraphSvgDriverOptions' + 'Wrong default value for property encoding in class ezcGraphSvgDriverOptions' ); $options->encoding = 'ISO-8859-15'; $this->assertSame( 'ISO-8859-15', $options->encoding, - 'Setting property value did not work for property idPrefix in class ezcGraphSvgDriverOptions' + 'Setting property value did not work for property encoding in class ezcGraphSvgDriverOptions' + ); + } + + public function testSvgDriverOptionsPropertyLinkCursor() + { + $options = new ezcGraphSvgDriverOptions(); + + $this->assertSame( + 'pointer', + $options->linkCursor, + 'Wrong default value for property linkCursor in class ezcGraphSvgDriverOptions' + ); + + $options->linkCursor = 'auto'; + $this->assertSame( + 'auto', + $options->linkCursor, + 'Setting property value did not work for property linkCursor in class ezcGraphSvgDriverOptions' ); } } diff --git a/tests/struct_test.php b/tests/struct_test.php index 699c3e8..ad7d555 100644 --- a/tests/struct_test.php +++ b/tests/struct_test.php @@ -24,7 +24,7 @@ class ezcGraphStructTest extends ezcTestCase public function testCreateContext() { - $context = new ezcGraphContext( 'set', 'point' ); + $context = new ezcGraphContext( 'set', 'point', 'url://' ); $this->assertSame( 'set', @@ -38,8 +38,15 @@ class ezcGraphStructTest extends ezcTestCase 'Wrong value when reading public property datapoint in ezcGraphContext.' ); + $this->assertSame( + 'url://', + $context->url, + 'Wrong value when reading public property url in ezcGraphContext.' + ); + $context->dataset = 'set 2'; $context->datapoint = 'point 2'; + $context->url = 'url://2'; $this->assertSame( 'set 2', @@ -52,6 +59,12 @@ class ezcGraphStructTest extends ezcTestCase $context->datapoint, 'Wrong value when reading public property datapoint in ezcGraphContext.' ); + + $this->assertSame( + 'url://2', + $context->url, + 'Wrong value when reading public property url in ezcGraphContext.' + ); } public function testContextUnknowPropertySet() @@ -109,6 +122,36 @@ class ezcGraphStructTest extends ezcTestCase ); } + public function testContextSetStateWithURL() + { + $context = new ezcGraphContext(); + + $context->__set_state( + array( + 'dataset' => 'set', + 'datapoint' => 'point', + 'url' => 'url://', + ) ); + + $this->assertSame( + 'set', + $context->dataset, + 'Wrong value when reading public property dataset in ezcGraphContext.' + ); + + $this->assertSame( + 'point', + $context->datapoint, + 'Wrong value when reading public property datapoint in ezcGraphContext.' + ); + + $this->assertSame( + 'url://', + $context->url, + 'Wrong value when reading public property url in ezcGraphContext.' + ); + } + public function testCreateCoordinate() { $context = new ezcGraphCoordinate( 23, 42 ); diff --git a/tests/suite.php b/tests/suite.php index 92ae202..4b490ae 100644 --- a/tests/suite.php +++ b/tests/suite.php @@ -12,38 +12,39 @@ /** * Require test suites. */ -require_once 'color_test.php'; +require_once 'axis_centered_renderer_test.php'; +require_once 'axis_exact_renderer_test.php'; +require_once 'background_test.php'; +require_once 'boundings_test.php'; require_once 'chart_test.php'; -require_once 'pie_test.php'; -require_once 'line_test.php'; -require_once 'dataset_test.php'; +require_once 'color_test.php'; require_once 'dataset_average_test.php'; require_once 'dataset_numeric_test.php'; require_once 'dataset_pdo_test.php'; -require_once 'element_options_test.php'; -require_once 'legend_test.php'; -require_once 'background_test.php'; -require_once 'text_test.php'; -require_once 'numeric_axis_test.php'; -require_once 'labeled_axis_test.php'; -require_once 'logarithmical_axis_test.php'; +require_once 'dataset_test.php'; require_once 'date_axis_test.php'; -require_once 'renderer_2d_test.php'; -require_once 'renderer_3d_test.php'; -require_once 'axis_exact_renderer_test.php'; -require_once 'axis_centered_renderer_test.php'; -require_once 'driver_options_test.php'; +require_once 'driver_flash_test.php'; require_once 'driver_gd_test.php'; +require_once 'driver_options_test.php'; require_once 'driver_svg_test.php'; -require_once 'driver_flash_test.php'; +require_once 'element_options_test.php'; require_once 'font_test.php'; -require_once 'palette_test.php'; +require_once 'image_map_test.php'; +require_once 'labeled_axis_test.php'; +require_once 'legend_test.php'; +require_once 'line_test.php'; +require_once 'logarithmical_axis_test.php'; require_once 'matrix_test.php'; -require_once 'vector_test.php'; -require_once 'boundings_test.php'; +require_once 'numeric_axis_test.php'; +require_once 'palette_test.php'; +require_once 'pie_test.php'; require_once 'polynom_test.php'; +require_once 'renderer_2d_test.php'; +require_once 'renderer_3d_test.php'; require_once 'struct_test.php'; -require_once 'image_map_test.php'; +require_once 'text_test.php'; +require_once 'tools_test.php'; +require_once 'vector_test.php'; /** * Test suite for ImageAnalysis package. @@ -58,38 +59,39 @@ class ezcGraphSuite extends PHPUnit_Framework_TestSuite parent::__construct(); $this->setName( "Graph" ); - $this->addTest( ezcGraphColorTest::suite() ); + $this->addTest( ezcGraphAxisCenteredRendererTest::suite() ); + $this->addTest( ezcGraphAxisExactRendererTest::suite() ); + $this->addTest( ezcGraphBackgroundTest::suite() ); + $this->addTest( ezcGraphBoundingsTest::suite() ); $this->addTest( ezcGraphChartTest::suite() ); - $this->addTest( ezcGraphPieChartTest::suite() ); - $this->addTest( ezcGraphLineChartTest::suite() ); - $this->addTest( ezcGraphDataSetTest::suite() ); + $this->addTest( ezcGraphColorTest::suite() ); $this->addTest( ezcGraphDataSetAverageTest::suite() ); - $this->addTest( ezcGraphNumericDataSetTest::suite() ); - $this->addTest( ezcGraphPdoDataSetTest::suite() ); + $this->addTest( ezcGraphDataSetTest::suite() ); + $this->addTest( ezcGraphDateAxisTest::suite() ); + $this->addTest( ezcGraphDriverOptionsTest::suite() ); $this->addTest( ezcGraphElementOptionsTest::suite() ); - $this->addTest( ezcGraphLegendTest::suite() ); - $this->addTest( ezcGraphBackgroundTest::suite() ); - $this->addTest( ezcGraphNumericAxisTest::suite() ); + $this->addTest( ezcGraphFlashDriverTest::suite() ); + $this->addTest( ezcGraphFontTest::suite() ); + $this->addTest( ezcGraphGdDriverTest::suite() ); + $this->addTest( ezcGraphImageMapTest::suite() ); $this->addTest( ezcGraphLabeledAxisTest::suite() ); + $this->addTest( ezcGraphLegendTest::suite() ); + $this->addTest( ezcGraphLineChartTest::suite() ); $this->addTest( ezcGraphLogarithmicalAxisTest::suite() ); - $this->addTest( ezcGraphDateAxisTest::suite() ); + $this->addTest( ezcGraphMatrixTest::suite() ); + $this->addTest( ezcGraphNumericAxisTest::suite() ); + $this->addTest( ezcGraphNumericDataSetTest::suite() ); + $this->addTest( ezcGraphPaletteTest::suite() ); + $this->addTest( ezcGraphPdoDataSetTest::suite() ); + $this->addTest( ezcGraphPieChartTest::suite() ); + $this->addTest( ezcGraphPolynomTest::suite() ); $this->addTest( ezcGraphRenderer2dTest::suite() ); $this->addTest( ezcGraphRenderer3dTest::suite() ); - $this->addTest( ezcGraphAxisExactRendererTest::suite() ); - $this->addTest( ezcGraphAxisCenteredRendererTest::suite() ); - $this->addTest( ezcGraphDriverOptionsTest::suite() ); - $this->addTest( ezcGraphGdDriverTest::suite() ); + $this->addTest( ezcGraphStructTest::suite() ); $this->addTest( ezcGraphSvgDriverTest::suite() ); - $this->addTest( ezcGraphFlashDriverTest::suite() ); - $this->addTest( ezcGraphFontTest::suite() ); $this->addTest( ezcGraphTextTest::suite() ); - $this->addTest( ezcGraphPaletteTest::suite() ); - $this->addTest( ezcGraphMatrixTest::suite() ); + $this->addTest( ezcGraphToolsTest::suite() ); $this->addTest( ezcGraphVectorTest::suite() ); - $this->addTest( ezcGraphBoundingsTest::suite() ); - $this->addTest( ezcGraphPolynomTest::suite() ); - $this->addTest( ezcGraphStructTest::suite() ); - $this->addTest( ezcGraphImageMapTest::suite() ); } public static function suite() diff --git a/tests/tools_test.php b/tests/tools_test.php new file mode 100644 index 0000000..e597f17 --- /dev/null +++ b/tests/tools_test.php @@ -0,0 +1,266 @@ +tempDir = $this->createTempDir( __CLASS__ . sprintf( '_%03d_', ++$i ) ) . '/'; + $this->basePath = dirname( __FILE__ ) . '/data/'; + } + + protected function tearDown() + { + if ( !$this->hasFailed() ) + { + $this->removeTempDir(); + } + } + + public function testPieChartImageMap() + { + $filename = $this->tempDir . __FUNCTION__ . '.png'; + $htmlFilename = $this->tempDir . __FUNCTION__ . '.html'; + + $chart = new ezcGraphPieChart(); + $chart->data['sample'] = new ezcGraphArrayDataSet( array( + 'Mozilla' => 4375, + 'IE' => 345, + 'Opera' => 1204, + 'wget' => 231, + 'Safari' => 987, + ) ); + + $chart->data['sample']->url = 'http://example.org/browsers'; + $chart->data['sample']->url['Mozilla'] = 'http://example.org/browsers/mozilla'; + $chart->data['sample']->highlight['Opera'] = true; + + $chart->driver = new ezcGraphGdDriver(); + $chart->options->font->path = $this->basePath . 'font.ttf'; + + $chart->render( 500, 200, $filename ); + + file_put_contents( $htmlFilename, ezcGraphTools::createImageMap( $chart ) ); + + $this->compare( + $htmlFilename, + $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.html' + ); + } + + public function testPieChartImageMapCustomName() + { + $filename = $this->tempDir . __FUNCTION__ . '.png'; + $htmlFilename = $this->tempDir . __FUNCTION__ . '.html'; + + $chart = new ezcGraphPieChart(); + $chart->data['sample'] = new ezcGraphArrayDataSet( array( + 'Mozilla' => 4375, + 'IE' => 345, + 'Opera' => 1204, + 'wget' => 231, + 'Safari' => 987, + ) ); + + $chart->data['sample']->url = 'http://example.org/browsers'; + $chart->data['sample']->url['Mozilla'] = 'http://example.org/browsers/mozilla'; + $chart->data['sample']->highlight['Opera'] = true; + + $chart->driver = new ezcGraphGdDriver(); + $chart->options->font->path = $this->basePath . 'font.ttf'; + + $chart->render( 500, 200, $filename ); + + file_put_contents( $htmlFilename, ezcGraphTools::createImageMap( $chart, 'CustomImageMapName' ) ); + + $this->compare( + $htmlFilename, + $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.html' + ); + } + + public function testLineChartImageMap() + { + $filename = $this->tempDir . __FUNCTION__ . '.png'; + $htmlFilename = $this->tempDir . __FUNCTION__ . '.html'; + + $chart = new ezcGraphLineChart(); + $chart->palette = new ezcGraphPaletteBlack(); + $chart->options->fillLines = 200; + + $chart->data['Line 1'] = new ezcGraphArrayDataSet( array( 'sample 1' => 234, 'sample 2' => 21, 'sample 3' => 324, 'sample 4' => 120, 'sample 5' => 1) ); + $chart->data['Line 2'] = new ezcGraphArrayDataSet( array( 'sample 1' => 543, 'sample 2' => 234, 'sample 3' => 298, 'sample 4' => 5, 'sample 5' => 613) ); + + $chart->data['Line 1']->url = 'http://example.org/line_1'; + $chart->data['Line 2']->url['sample 3'] = 'http://example.org/line_2/sample_3'; + + $chart->driver = new ezcGraphGdDriver(); + $chart->options->font->path = $this->basePath . 'font.ttf'; + + $chart->render( 500, 200, $filename ); + + file_put_contents( $htmlFilename, ezcGraphTools::createImageMap( $chart ) ); + + $this->compare( + $htmlFilename, + $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.html' + ); + } + + public function testImageMapWithWrongDriver() + { + $filename = $this->tempDir . __FUNCTION__ . '.png'; + + $chart = new ezcGraphLineChart(); + $chart->data['Line 1'] = new ezcGraphArrayDataSet( array( 'sample 1' => 234, 'sample 2' => 21, 'sample 3' => 324, 'sample 4' => 120, 'sample 5' => 1) ); + $chart->render( 500, 200, $filename ); + + try + { + ezcGraphTools::createImageMap( $chart ); + } + catch ( ezcGraphToolsIncompatibleDriverException $e ) + { + return true; + } + + $this->fail( 'Expected ezcGraphToolsIncompatibleDriverException.' ); + } + + public function testImageMapWithoutRendering() + { + $filename = $this->tempDir . __FUNCTION__ . '.png'; + + $chart = new ezcGraphLineChart(); + $chart->data['Line 1'] = new ezcGraphArrayDataSet( array( 'sample 1' => 234, 'sample 2' => 21, 'sample 3' => 324, 'sample 4' => 120, 'sample 5' => 1) ); + $chart->driver = new ezcGraphGdDriver(); + + try + { + ezcGraphTools::createImageMap( $chart ); + } + catch ( ezcGraphToolsNotRenderedException $e ) + { + return true; + } + + $this->fail( 'Expected ezcGraphToolsNotRenderedException.' ); + } + + public function testPieChartSvgLinking() + { + $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->data['sample']->url = 'http://example.org/browsers'; + $chart->data['sample']->url['Mozilla'] = 'http://example.org/browsers/mozilla'; + $chart->data['sample']->highlight['Opera'] = true; + + $chart->render( 500, 200, $filename ); + + ezcGraphTools::linkSvgElements( $chart ); + + $this->compare( + $filename, + $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.svg' + ); + } + + public function testLineChartSvgLinking() + { + $filename = $this->tempDir . __FUNCTION__ . '.svg'; + + $chart = new ezcGraphLineChart(); + $chart->palette = new ezcGraphPaletteBlack(); + $chart->options->fillLines = 200; + + $chart->data['Line 1'] = new ezcGraphArrayDataSet( array( 'sample 1' => 234, 'sample 2' => 21, 'sample 3' => 324, 'sample 4' => 120, 'sample 5' => 1) ); + $chart->data['Line 2'] = new ezcGraphArrayDataSet( array( 'sample 1' => 543, 'sample 2' => 234, 'sample 3' => 298, 'sample 4' => 5, 'sample 5' => 613) ); + + $chart->data['Line 1']->url = 'http://example.org/line_1'; + $chart->data['Line 2']->url['sample 3'] = 'http://example.org/line_2/sample_3'; + + $chart->render( 500, 200, $filename ); + + ezcGraphTools::linkSvgElements( $chart ); + + $this->compare( + $filename, + $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.svg' + ); + } + + public function testSvgLinkingWithWrongDriver() + { + $filename = $this->tempDir . __FUNCTION__ . '.svg'; + + $chart = new ezcGraphLineChart(); + $chart->data['Line 1'] = new ezcGraphArrayDataSet( array( 'sample 1' => 234, 'sample 2' => 21, 'sample 3' => 324, 'sample 4' => 120, 'sample 5' => 1) ); + $chart->render( 500, 200, $filename ); + + $chart->driver = new ezcGraphGdDriver(); + $chart->options->font->path = $this->basePath . 'font.ttf'; + + try + { + ezcGraphTools::linkSvgElements( $chart ); + } + catch ( ezcGraphToolsIncompatibleDriverException $e ) + { + return true; + } + + $this->fail( 'Expected ezcGraphToolsIncompatibleDriverException.' ); + } + + public function testSvgLinkingWithoutRendering() + { + $filename = $this->tempDir . __FUNCTION__ . '.svg'; + + $chart = new ezcGraphLineChart(); + $chart->data['Line 1'] = new ezcGraphArrayDataSet( array( 'sample 1' => 234, 'sample 2' => 21, 'sample 3' => 324, 'sample 4' => 120, 'sample 5' => 1) ); + + try + { + ezcGraphTools::linkSvgElements( $chart ); + } + catch ( ezcGraphToolsNotRenderedException $e ) + { + return true; + } + + $this->fail( 'Expected ezcGraphToolsNotRenderedException.' ); + } +} + +?> -- cgit v1.1