diff options
author | Kore Nordmann <github@kore-nordmann.de> | 2006-06-07 12:28:53 +0000 |
---|---|---|
committer | Kore Nordmann <github@kore-nordmann.de> | 2006-06-07 12:28:53 +0000 |
commit | c8ce91759e37ab7afb61068862e4a057ce1aa5b8 (patch) | |
tree | ce983224b7f0259d8f59dee891cdbede9104a6a9 /tests | |
parent | 03c4ad60f8fd30891fbbf981f6d56f6b1b5007c7 (diff) | |
download | zetacomponents-graph-c8ce91759e37ab7afb61068862e4a057ce1aa5b8.zip zetacomponents-graph-c8ce91759e37ab7afb61068862e4a057ce1aa5b8.tar.gz |
- Cleaned up tests
Diffstat (limited to 'tests')
-rw-r--r-- | tests/chart_test.php | 97 | ||||
-rw-r--r-- | tests/color_test.php | 4 | ||||
-rw-r--r-- | tests/dataset_test.php | 167 | ||||
-rw-r--r-- | tests/font_test.php | 55 | ||||
-rw-r--r-- | tests/graph_test.php | 22 | ||||
-rw-r--r-- | tests/labeled_axis_test.php | 446 | ||||
-rw-r--r-- | tests/legend_test.php | 745 | ||||
-rw-r--r-- | tests/line_test.php | 304 | ||||
-rw-r--r-- | tests/numeric_axis_test.php | 660 | ||||
-rw-r--r-- | tests/palette_test.php | 206 | ||||
-rw-r--r-- | tests/pie_test.php | 17 | ||||
-rw-r--r-- | tests/renderer_2d_test.php | 31 | ||||
-rw-r--r-- | tests/text_test.php | 114 |
13 files changed, 1049 insertions, 1819 deletions
diff --git a/tests/chart_test.php b/tests/chart_test.php index a1ee7c4..2b8d8ce 100644 --- a/tests/chart_test.php +++ b/tests/chart_test.php @@ -51,15 +51,8 @@ class ezcGraphChartTest extends ezcTestCase public function testSetTitle() { - try - { - $pieChart = ezcGraph::create( 'Pie' ); - $pieChart->title = 'Test title'; - } - catch ( Exception $e ) - { - $this->fail( $e->getMessage() ); - } + $pieChart = ezcGraph::create( 'Pie' ); + $pieChart->title = 'Test title'; $this->assertSame( 'Test title', @@ -73,15 +66,8 @@ class ezcGraphChartTest extends ezcTestCase public function testSetOptionsValidBackgroundImage() { - try - { - $pieChart = ezcGraph::create( 'Pie' ); - $pieChart->options->backgroundImage = $this->basePath . $this->testFiles['jpeg']; - } - catch ( Exception $e ) - { - $this->fail( $e->getMessage() ); - } + $pieChart = ezcGraph::create( 'Pie' ); + $pieChart->options->backgroundImage = $this->basePath . $this->testFiles['jpeg']; $this->assertProtectedPropertySame( $pieChart->options, 'backgroundImage', $this->basePath . $this->testFiles['jpeg'] ); } @@ -97,10 +83,6 @@ class ezcGraphChartTest extends ezcTestCase { return true; } - catch ( Exception $e ) - { - $this->fail( $e->getMessage() ); - } $this->fail( 'Expected ezcGraphInvalidImageFileException' ); } @@ -116,25 +98,14 @@ class ezcGraphChartTest extends ezcTestCase { return true; } - catch ( Exception $e ) - { - $this->fail( $e->getMessage() ); - } $this->fail( 'Expected ezcBaseFileNotFoundException' ); } public function testSetOptionsBackground() { - try - { - $pieChart = ezcGraph::create( 'Pie' ); - $pieChart->options->background = '#FF0000'; - } - catch ( Exception $e ) - { - $this->fail( $e->getMessage() ); - } + $pieChart = ezcGraph::create( 'Pie' ); + $pieChart->options->background = '#FF0000'; $this->assertEquals( ezcGraphColor::fromHex( 'FF0000' ), @@ -144,15 +115,8 @@ class ezcGraphChartTest extends ezcTestCase public function testSetOptionsBorder() { - try - { - $pieChart = ezcGraph::create( 'Pie' ); - $pieChart->options->border = '#FF0000'; - } - catch ( Exception $e ) - { - $this->fail( $e->getMessage() ); - } + $pieChart = ezcGraph::create( 'Pie' ); + $pieChart->options->border = '#FF0000'; $this->assertEquals( ezcGraphColor::fromHex( 'FF0000' ), @@ -162,15 +126,8 @@ class ezcGraphChartTest extends ezcTestCase public function testSetOptionsBorderWidth() { - try - { - $pieChart = ezcGraph::create( 'Pie' ); - $pieChart->options->borderWidth = 3; - } - catch ( Exception $e ) - { - $this->fail( $e->getMessage() ); - } + $pieChart = ezcGraph::create( 'Pie' ); + $pieChart->options->borderWidth = 3; $this->assertProtectedPropertySame( $pieChart->options, 'borderWidth', 3 ); } @@ -186,25 +143,14 @@ class ezcGraphChartTest extends ezcTestCase { return true; } - catch ( Exception $e ) - { - $this->fail( $e->getMessage() ); - } $this->fail( 'Expected ezcBasePropertyNotFoundException' ); } public function testSetRenderer() { - try - { - $pieChart = ezcGraph::create( 'Pie' ); - $renderer = $pieChart->renderer = new ezcGraphRenderer2D(); - } - catch ( Exception $e ) - { - $this->fail( $e->getMessage() ); - } + $pieChart = ezcGraph::create( 'Pie' ); + $renderer = $pieChart->renderer = new ezcGraphRenderer2D(); $this->assertSame( $renderer, @@ -223,25 +169,14 @@ class ezcGraphChartTest extends ezcTestCase { return true; } - catch ( Exception $e ) - { - $this->fail( $e->getMessage() ); - } $this->fail( 'Expected ezcGraphInvalidRendererException' ); } public function testSetDriver() { - try - { - $pieChart = ezcGraph::create( 'Pie' ); - $driver = $pieChart->driver = new ezcGraphGdDriver(); - } - catch ( Exception $e ) - { - $this->fail( $e->getMessage() ); - } + $pieChart = ezcGraph::create( 'Pie' ); + $driver = $pieChart->driver = new ezcGraphGdDriver(); $this->assertSame( $driver, @@ -260,10 +195,6 @@ class ezcGraphChartTest extends ezcTestCase { return true; } - catch ( Exception $e ) - { - $this->fail( $e->getMessage() ); - } $this->fail( 'Expected ezcGraphInvalidDriverException' ); } diff --git a/tests/color_test.php b/tests/color_test.php index 90beced..491060d 100644 --- a/tests/color_test.php +++ b/tests/color_test.php @@ -131,10 +131,6 @@ class ezcGraphColorTest extends ezcTestCase { return true; } - catch ( Exception $e ) - { - $this->fail( $e->getMessage() ); - } $this->fail( 'Expected ezcGraphUnknownColorDefinitionException' ); } diff --git a/tests/dataset_test.php b/tests/dataset_test.php index 7c16eda..3386c89 100644 --- a/tests/dataset_test.php +++ b/tests/dataset_test.php @@ -43,15 +43,8 @@ class ezcGraphDatasetTest extends ezcTestCase public function testCreateDatasetFromArray() { - try - { - $chart = ezcGraph::create( 'Pie' ); - $chart->humanoids = array( 'monkey' => 54, 'ape' => 37, 'human' => 9 ); - } - catch ( Exception $e ) - { - $this->fail( $e->getMessage() ); - } + $chart = ezcGraph::create( 'Pie' ); + $chart->humanoids = array( 'monkey' => 54, 'ape' => 37, 'human' => 9 ); $datasets = $this->getNonPublicProperty( $chart, 'data' ); $this->assertTrue( @@ -62,15 +55,8 @@ class ezcGraphDatasetTest extends ezcTestCase public function testGetDataset() { - try - { - $chart = ezcGraph::create( 'Pie' ); - $chart->humanoids = array( 'monkey' => 54, 'ape' => 37, 'human' => 9 ); - } - catch ( Exception $e ) - { - $this->fail( $e->getMessage() ); - } + $chart = ezcGraph::create( 'Pie' ); + $chart->humanoids = array( 'monkey' => 54, 'ape' => 37, 'human' => 9 ); $this->assertTrue( $chart->humanoids instanceof ezcGraphDataset, @@ -80,15 +66,8 @@ class ezcGraphDatasetTest extends ezcTestCase public function testDatasetContent() { - try - { - $chart = ezcGraph::create( 'Pie' ); - $chart->example = array( 'monkey' => 54, 2001 => 37 ); - } - catch ( Exception $e ) - { - $this->fail( $e->getMessage() ); - } + $chart = ezcGraph::create( 'Pie' ); + $chart->example = array( 'monkey' => 54, 2001 => 37 ); $data = $this->getNonPublicProperty( $chart->example, 'data' ); @@ -104,16 +83,9 @@ class ezcGraphDatasetTest extends ezcTestCase public function testCreateMultipleDatasetsFromArray() { - try - { - $chart = ezcGraph::create( 'Line' ); - $chart->income = array( 2000 => 2345.2, 2456.3, 2567.4 ); - $chart->spending = array( 2000 => 2347.2, 2458.3, 2569.4 ); - } - catch ( Exception $e ) - { - $this->fail( $e->getMessage() ); - } + $chart = ezcGraph::create( 'Line' ); + $chart->income = array( 2000 => 2345.2, 2456.3, 2567.4 ); + $chart->spending = array( 2000 => 2347.2, 2458.3, 2569.4 ); $datasets = $this->getNonPublicProperty( $chart, 'data' ); $this->assertTrue( @@ -138,25 +110,14 @@ class ezcGraphDatasetTest extends ezcTestCase { return true; } - catch ( Exception $e ) - { - $this->fail( $e->getMessage() ); - } $this->fail( 'Expected ezcGraphTooManyDatasetsExceptions.' ); } public function testDatasetLabel() { - try - { - $chart = ezcGraph::create( 'Pie' ); - $chart->income = array( 2000 => 2345.2, 2456.3, 2567.4 ); - } - catch ( Exception $e ) - { - $this->fail( $e->getMessage() ); - } + $chart = ezcGraph::create( 'Pie' ); + $chart->income = array( 2000 => 2345.2, 2456.3, 2567.4 ); $this->assertEquals( 'income', @@ -166,16 +127,9 @@ class ezcGraphDatasetTest extends ezcTestCase public function testDatasetSetLabel() { - try - { - $chart = ezcGraph::create( 'Pie' ); - $chart->income = array( 2000 => 2345.2, 2456.3, 2567.4 ); - $chart->income->label = 'Income Label'; - } - catch ( Exception $e ) - { - $this->fail( $e->getMessage() ); - } + $chart = ezcGraph::create( 'Pie' ); + $chart->income = array( 2000 => 2345.2, 2456.3, 2567.4 ); + $chart->income->label = 'Income Label'; $this->assertEquals( 'Income Label', @@ -185,16 +139,9 @@ class ezcGraphDatasetTest extends ezcTestCase public function testDatasetSetColor() { - try - { - $chart = ezcGraph::create( 'Pie' ); - $chart->income = array( 2000 => 2345.2, 2456.3, 2567.4 ); - $chart->income->color = '#FF0000'; - } - catch ( Exception $e ) - { - $this->fail( $e->getMessage() ); - } + $chart = ezcGraph::create( 'Pie' ); + $chart->income = array( 2000 => 2345.2, 2456.3, 2567.4 ); + $chart->income->color = '#FF0000'; $this->assertEquals( ezcGraphColor::fromHex( '#FF0000' ), @@ -204,16 +151,9 @@ class ezcGraphDatasetTest extends ezcTestCase public function testDatasetSetSymbol() { - try - { - $chart = ezcGraph::create( 'Pie' ); - $chart->income = array( 2000 => 2345.2, 2456.3, 2567.4 ); - $chart->income->symbol = ezcGraph::DIAMOND; - } - catch ( Exception $e ) - { - $this->fail( $e->getMessage() ); - } + $chart = ezcGraph::create( 'Pie' ); + $chart->income = array( 2000 => 2345.2, 2456.3, 2567.4 ); + $chart->income->symbol = ezcGraph::DIAMOND; $this->assertEquals( ezcGraph::DIAMOND, @@ -223,16 +163,9 @@ class ezcGraphDatasetTest extends ezcTestCase public function testDatasetSetSingleColor() { - try - { - $chart = ezcGraph::create( 'Pie' ); - $chart->income = array( 2000 => 2345.2, 2456.3, 2567.4 ); - $chart->income->color[2001] = '#FF0000'; - } - catch ( Exception $e ) - { - $this->fail( $e->getMessage() ); - } + $chart = ezcGraph::create( 'Pie' ); + $chart->income = array( 2000 => 2345.2, 2456.3, 2567.4 ); + $chart->income->color[2001] = '#FF0000'; $this->assertEquals( ezcGraphColor::fromHex( '#FF0000' ), @@ -242,16 +175,9 @@ class ezcGraphDatasetTest extends ezcTestCase public function testDatasetSetSingleSymbol() { - try - { - $chart = ezcGraph::create( 'Pie' ); - $chart->income = array( 2000 => 2345.2, 2456.3, 2567.4 ); - $chart->income->symbol[2001] = ezcGraph::DIAMOND; - } - catch ( Exception $e ) - { - $this->fail( $e->getMessage() ); - } + $chart = ezcGraph::create( 'Pie' ); + $chart->income = array( 2000 => 2345.2, 2456.3, 2567.4 ); + $chart->income->symbol[2001] = ezcGraph::DIAMOND; $this->assertEquals( ezcGraph::DIAMOND, @@ -261,16 +187,9 @@ class ezcGraphDatasetTest extends ezcTestCase public function testDatasetPropertyValueFallback() { - try - { - $chart = ezcGraph::create( 'Pie' ); - $chart->income = array( 2000 => 2345.2, 2456.3, 2567.4 ); - $chart->income->symbol = ezcGraph::DIAMOND; - } - catch ( Exception $e ) - { - $this->fail( $e->getMessage() ); - } + $chart = ezcGraph::create( 'Pie' ); + $chart->income = array( 2000 => 2345.2, 2456.3, 2567.4 ); + $chart->income->symbol = ezcGraph::DIAMOND; $this->assertEquals( ezcGraph::DIAMOND, @@ -290,25 +209,14 @@ class ezcGraphDatasetTest extends ezcTestCase { return true; } - catch ( Exception $e ) - { - $this->fail( $e->getMessage() ); - } $this->fail( 'Expected ezcGraphNoSuchDataException.' ); } public function testDatasetGetSingleData() { - try - { - $chart = ezcGraph::create( 'Pie' ); - $chart->income = array( 2000 => 2345.2, 2456.3, 2567.4 ); - } - catch ( Exception $e ) - { - $this->fail( $e->getMessage() ); - } + $chart = ezcGraph::create( 'Pie' ); + $chart->income = array( 2000 => 2345.2, 2456.3, 2567.4 ); $this->assertSame( 2345.2, @@ -318,16 +226,9 @@ class ezcGraphDatasetTest extends ezcTestCase public function testDatasetSetSingleData() { - try - { - $chart = ezcGraph::create( 'Pie' ); - $chart->income = array( 2000 => 2345.2, 2456.3, 2567.4 ); - $chart->income[2005] = 234.21; - } - catch ( Exception $e ) - { - $this->fail( $e->getMessage() ); - } + $chart = ezcGraph::create( 'Pie' ); + $chart->income = array( 2000 => 2345.2, 2456.3, 2567.4 ); + $chart->income[2005] = 234.21; $this->assertSame( 234.21, diff --git a/tests/font_test.php b/tests/font_test.php index ce389c0..7a362ad 100644 --- a/tests/font_test.php +++ b/tests/font_test.php @@ -46,15 +46,8 @@ class ezcGraphFontTest extends ezcTestCase public function testSetGeneralFont() { - try - { - $chart = ezcGraph::create( 'Pie' ); - $chart->options->font = $this->basePath . 'font.ttf'; - } - catch ( Exception $e ) - { - $this->fail( $e->getMessage() ); - } + $chart = ezcGraph::create( 'Pie' ); + $chart->options->font = $this->basePath . 'font.ttf'; $this->assertTrue( $chart->options->font instanceof ezcGraphFontOptions, @@ -76,15 +69,8 @@ class ezcGraphFontTest extends ezcTestCase public function testGetGeneralFontForElement() { - try - { - $chart = ezcGraph::create( 'Pie' ); - $chart->options->font = $this->basePath . 'font.ttf'; - } - catch ( Exception $e ) - { - $this->fail( $e->getMessage() ); - } + $chart = ezcGraph::create( 'Pie' ); + $chart->options->font = $this->basePath . 'font.ttf'; $this->assertTrue( $chart->legend->font instanceof ezcGraphFontOptions, @@ -100,16 +86,9 @@ class ezcGraphFontTest extends ezcTestCase public function testSetFontForElement() { - try - { - $chart = ezcGraph::create( 'Line' ); - $chart->options->font = $this->basePath . 'font.ttf'; - $chart->legend->font = $this->basePath . 'font2.ttf'; - } - catch ( Exception $e ) - { - $this->fail( $e->getMessage() ); - } + $chart = ezcGraph::create( 'Line' ); + $chart->options->font = $this->basePath . 'font.ttf'; + $chart->legend->font = $this->basePath . 'font2.ttf'; $this->assertEquals( $this->basePath . 'font.ttf', @@ -137,19 +116,11 @@ class ezcGraphFontTest extends ezcTestCase public function testSetFontForElementWithRendering() { - try - { - $chart = ezcGraph::create( 'Line' ); - $chart->sampleData = array( 'sample 1' => 234, 'sample 2' => 21, 'sample 3' => 324, 'sample 4' => 120, 'sample 5' => 1); - $chart->sampleData->color = '#CC0000'; - $chart->options->font = $this->basePath . 'font.ttf'; - $chart->legend->font = $this->basePath . 'font2.ttf'; - $chart->render( 500, 200 ); - } - catch ( Exception $e ) - { - $this->fail( $e->getMessage() ); - } + $chart = ezcGraph::create( 'Line' ); + $chart->sampleData = array( 'sample 1' => 234, 'sample 2' => 21, 'sample 3' => 324, 'sample 4' => 120, 'sample 5' => 1); + $chart->options->font = $this->basePath . 'font.ttf'; + $chart->legend->font = $this->basePath . 'font2.ttf'; + $chart->render( 500, 200 ); $this->assertEquals( $this->basePath . 'font.ttf', @@ -175,5 +146,5 @@ class ezcGraphFontTest extends ezcTestCase ); } } -?> +?> diff --git a/tests/graph_test.php b/tests/graph_test.php index a085984..4c25c33 100644 --- a/tests/graph_test.php +++ b/tests/graph_test.php @@ -43,14 +43,7 @@ class ezcGraphTest extends ezcTestCase public function testFactoryPieChart() { - try - { - $pieChart = ezcGraph::create( 'Pie' ); - } - catch ( Exception $e ) - { - $this->fail( $e->getMessage() ); - } + $pieChart = ezcGraph::create( 'Pie' ); $this->assertTrue( $pieChart instanceof ezcGraphPieChart, @@ -60,14 +53,7 @@ class ezcGraphTest extends ezcTestCase public function testFactoryLineChart() { - try - { - $lineChart = ezcGraph::create( 'Line' ); - } - catch ( Exception $e ) - { - $this->fail( $e->getMessage() ); - } + $lineChart = ezcGraph::create( 'Line' ); $this->assertTrue( $lineChart instanceof ezcGraphLineChart, @@ -85,10 +71,6 @@ class ezcGraphTest extends ezcTestCase { return true; } - catch ( Exception $e ) - { - $this->fail( $e->getMessage() ); - } $this->fail( 'Expected ezcGraphUnknownChartTypeException' ); } diff --git a/tests/labeled_axis_test.php b/tests/labeled_axis_test.php index 6e95f5f..009c3e7 100644 --- a/tests/labeled_axis_test.php +++ b/tests/labeled_axis_test.php @@ -52,17 +52,9 @@ class ezcGraphLabeledAxisTest extends ezcTestCase public function testAutomaticLabelingSingle() { - try - { - $chart = ezcGraph::create( 'Line' ); - $chart->sample = array( 2000 => 20, 70, 12, 130 ); - $chart->sample->color = '#FF0000'; - $chart->render( 500, 200 ); - } - catch ( Exception $e ) - { - $this->fail( $e->getMessage() ); - } + $chart = ezcGraph::create( 'Line' ); + $chart->sample = array( 2000 => 20, 70, 12, 130 ); + $chart->render( 500, 200 ); $this->assertSame( array( @@ -77,19 +69,10 @@ class ezcGraphLabeledAxisTest extends ezcTestCase public function testAutomaticLabelingMultiple() { - try - { - $chart = ezcGraph::create( 'Line' ); - $chart->sample = array( 2000 => 1045, 1300, 1012, 1450 ); - $chart->sample->color = '#FF0000'; - $chart->sample2 = array( 2002 => 1270, 1170, 1610, 1370 ); - $chart->sample2->color = '#00FF00'; - $chart->render( 500, 200 ); - } - catch ( Exception $e ) - { - $this->fail( $e->getMessage() ); - } + $chart = ezcGraph::create( 'Line' ); + $chart->sample = array( 2000 => 1045, 1300, 1012, 1450 ); + $chart->sample2 = array( 2002 => 1270, 1170, 1610, 1370 ); + $chart->render( 500, 200 ); $this->assertSame( array( @@ -106,19 +89,10 @@ class ezcGraphLabeledAxisTest extends ezcTestCase public function testAutomaticLabelingMultipleMixed() { - try - { - $chart = ezcGraph::create( 'Line' ); - $chart->sample = array( 2000 => 1045, 2001 => 1300, 2004 => 1012, 2006 => 1450 ); - $chart->sample->color = '#FF0000'; - $chart->sample2 = array( 2001 => 1270, 1170, 1610, 1370, 1559 ); - $chart->sample2->color = '#00FF00'; - $chart->render( 500, 200 ); - } - catch ( Exception $e ) - { - $this->fail( $e->getMessage() ); - } + $chart = ezcGraph::create( 'Line' ); + $chart->sample = array( 2000 => 1045, 2001 => 1300, 2004 => 1012, 2006 => 1450 ); + $chart->sample2 = array( 2001 => 1270, 1170, 1610, 1370, 1559 ); + $chart->render( 500, 200 ); $this->assertSame( array( @@ -136,18 +110,10 @@ class ezcGraphLabeledAxisTest extends ezcTestCase public function testPositionLeft() { - try - { - $chart = ezcGraph::create( 'Line' ); - $chart->sample = array( 2000 => 1045, 1300, 1012, 1450 ); - $chart->sample->color = '#FF0000'; - $chart->X_axis->position = ezcGraph::LEFT; - $chart->render( 500, 200 ); - } - catch ( Exception $e ) - { - $this->fail( $e->getMessage() ); - } + $chart = ezcGraph::create( 'Line' ); + $chart->sample = array( 2000 => 1045, 1300, 1012, 1450 ); + $chart->X_axis->position = ezcGraph::LEFT; + $chart->render( 500, 200 ); $testBoundings = new ezcGraphBoundings(); $testBoundings->x0 = 50; @@ -188,18 +154,10 @@ class ezcGraphLabeledAxisTest extends ezcTestCase public function testPositionRight() { - try - { - $chart = ezcGraph::create( 'Line' ); - $chart->sample = array( 2000 => 1045, 1300, 1012, 1450 ); - $chart->sample->color = '#FF0000'; - $chart->X_axis->position = ezcGraph::RIGHT; - $chart->render( 500, 200 ); - } - catch ( Exception $e ) - { - $this->fail( $e->getMessage() ); - } + $chart = ezcGraph::create( 'Line' ); + $chart->sample = array( 2000 => 1045, 1300, 1012, 1450 ); + $chart->X_axis->position = ezcGraph::RIGHT; + $chart->render( 500, 200 ); $testBoundings = new ezcGraphBoundings(); $testBoundings->x0 = 50; @@ -240,18 +198,10 @@ class ezcGraphLabeledAxisTest extends ezcTestCase public function testPositionTop() { - try - { - $chart = ezcGraph::create( 'Line' ); - $chart->sample = array( 2000 => 1045, 1300, 1012, 1450 ); - $chart->sample->color = '#FF0000'; - $chart->X_axis->position = ezcGraph::TOP; - $chart->render( 500, 200 ); - } - catch ( Exception $e ) - { - $this->fail( $e->getMessage() ); - } + $chart = ezcGraph::create( 'Line' ); + $chart->sample = array( 2000 => 1045, 1300, 1012, 1450 ); + $chart->X_axis->position = ezcGraph::TOP; + $chart->render( 500, 200 ); $testBoundings = new ezcGraphBoundings(); $testBoundings->x0 = 50; @@ -292,18 +242,10 @@ class ezcGraphLabeledAxisTest extends ezcTestCase public function testPositionBottom() { - try - { - $chart = ezcGraph::create( 'Line' ); - $chart->sample = array( 2000 => 1045, 1300, 1012, 1450 ); - $chart->sample->color = '#FF0000'; - $chart->X_axis->position = ezcGraph::BOTTOM; - $chart->render( 500, 200 ); - } - catch ( Exception $e ) - { - $this->fail( $e->getMessage() ); - } + $chart = ezcGraph::create( 'Line' ); + $chart->sample = array( 2000 => 1045, 1300, 1012, 1450 ); + $chart->X_axis->position = ezcGraph::BOTTOM; + $chart->render( 500, 200 ); $testBoundings = new ezcGraphBoundings(); $testBoundings->x0 = 50; @@ -344,203 +286,167 @@ class ezcGraphLabeledAxisTest extends ezcTestCase public function testRenderLabeledAxisBase() { - try - { - $chart = ezcGraph::create( 'Line' ); - $chart->sample = array( 2000 => 1045, 1300, 1012, 1450 ); - $chart->sample->color = '#FF0000'; - $chart->sample2 = array( 2000 => 1270, 1170, 1610, 1370 ); - $chart->sample2->color = '#00FF00'; - - $mockedRenderer = $this->getMock( 'ezcGraphRenderer2D', array( - 'drawLine', - ) ); - - // X-Axis - $mockedRenderer - ->expects( $this->at( 0 ) ) - ->method( 'drawLine' ) - ->with( - $this->equalTo( ezcGraphColor::fromHex( '#2E3436' ) ), - $this->equalTo( new ezcGraphCoordinate( 100, 190 ) ), - $this->equalTo( new ezcGraphCoordinate( 500, 190 ) ), - $this->equalTo( false ) - ); - - $chart->renderer = $mockedRenderer; - - $chart->render( 500, 200 ); - } - catch ( Exception $e ) - { - $this->fail( $e->getMessage() ); - } + $chart = ezcGraph::create( 'Line' ); + $chart->sample = array( 2000 => 1045, 1300, 1012, 1450 ); + $chart->sample2 = array( 2000 => 1270, 1170, 1610, 1370 ); + + $mockedRenderer = $this->getMock( 'ezcGraphRenderer2D', array( + 'drawLine', + ) ); + + // X-Axis + $mockedRenderer + ->expects( $this->at( 0 ) ) + ->method( 'drawLine' ) + ->with( + $this->equalTo( ezcGraphColor::fromHex( '#2E3436' ) ), + $this->equalTo( new ezcGraphCoordinate( 100, 190 ) ), + $this->equalTo( new ezcGraphCoordinate( 500, 190 ) ), + $this->equalTo( false ) + ); + + $chart->renderer = $mockedRenderer; + + $chart->render( 500, 200 ); } public function testRenderLabeledAxisArrowHead() { - try - { - $chart = ezcGraph::create( 'Line' ); - $chart->sample = array( 2000 => 1045, 1300, 1012, 1450 ); - $chart->sample->color = '#FF0000'; - $chart->sample2 = array( 2000 => 1270, 1170, 1610, 1370 ); - $chart->sample2->color = '#00FF00'; - - $mockedRenderer = $this->getMock( 'ezcGraphRenderer2D', array( - 'drawPolygon', - ) ); - - // X-Axis - $mockedRenderer - ->expects( $this->at( 0 ) ) - ->method( 'drawPolygon' ) - ->with( - $this->equalTo( array( - new ezcGraphCoordinate( 500, 190 ), - new ezcGraphCoordinate( 490, 185 ), - new ezcGraphCoordinate( 490, 195 ), - ) ), - $this->equalTo( ezcGraphColor::fromHex( '#2E3436' ) ), - $this->equalTo( true ) - ); - - $chart->renderer = $mockedRenderer; - - $chart->render( 500, 200 ); - } - catch ( Exception $e ) - { - $this->fail( $e->getMessage() ); - } + $chart = ezcGraph::create( 'Line' ); + $chart->sample = array( 2000 => 1045, 1300, 1012, 1450 ); + $chart->sample2 = array( 2000 => 1270, 1170, 1610, 1370 ); + + $mockedRenderer = $this->getMock( 'ezcGraphRenderer2D', array( + 'drawPolygon', + ) ); + + // X-Axis + $mockedRenderer + ->expects( $this->at( 0 ) ) + ->method( 'drawPolygon' ) + ->with( + $this->equalTo( array( + new ezcGraphCoordinate( 500, 190 ), + new ezcGraphCoordinate( 490, 185 ), + new ezcGraphCoordinate( 490, 195 ), + ) ), + $this->equalTo( ezcGraphColor::fromHex( '#2E3436' ) ), + $this->equalTo( true ) + ); + + $chart->renderer = $mockedRenderer; + + $chart->render( 500, 200 ); } public function testRenderLabeledAxisMajor() { - try - { - $chart = ezcGraph::create( 'Line' ); - $chart->sample = array( 2000 => 1045, 1300, 1012, 1450 ); - $chart->sample->color = '#FF0000'; - $chart->sample2 = array( 2000 => 1270, 1170, 1610, 1370 ); - $chart->sample2->color = '#00FF00'; - - $mockedRenderer = $this->getMock( 'ezcGraphRenderer2D', array( - 'drawLine', - ) ); - - // X-Axis - $mockedRenderer - ->expects( $this->at( 1 ) ) - ->method( 'drawLine' ) - ->with( - $this->equalTo( ezcGraphColor::fromHex( '#2E3436' ) ), - $this->equalTo( new ezcGraphCoordinate( 120, 194 ) ), - $this->equalTo( new ezcGraphCoordinate( 120, 186 ) ), - $this->equalTo( false ) - ); - $mockedRenderer - ->expects( $this->at( 2 ) ) - ->method( 'drawLine' ) - ->with( - $this->equalTo( ezcGraphColor::fromHex( '#2E3436' ) ), - $this->equalTo( new ezcGraphCoordinate( 240, 194 ) ), - $this->equalTo( new ezcGraphCoordinate( 240, 186 ) ), - $this->equalTo( false ) - ); - $mockedRenderer - ->expects( $this->at( 3 ) ) - ->method( 'drawLine' ) - ->with( - $this->equalTo( ezcGraphColor::fromHex( '#2E3436' ) ), - $this->equalTo( new ezcGraphCoordinate( 361, 194 ) ), - $this->equalTo( new ezcGraphCoordinate( 361, 186 ) ), - $this->equalTo( false ) - ); - $mockedRenderer - ->expects( $this->at( 4 ) ) - ->method( 'drawLine' ) - ->with( - $this->equalTo( ezcGraphColor::fromHex( '#2E3436' ) ), - $this->equalTo( new ezcGraphCoordinate( 481, 194 ) ), - $this->equalTo( new ezcGraphCoordinate( 481, 186 ) ), - $this->equalTo( false ) - ); - - $chart->renderer = $mockedRenderer; - - $chart->render( 500, 200 ); - } - catch ( Exception $e ) - { - $this->fail( $e->getMessage() ); - } + $chart = ezcGraph::create( 'Line' ); + $chart->sample = array( 2000 => 1045, 1300, 1012, 1450 ); + $chart->sample2 = array( 2000 => 1270, 1170, 1610, 1370 ); + + $mockedRenderer = $this->getMock( 'ezcGraphRenderer2D', array( + 'drawLine', + ) ); + + // X-Axis + $mockedRenderer + ->expects( $this->at( 1 ) ) + ->method( 'drawLine' ) + ->with( + $this->equalTo( ezcGraphColor::fromHex( '#2E3436' ) ), + $this->equalTo( new ezcGraphCoordinate( 120, 194 ) ), + $this->equalTo( new ezcGraphCoordinate( 120, 186 ) ), + $this->equalTo( false ) + ); + $mockedRenderer + ->expects( $this->at( 2 ) ) + ->method( 'drawLine' ) + ->with( + $this->equalTo( ezcGraphColor::fromHex( '#2E3436' ) ), + $this->equalTo( new ezcGraphCoordinate( 240, 194 ) ), + $this->equalTo( new ezcGraphCoordinate( 240, 186 ) ), + $this->equalTo( false ) + ); + $mockedRenderer + ->expects( $this->at( 3 ) ) + ->method( 'drawLine' ) + ->with( + $this->equalTo( ezcGraphColor::fromHex( '#2E3436' ) ), + $this->equalTo( new ezcGraphCoordinate( 361, 194 ) ), + $this->equalTo( new ezcGraphCoordinate( 361, 186 ) ), + $this->equalTo( false ) + ); + $mockedRenderer + ->expects( $this->at( 4 ) ) + ->method( 'drawLine' ) + ->with( + $this->equalTo( ezcGraphColor::fromHex( '#2E3436' ) ), + $this->equalTo( new ezcGraphCoordinate( 481, 194 ) ), + $this->equalTo( new ezcGraphCoordinate( 481, 186 ) ), + $this->equalTo( false ) + ); + + $chart->renderer = $mockedRenderer; + + $chart->render( 500, 200 ); } public function testRenderLabeledAxisLabels() { - try - { - $chart = ezcGraph::create( 'Line' ); - $chart->sample = array( 2000 => 1045, 1300, 1012, 1450 ); - $chart->sample->color = '#FF0000'; - $chart->sample2 = array( 2000 => 1270, 1170, 1610, 1370 ); - $chart->sample2->color = '#00FF00'; - - $mockedRenderer = $this->getMock( 'ezcGraphRenderer2D', array( - 'drawTextBox', - ) ); - - // X-Axis - $mockedRenderer - ->expects( $this->at( 2 ) ) - ->method( 'drawTextBox' ) - ->with( - $this->equalTo( new ezcGraphCoordinate( 122, 192 ) ), - $this->equalTo( '2000' ), - $this->equalTo( 88 ), - $this->equalTo( 8 ), - $this->equalTo( ezcGraph::LEFT | ezcGraph::TOP ) - ); - $mockedRenderer - ->expects( $this->at( 3 ) ) - ->method( 'drawTextBox' ) - ->with( - $this->equalTo( new ezcGraphCoordinate( 212, 192 ) ), - $this->equalTo( '2001' ), - $this->equalTo( 88 ), - $this->equalTo( 8 ), - $this->equalTo( ezcGraph::CENTER | ezcGraph::TOP ) - ); - $mockedRenderer - ->expects( $this->at( 4 ) ) - ->method( 'drawTextBox' ) - ->with( - $this->equalTo( new ezcGraphCoordinate( 303, 192 ) ), - $this->equalTo( '2002' ), - $this->equalTo( 88 ), - $this->equalTo( 8 ), - $this->equalTo( ezcGraph::CENTER | ezcGraph::TOP ) - ); - $mockedRenderer - ->expects( $this->at( 5 ) ) - ->method( 'drawTextBox' ) - ->with( - $this->equalTo( new ezcGraphCoordinate( 393, 192 ) ), - $this->equalTo( '2003' ), - $this->equalTo( 88 ), - $this->equalTo( 8 ), - $this->equalTo( ezcGraph::RIGHT | ezcGraph::TOP ) - ); - - $chart->renderer = $mockedRenderer; - - $chart->render( 500, 200 ); - } - catch ( Exception $e ) - { - $this->fail( $e->getMessage() ); - } + $chart = ezcGraph::create( 'Line' ); + $chart->sample = array( 2000 => 1045, 1300, 1012, 1450 ); + $chart->sample2 = array( 2000 => 1270, 1170, 1610, 1370 ); + + $mockedRenderer = $this->getMock( 'ezcGraphRenderer2D', array( + 'drawTextBox', + ) ); + + // X-Axis + $mockedRenderer + ->expects( $this->at( 2 ) ) + ->method( 'drawTextBox' ) + ->with( + $this->equalTo( new ezcGraphCoordinate( 122, 192 ) ), + $this->equalTo( '2000' ), + $this->equalTo( 88 ), + $this->equalTo( 8 ), + $this->equalTo( ezcGraph::LEFT | ezcGraph::TOP ) + ); + $mockedRenderer + ->expects( $this->at( 3 ) ) + ->method( 'drawTextBox' ) + ->with( + $this->equalTo( new ezcGraphCoordinate( 212, 192 ) ), + $this->equalTo( '2001' ), + $this->equalTo( 88 ), + $this->equalTo( 8 ), + $this->equalTo( ezcGraph::CENTER | ezcGraph::TOP ) + ); + $mockedRenderer + ->expects( $this->at( 4 ) ) + ->method( 'drawTextBox' ) + ->with( + $this->equalTo( new ezcGraphCoordinate( 303, 192 ) ), + $this->equalTo( '2002' ), + $this->equalTo( 88 ), + $this->equalTo( 8 ), + $this->equalTo( ezcGraph::CENTER | ezcGraph::TOP ) + ); + $mockedRenderer + ->expects( $this->at( 5 ) ) + ->method( 'drawTextBox' ) + ->with( + $this->equalTo( new ezcGraphCoordinate( 393, 192 ) ), + $this->equalTo( '2003' ), + $this->equalTo( 88 ), + $this->equalTo( 8 ), + $this->equalTo( ezcGraph::RIGHT | ezcGraph::TOP ) + ); + + $chart->renderer = $mockedRenderer; + + $chart->render( 500, 200 ); } } diff --git a/tests/legend_test.php b/tests/legend_test.php index f850b22..fcacead 100644 --- a/tests/legend_test.php +++ b/tests/legend_test.php @@ -64,15 +64,8 @@ class ezcGraphLegendTest extends ezcTestCase public function testLegendSetBackground() { - try - { - $chart = ezcGraph::create( 'Pie' ); - $chart->legend->background = '#FF0000'; - } - catch ( Exception $e ) - { - $this->fail( $e->getMessage() ); - } + $chart = ezcGraph::create( 'Pie' ); + $chart->legend->background = '#FF0000'; $this->assertEquals( ezcGraphColor::fromHex( '#FF0000' ), @@ -87,15 +80,8 @@ class ezcGraphLegendTest extends ezcTestCase public function testLegendSetBorder() { - try - { - $chart = ezcGraph::create( 'Pie' ); - $chart->legend->border = '#FF0000'; - } - catch ( Exception $e ) - { - $this->fail( $e->getMessage() ); - } + $chart = ezcGraph::create( 'Pie' ); + $chart->legend->border = '#FF0000'; $this->assertEquals( ezcGraphColor::fromHex( '#FF0000' ), @@ -110,15 +96,8 @@ class ezcGraphLegendTest extends ezcTestCase public function testLegendSetBorderWidth() { - try - { - $chart = ezcGraph::create( 'Pie' ); - $chart->legend->borderWidth = 1; - } - catch ( Exception $e ) - { - $this->fail( $e->getMessage() ); - } + $chart = ezcGraph::create( 'Pie' ); + $chart->legend->borderWidth = 1; $this->assertEquals( 1, @@ -133,15 +112,8 @@ class ezcGraphLegendTest extends ezcTestCase public function testLegendSetPosition() { - try - { - $chart = ezcGraph::create( 'Pie' ); - $chart->legend->position = ezcGraph::LEFT; - } - catch ( Exception $e ) - { - $this->fail( $e->getMessage() ); - } + $chart = ezcGraph::create( 'Pie' ); + $chart->legend->position = ezcGraph::LEFT; $this->assertEquals( ezcGraph::LEFT, @@ -156,420 +128,357 @@ class ezcGraphLegendTest extends ezcTestCase public function testRenderLegendBackground() { - try - { - $chart = ezcGraph::create( 'Line' ); - $this->addSampleData( $chart ); - $chart->legend->background = '#0000FF'; - - $mockedRenderer = $this->getMock( 'ezcGraphRenderer2D', array( - 'drawBackground', - ) ); - - $mockedRenderer - ->expects( $this->at( 1 ) ) - ->method( 'drawBackground' ) - ->with( - $this->equalTo( ezcGraphColor::fromHex( '#0000FF' ) ), - $this->equalTo( new ezcGraphCoordinate( 0, 0 ) ), - $this->equalTo( 100 ), - $this->equalTo( 200 ) - ); - $chart->renderer = $mockedRenderer; - - $chart->render( 500, 200 ); - } - catch ( Exception $e ) - { - $this->fail( $e->getMessage() ); - } + $chart = ezcGraph::create( 'Line' ); + $this->addSampleData( $chart ); + $chart->legend->background = '#0000FF'; + + $mockedRenderer = $this->getMock( 'ezcGraphRenderer2D', array( + 'drawBackground', + ) ); + + $mockedRenderer + ->expects( $this->at( 1 ) ) + ->method( 'drawBackground' ) + ->with( + $this->equalTo( ezcGraphColor::fromHex( '#0000FF' ) ), + $this->equalTo( new ezcGraphCoordinate( 0, 0 ) ), + $this->equalTo( 100 ), + $this->equalTo( 200 ) + ); + $chart->renderer = $mockedRenderer; + + $chart->render( 500, 200 ); } public function testRenderLegendSymbols() { - try - { - $chart = ezcGraph::create( 'Line' ); - $this->addSampleData( $chart ); - $chart->legend->background = '#0000FF'; - - $mockedRenderer = $this->getMock( 'ezcGraphRenderer2D', array( - 'drawSymbol', - ) ); - - $mockedRenderer - ->expects( $this->at( 0 ) ) - ->method( 'drawSymbol' ) - ->with( - $this->equalTo( ezcGraphColor::fromHex( '#0000FF' ) ), - $this->equalTo( new ezcGraphCoordinate( 2, 2 ) ), - $this->equalTo( 12 ), - $this->equalTo( 12 ), - ezcGraph::DIAMOND - ); - $mockedRenderer - ->expects( $this->at( 1 ) ) - ->method( 'drawSymbol' ) - ->with( - $this->equalTo( ezcGraphColor::fromHex( '#FF0000' ) ), - $this->equalTo( new ezcGraphCoordinate( 2, 18 ) ), - $this->equalTo( 12 ), - $this->equalTo( 12 ), - ezcGraph::NO_SYMBOL - ); - $mockedRenderer - ->expects( $this->at( 2 ) ) - ->method( 'drawSymbol' ) - ->with( - $this->equalTo( ezcGraphColor::fromHex( '#FF0000' ) ), - $this->equalTo( new ezcGraphCoordinate( 2, 34 ) ), - $this->equalTo( 12 ), - $this->equalTo( 12 ), - ezcGraph::NO_SYMBOL - ); - - $chart->renderer = $mockedRenderer; - - $chart->render( 500, 200 ); - } - catch ( Exception $e ) - { - $this->fail( $e->getMessage() ); - } + $chart = ezcGraph::create( 'Line' ); + $this->addSampleData( $chart ); + $chart->legend->background = '#0000FF'; + + $mockedRenderer = $this->getMock( 'ezcGraphRenderer2D', array( + 'drawSymbol', + ) ); + + $mockedRenderer + ->expects( $this->at( 0 ) ) + ->method( 'drawSymbol' ) + ->with( + $this->equalTo( ezcGraphColor::fromHex( '#0000FF' ) ), + $this->equalTo( new ezcGraphCoordinate( 2, 2 ) ), + $this->equalTo( 12 ), + $this->equalTo( 12 ), + ezcGraph::DIAMOND + ); + $mockedRenderer + ->expects( $this->at( 1 ) ) + ->method( 'drawSymbol' ) + ->with( + $this->equalTo( ezcGraphColor::fromHex( '#FF0000' ) ), + $this->equalTo( new ezcGraphCoordinate( 2, 18 ) ), + $this->equalTo( 12 ), + $this->equalTo( 12 ), + ezcGraph::NO_SYMBOL + ); + $mockedRenderer + ->expects( $this->at( 2 ) ) + ->method( 'drawSymbol' ) + ->with( + $this->equalTo( ezcGraphColor::fromHex( '#FF0000' ) ), + $this->equalTo( new ezcGraphCoordinate( 2, 34 ) ), + $this->equalTo( 12 ), + $this->equalTo( 12 ), + ezcGraph::NO_SYMBOL + ); + + $chart->renderer = $mockedRenderer; + + $chart->render( 500, 200 ); } public function testRenderLegendText() { - try - { - $chart = ezcGraph::create( 'Line' ); - $this->addSampleData( $chart ); - $chart->legend->background = '#0000FF'; - - $mockedRenderer = $this->getMock( 'ezcGraphRenderer2D', array( - 'drawTextBox', - ) ); - - $mockedRenderer - ->expects( $this->at( 0 ) ) - ->method( 'drawTextBox' ) - ->with( - $this->equalTo( new ezcGraphCoordinate( 17, 2 ) ), - 'sampleData', - $this->equalTo( 81 ), - $this->equalTo( 12 ), - $this->equalTo( ezcGraph::LEFT | ezcGraph::MIDDLE ) - ); - $mockedRenderer - ->expects( $this->at( 1 ) ) - ->method( 'drawTextBox' ) - ->with( - $this->equalTo( new ezcGraphCoordinate( 17, 18 ) ), - 'moreData', - $this->equalTo( 81 ), - $this->equalTo( 12 ), - $this->equalTo( ezcGraph::LEFT | ezcGraph::MIDDLE ) - - ); - $mockedRenderer - ->expects( $this->at( 2 ) ) - ->method( 'drawTextBox' ) - ->with( - $this->equalTo( new ezcGraphCoordinate( 17, 34 ) ), - 'Even more data', - $this->equalTo( 81 ), - $this->equalTo( 12 ), - $this->equalTo( ezcGraph::LEFT | ezcGraph::MIDDLE ) - - ); - - $chart->renderer = $mockedRenderer; - - $chart->render( 500, 200 ); - } - catch ( Exception $e ) - { - $this->fail( $e->getMessage() ); - } + $chart = ezcGraph::create( 'Line' ); + $this->addSampleData( $chart ); + $chart->legend->background = '#0000FF'; + + $mockedRenderer = $this->getMock( 'ezcGraphRenderer2D', array( + 'drawTextBox', + ) ); + + $mockedRenderer + ->expects( $this->at( 0 ) ) + ->method( 'drawTextBox' ) + ->with( + $this->equalTo( new ezcGraphCoordinate( 17, 2 ) ), + 'sampleData', + $this->equalTo( 81 ), + $this->equalTo( 12 ), + $this->equalTo( ezcGraph::LEFT | ezcGraph::MIDDLE ) + ); + $mockedRenderer + ->expects( $this->at( 1 ) ) + ->method( 'drawTextBox' ) + ->with( + $this->equalTo( new ezcGraphCoordinate( 17, 18 ) ), + 'moreData', + $this->equalTo( 81 ), + $this->equalTo( 12 ), + $this->equalTo( ezcGraph::LEFT | ezcGraph::MIDDLE ) + + ); + $mockedRenderer + ->expects( $this->at( 2 ) ) + ->method( 'drawTextBox' ) + ->with( + $this->equalTo( new ezcGraphCoordinate( 17, 34 ) ), + 'Even more data', + $this->equalTo( 81 ), + $this->equalTo( 12 ), + $this->equalTo( ezcGraph::LEFT | ezcGraph::MIDDLE ) + + ); + + $chart->renderer = $mockedRenderer; + + $chart->render( 500, 200 ); } public function testRenderLegendBackgroundRight() { - try - { - $chart = ezcGraph::create( 'Line' ); - $this->addSampleData( $chart ); - $chart->legend->background = '#0000FF'; - $chart->legend->position = ezcGraph::RIGHT; - - $mockedRenderer = $this->getMock( 'ezcGraphRenderer2D', array( - 'drawBackground', - 'drawTextBox', - 'drawSymbol', - 'drawLine', - ) ); - $mockedRenderer - ->expects( $this->at( 1 ) ) - ->method( 'drawBackground' ) - ->with( - $this->equalTo( ezcGraphColor::fromHex( '#0000FF' ) ), - $this->equalTo( new ezcGraphCoordinate( 400, 0 ) ), - $this->equalTo( 100 ), - $this->equalTo( 200 ) - ); - $chart->renderer = $mockedRenderer; - - $chart->render( 500, 200 ); - } - catch ( Exception $e ) - { - $this->fail( $e->getMessage() ); - } + $chart = ezcGraph::create( 'Line' ); + $this->addSampleData( $chart ); + $chart->legend->background = '#0000FF'; + $chart->legend->position = ezcGraph::RIGHT; + + $mockedRenderer = $this->getMock( 'ezcGraphRenderer2D', array( + 'drawBackground', + 'drawTextBox', + 'drawSymbol', + 'drawLine', + ) ); + $mockedRenderer + ->expects( $this->at( 1 ) ) + ->method( 'drawBackground' ) + ->with( + $this->equalTo( ezcGraphColor::fromHex( '#0000FF' ) ), + $this->equalTo( new ezcGraphCoordinate( 400, 0 ) ), + $this->equalTo( 100 ), + $this->equalTo( 200 ) + ); + $chart->renderer = $mockedRenderer; + + $chart->render( 500, 200 ); } public function testRenderLegendSymbolsRight() { - try - { - $chart = ezcGraph::create( 'Line' ); - $this->addSampleData( $chart ); - $chart->legend->background = '#0000FF'; - $chart->legend->position = ezcGraph::RIGHT; - - $mockedRenderer = $this->getMock( 'ezcGraphRenderer2D', array( - 'drawSymbol', - ) ); - - $mockedRenderer - ->expects( $this->at( 0 ) ) - ->method( 'drawSymbol' ) - ->with( - $this->equalTo( ezcGraphColor::fromHex( '#0000FF' ) ), - $this->equalTo( new ezcGraphCoordinate( 402, 2 ) ), - $this->equalTo( 12 ), - $this->equalTo( 12 ), - ezcGraph::DIAMOND - ); - $mockedRenderer - ->expects( $this->at( 1 ) ) - ->method( 'drawSymbol' ) - ->with( - $this->equalTo( ezcGraphColor::fromHex( '#FF0000' ) ), - $this->equalTo( new ezcGraphCoordinate( 402, 18 ) ), - $this->equalTo( 12 ), - $this->equalTo( 12 ), - ezcGraph::NO_SYMBOL - ); - $mockedRenderer - ->expects( $this->at( 2 ) ) - ->method( 'drawSymbol' ) - ->with( - $this->equalTo( ezcGraphColor::fromHex( '#FF0000' ) ), - $this->equalTo( new ezcGraphCoordinate( 402, 34 ) ), - $this->equalTo( 12 ), - $this->equalTo( 12 ), - ezcGraph::NO_SYMBOL - ); - - $chart->renderer = $mockedRenderer; - - $chart->render( 500, 200 ); - } - catch ( Exception $e ) - { - $this->fail( $e->getMessage() ); - } + $chart = ezcGraph::create( 'Line' ); + $this->addSampleData( $chart ); + $chart->legend->background = '#0000FF'; + $chart->legend->position = ezcGraph::RIGHT; + + $mockedRenderer = $this->getMock( 'ezcGraphRenderer2D', array( + 'drawSymbol', + ) ); + + $mockedRenderer + ->expects( $this->at( 0 ) ) + ->method( 'drawSymbol' ) + ->with( + $this->equalTo( ezcGraphColor::fromHex( '#0000FF' ) ), + $this->equalTo( new ezcGraphCoordinate( 402, 2 ) ), + $this->equalTo( 12 ), + $this->equalTo( 12 ), + ezcGraph::DIAMOND + ); + $mockedRenderer + ->expects( $this->at( 1 ) ) + ->method( 'drawSymbol' ) + ->with( + $this->equalTo( ezcGraphColor::fromHex( '#FF0000' ) ), + $this->equalTo( new ezcGraphCoordinate( 402, 18 ) ), + $this->equalTo( 12 ), + $this->equalTo( 12 ), + ezcGraph::NO_SYMBOL + ); + $mockedRenderer + ->expects( $this->at( 2 ) ) + ->method( 'drawSymbol' ) + ->with( + $this->equalTo( ezcGraphColor::fromHex( '#FF0000' ) ), + $this->equalTo( new ezcGraphCoordinate( 402, 34 ) ), + $this->equalTo( 12 ), + $this->equalTo( 12 ), + ezcGraph::NO_SYMBOL + ); + + $chart->renderer = $mockedRenderer; + + $chart->render( 500, 200 ); } public function testRenderLegendBackgroundBottom() { - try - { - $chart = ezcGraph::create( 'Line' ); - $this->addSampleData( $chart ); - $chart->legend->background = '#0000FF'; - $chart->legend->position = ezcGraph::BOTTOM; - - $mockedRenderer = $this->getMock( 'ezcGraphRenderer2D', array( - 'drawBackground', - ) ); - $mockedRenderer - ->expects( $this->at( 1 ) ) - ->method( 'drawBackground' ) - ->with( - $this->equalTo( ezcGraphColor::fromHex( '#0000FF' ) ), - $this->equalTo( new ezcGraphCoordinate( 0, 180 ) ), - $this->equalTo( 500 ), - $this->equalTo( 20 ) - ); - $chart->renderer = $mockedRenderer; - - $chart->render( 500, 200 ); - } - catch ( Exception $e ) - { - $this->fail( $e->getMessage() ); - } + $chart = ezcGraph::create( 'Line' ); + $this->addSampleData( $chart ); + $chart->legend->background = '#0000FF'; + $chart->legend->position = ezcGraph::BOTTOM; + + $mockedRenderer = $this->getMock( 'ezcGraphRenderer2D', array( + 'drawBackground', + ) ); + $mockedRenderer + ->expects( $this->at( 1 ) ) + ->method( 'drawBackground' ) + ->with( + $this->equalTo( ezcGraphColor::fromHex( '#0000FF' ) ), + $this->equalTo( new ezcGraphCoordinate( 0, 180 ) ), + $this->equalTo( 500 ), + $this->equalTo( 20 ) + ); + $chart->renderer = $mockedRenderer; + + $chart->render( 500, 200 ); } public function testRenderLegendSymbolsBottom() { - try - { - $chart = ezcGraph::create( 'Line' ); - $this->addSampleData( $chart ); - $chart->legend->background = '#0000FF'; - $chart->legend->position = ezcGraph::BOTTOM; - - $mockedRenderer = $this->getMock( 'ezcGraphRenderer2D', array( - 'drawSymbol', - ) ); - - $mockedRenderer - ->expects( $this->at( 0 ) ) - ->method( 'drawSymbol' ) - ->with( - $this->equalTo( ezcGraphColor::fromHex( '#0000FF' ) ), - $this->equalTo( new ezcGraphCoordinate( 2, 182 ) ), - $this->equalTo( 12 ), - $this->equalTo( 12 ), - ezcGraph::DIAMOND - ); - $mockedRenderer - ->expects( $this->at( 1 ) ) - ->method( 'drawSymbol' ) - ->with( - $this->equalTo( ezcGraphColor::fromHex( '#FF0000' ) ), - $this->equalTo( new ezcGraphCoordinate( 101, 182 ) ), - $this->equalTo( 12 ), - $this->equalTo( 12 ), - ezcGraph::NO_SYMBOL - ); - $mockedRenderer - ->expects( $this->at( 2 ) ) - ->method( 'drawSymbol' ) - ->with( - $this->equalTo( ezcGraphColor::fromHex( '#FF0000' ) ), - $this->equalTo( new ezcGraphCoordinate( 200, 182 ) ), - $this->equalTo( 12 ), - $this->equalTo( 12 ), - ezcGraph::NO_SYMBOL - ); - - $chart->renderer = $mockedRenderer; - - $chart->render( 300, 200 ); - } - catch ( Exception $e ) - { - $this->fail( $e->getMessage() ); - } + $chart = ezcGraph::create( 'Line' ); + $this->addSampleData( $chart ); + $chart->legend->background = '#0000FF'; + $chart->legend->position = ezcGraph::BOTTOM; + + $mockedRenderer = $this->getMock( 'ezcGraphRenderer2D', array( + 'drawSymbol', + ) ); + + $mockedRenderer + ->expects( $this->at( 0 ) ) + ->method( 'drawSymbol' ) + ->with( + $this->equalTo( ezcGraphColor::fromHex( '#0000FF' ) ), + $this->equalTo( new ezcGraphCoordinate( 2, 182 ) ), + $this->equalTo( 12 ), + $this->equalTo( 12 ), + ezcGraph::DIAMOND + ); + $mockedRenderer + ->expects( $this->at( 1 ) ) + ->method( 'drawSymbol' ) + ->with( + $this->equalTo( ezcGraphColor::fromHex( '#FF0000' ) ), + $this->equalTo( new ezcGraphCoordinate( 101, 182 ) ), + $this->equalTo( 12 ), + $this->equalTo( 12 ), + ezcGraph::NO_SYMBOL + ); + $mockedRenderer + ->expects( $this->at( 2 ) ) + ->method( 'drawSymbol' ) + ->with( + $this->equalTo( ezcGraphColor::fromHex( '#FF0000' ) ), + $this->equalTo( new ezcGraphCoordinate( 200, 182 ) ), + $this->equalTo( 12 ), + $this->equalTo( 12 ), + ezcGraph::NO_SYMBOL + ); + + $chart->renderer = $mockedRenderer; + + $chart->render( 300, 200 ); } public function testRenderLegendTextBottom() { - try - { - $chart = ezcGraph::create( 'Line' ); - $this->addSampleData( $chart ); - $chart->legend->background = '#0000FF'; - $chart->legend->position = ezcGraph::TOP; - - $mockedRenderer = $this->getMock( 'ezcGraphRenderer2D', array( - 'drawTextBox', - ) ); - - $mockedRenderer - ->expects( $this->at( 0 ) ) - ->method( 'drawTextBox' ) - ->with( - $this->equalTo( new ezcGraphCoordinate( 18, 2 ) ), - 'sampleData', - $this->equalTo( 182 ), - $this->equalTo( 12 ) - ); - $mockedRenderer - ->expects( $this->at( 1 ) ) - ->method( 'drawTextBox' ) - ->with( - $this->equalTo( new ezcGraphCoordinate( 217, 2 ) ), - 'moreData', - $this->equalTo( 182 ), - $this->equalTo( 12 ) - ); - $mockedRenderer - ->expects( $this->at( 2 ) ) - ->method( 'drawTextBox' ) - ->with( - $this->equalTo( new ezcGraphCoordinate( 416, 2 ) ), - 'Even more data', - $this->equalTo( 182 ), - $this->equalTo( 12 ) - ); - - $chart->renderer = $mockedRenderer; - - $chart->render( 600, 200 ); - } - catch ( Exception $e ) - { - $this->fail( $e->getMessage() ); - } + $chart = ezcGraph::create( 'Line' ); + $this->addSampleData( $chart ); + $chart->legend->background = '#0000FF'; + $chart->legend->position = ezcGraph::TOP; + + $mockedRenderer = $this->getMock( 'ezcGraphRenderer2D', array( + 'drawTextBox', + ) ); + + $mockedRenderer + ->expects( $this->at( 0 ) ) + ->method( 'drawTextBox' ) + ->with( + $this->equalTo( new ezcGraphCoordinate( 18, 2 ) ), + 'sampleData', + $this->equalTo( 182 ), + $this->equalTo( 12 ) + ); + $mockedRenderer + ->expects( $this->at( 1 ) ) + ->method( 'drawTextBox' ) + ->with( + $this->equalTo( new ezcGraphCoordinate( 217, 2 ) ), + 'moreData', + $this->equalTo( 182 ), + $this->equalTo( 12 ) + ); + $mockedRenderer + ->expects( $this->at( 2 ) ) + ->method( 'drawTextBox' ) + ->with( + $this->equalTo( new ezcGraphCoordinate( 416, 2 ) ), + 'Even more data', + $this->equalTo( 182 ), + $this->equalTo( 12 ) + ); + + $chart->renderer = $mockedRenderer; + + $chart->render( 600, 200 ); } public function testRenderLegendBigSymbolsPadding() { - try - { - $chart = ezcGraph::create( 'Line' ); - $this->addSampleData( $chart ); - $chart->legend->background = '#0000FF'; - $chart->legend->padding = 3; - $chart->legend->symbolSize = 20; - - $mockedRenderer = $this->getMock( 'ezcGraphRenderer2D', array( - 'drawSymbol', - ) ); - - $mockedRenderer - ->expects( $this->at( 0 ) ) - ->method( 'drawSymbol' ) - ->with( - $this->equalTo( ezcGraphColor::fromHex( '#0000FF' ) ), - $this->equalTo( new ezcGraphCoordinate( 6, 6 ) ), - $this->equalTo( 14 ), - $this->equalTo( 14 ), - ezcGraph::DIAMOND - ); - $mockedRenderer - ->expects( $this->at( 1 ) ) - ->method( 'drawSymbol' ) - ->with( - $this->equalTo( ezcGraphColor::fromHex( '#FF0000' ) ), - $this->equalTo( new ezcGraphCoordinate( 6, 28 ) ), - $this->equalTo( 14 ), - $this->equalTo( 14 ), - ezcGraph::NO_SYMBOL - ); - $mockedRenderer - ->expects( $this->at( 2 ) ) - ->method( 'drawSymbol' ) - ->with( - $this->equalTo( ezcGraphColor::fromHex( '#FF0000' ) ), - $this->equalTo( new ezcGraphCoordinate( 6, 50 ) ), - $this->equalTo( 14 ), - $this->equalTo( 14 ), - ezcGraph::NO_SYMBOL - ); - - $chart->renderer = $mockedRenderer; - - $chart->render( 500, 200 ); - } - catch ( Exception $e ) - { - $this->fail( $e->getMessage() ); - } + $chart = ezcGraph::create( 'Line' ); + $this->addSampleData( $chart ); + $chart->legend->background = '#0000FF'; + $chart->legend->padding = 3; + $chart->legend->symbolSize = 20; + + $mockedRenderer = $this->getMock( 'ezcGraphRenderer2D', array( + 'drawSymbol', + ) ); + + $mockedRenderer + ->expects( $this->at( 0 ) ) + ->method( 'drawSymbol' ) + ->with( + $this->equalTo( ezcGraphColor::fromHex( '#0000FF' ) ), + $this->equalTo( new ezcGraphCoordinate( 6, 6 ) ), + $this->equalTo( 14 ), + $this->equalTo( 14 ), + ezcGraph::DIAMOND + ); + $mockedRenderer + ->expects( $this->at( 1 ) ) + ->method( 'drawSymbol' ) + ->with( + $this->equalTo( ezcGraphColor::fromHex( '#FF0000' ) ), + $this->equalTo( new ezcGraphCoordinate( 6, 28 ) ), + $this->equalTo( 14 ), + $this->equalTo( 14 ), + ezcGraph::NO_SYMBOL + ); + $mockedRenderer + ->expects( $this->at( 2 ) ) + ->method( 'drawSymbol' ) + ->with( + $this->equalTo( ezcGraphColor::fromHex( '#FF0000' ) ), + $this->equalTo( new ezcGraphCoordinate( 6, 50 ) ), + $this->equalTo( 14 ), + $this->equalTo( 14 ), + ezcGraph::NO_SYMBOL + ); + + $chart->renderer = $mockedRenderer; + + $chart->render( 500, 200 ); } } ?> diff --git a/tests/line_test.php b/tests/line_test.php index 677c8e4..bf7a817 100644 --- a/tests/line_test.php +++ b/tests/line_test.php @@ -20,6 +20,8 @@ class ezcGraphLineChartTest extends ezcTestCase protected $basePath; + protected $tempDir; + public static function suite() { return new ezcTestSuite( "ezcGraphLineChartTest" ); @@ -32,6 +34,8 @@ class ezcGraphLineChartTest extends ezcTestCase */ public function setUp() { + static $i = 0; + $this->tempDir = $this->createTempDir( 'ezcGraphGdDriverTest' . sprintf( '_%03d_', ++$i ) ) . '/'; $this->basePath = dirname( __FILE__ ) . '/data/'; } @@ -42,6 +46,7 @@ class ezcGraphLineChartTest extends ezcTestCase */ public function tearDown() { + //$this->removeTempDir(); } protected function addSampleData( ezcGraphChart $chart ) @@ -54,16 +59,9 @@ class ezcGraphLineChartTest extends ezcTestCase public function testElementGenerationLegend() { - try - { - $chart = ezcGraph::create( 'Line' ); - $this->addSampleData( $chart ); - $chart->render( 500, 200 ); - } - catch ( Exception $e ) - { - $this->fail( $e->getMessage() ); - } + $chart = ezcGraph::create( 'Line' ); + $this->addSampleData( $chart ); + $chart->render( 500, 200 ); $legend = $this->getNonPublicProperty( $chart->legend, 'labels' ); @@ -100,180 +98,148 @@ class ezcGraphLineChartTest extends ezcTestCase public function testRenderChartLines() { - try - { - $chart = ezcGraph::create( 'Line' ); - $chart->sampleData = array( 'sample 1' => 234, 'sample 2' => 21, 'sample 3' => 324, 'sample 4' => 120, 'sample 5' => 1); - $chart->sampleData->color = '#CC0000'; - $chart->sampleData->symbol = ezcGraph::DIAMOND; - - $mockedRenderer = $this->getMock( 'ezcGraphRenderer2D', array( - 'drawLine', - ) ); - - $mockedRenderer - ->expects( $this->at( 28 ) ) - ->method( 'drawLine' ) - ->with( - $this->equalTo( ezcGraphColor::fromHex( '#CC0000' ) ), - $this->equalTo( new ezcGraphCoordinate( 120, 85 ) ), - $this->equalTo( new ezcGraphCoordinate( 210, 181 ) ), - $this->equalTo( true ) - ); - $mockedRenderer - ->expects( $this->at( 29 ) ) - ->method( 'drawLine' ) - ->with( - $this->equalTo( ezcGraphColor::fromHex( '#CC0000' ) ), - $this->equalTo( new ezcGraphCoordinate( 210, 181 ) ), - $this->equalTo( new ezcGraphCoordinate( 300, 44 ) ), - $this->equalTo( true ) - ); - $mockedRenderer - ->expects( $this->at( 30 ) ) - ->method( 'drawLine' ) - ->with( - $this->equalTo( ezcGraphColor::fromHex( '#CC0000' ) ), - $this->equalTo( new ezcGraphCoordinate( 300, 44 ) ), - $this->equalTo( new ezcGraphCoordinate( 390, 136 ) ), - $this->equalTo( true ) - ); - $mockedRenderer - ->expects( $this->at( 31 ) ) - ->method( 'drawLine' ) - ->with( - $this->equalTo( ezcGraphColor::fromHex( '#CC0000' ) ), - $this->equalTo( new ezcGraphCoordinate( 390, 136 ) ), - $this->equalTo( new ezcGraphCoordinate( 480, 190 ) ), - $this->equalTo( true ) - ); - - $chart->renderer = $mockedRenderer; - - $chart->render( 500, 200 ); - } - catch ( Exception $e ) - { - $this->fail( $e->getMessage() ); - } + $chart = ezcGraph::create( 'Line' ); + $chart->sampleData = array( 'sample 1' => 234, 'sample 2' => 21, 'sample 3' => 324, 'sample 4' => 120, 'sample 5' => 1); + $chart->sampleData->color = '#CC0000'; + $chart->sampleData->symbol = ezcGraph::DIAMOND; + + $mockedRenderer = $this->getMock( 'ezcGraphRenderer2D', array( + 'drawLine', + ) ); + + $mockedRenderer + ->expects( $this->at( 28 ) ) + ->method( 'drawLine' ) + ->with( + $this->equalTo( ezcGraphColor::fromHex( '#CC0000' ) ), + $this->equalTo( new ezcGraphCoordinate( 120, 85 ) ), + $this->equalTo( new ezcGraphCoordinate( 210, 181 ) ), + $this->equalTo( true ) + ); + $mockedRenderer + ->expects( $this->at( 29 ) ) + ->method( 'drawLine' ) + ->with( + $this->equalTo( ezcGraphColor::fromHex( '#CC0000' ) ), + $this->equalTo( new ezcGraphCoordinate( 210, 181 ) ), + $this->equalTo( new ezcGraphCoordinate( 300, 44 ) ), + $this->equalTo( true ) + ); + $mockedRenderer + ->expects( $this->at( 30 ) ) + ->method( 'drawLine' ) + ->with( + $this->equalTo( ezcGraphColor::fromHex( '#CC0000' ) ), + $this->equalTo( new ezcGraphCoordinate( 300, 44 ) ), + $this->equalTo( new ezcGraphCoordinate( 390, 136 ) ), + $this->equalTo( true ) + ); + $mockedRenderer + ->expects( $this->at( 31 ) ) + ->method( 'drawLine' ) + ->with( + $this->equalTo( ezcGraphColor::fromHex( '#CC0000' ) ), + $this->equalTo( new ezcGraphCoordinate( 390, 136 ) ), + $this->equalTo( new ezcGraphCoordinate( 480, 190 ) ), + $this->equalTo( true ) + ); + + $chart->renderer = $mockedRenderer; + + $chart->render( 500, 200 ); } public function testRenderChartSymbols() { - try - { - $chart = ezcGraph::create( 'Line' ); - $chart->sampleData = array( 'sample 1' => 234, 'sample 2' => 21, 'sample 3' => 324, 'sample 4' => 120, 'sample 5' => 1); - $chart->sampleData->color = '#CC0000'; - $chart->sampleData->symbol = ezcGraph::DIAMOND; - - $mockedRenderer = $this->getMock( 'ezcGraphRenderer2D', array( - 'drawSymbol', - ) ); - - $mockedRenderer - ->expects( $this->at( 1 ) ) - ->method( 'drawSymbol' ) - ->with( - $this->equalTo( ezcGraphColor::fromHex( '#CC0000' ) ), - $this->equalTo( new ezcGraphCoordinate( 116, 81 ) ), - $this->equalTo( 8 ), - $this->equalTo( 8 ), - $this->equalTo( ezcGraph::DIAMOND ) - ); - $mockedRenderer - ->expects( $this->at( 2 ) ) - ->method( 'drawSymbol' ) - ->with( - $this->equalTo( ezcGraphColor::fromHex( '#CC0000' ) ), - $this->equalTo( new ezcGraphCoordinate( 206, 177 ) ), - $this->equalTo( 8 ), - $this->equalTo( 8 ), - $this->equalTo( ezcGraph::DIAMOND ) - ); - $mockedRenderer - ->expects( $this->at( 3 ) ) - ->method( 'drawSymbol' ) - ->with( - $this->equalTo( ezcGraphColor::fromHex( '#CC0000' ) ), - $this->equalTo( new ezcGraphCoordinate( 296, 40 ) ), - $this->equalTo( 8 ), - $this->equalTo( 8 ), - $this->equalTo( ezcGraph::DIAMOND ) - ); - $mockedRenderer - ->expects( $this->at( 4 ) ) - ->method( 'drawSymbol' ) - ->with( - $this->equalTo( ezcGraphColor::fromHex( '#CC0000' ) ), - $this->equalTo( new ezcGraphCoordinate( 386, 132 ) ), - $this->equalTo( 8 ), - $this->equalTo( 8 ), - $this->equalTo( ezcGraph::DIAMOND ) - ); - $mockedRenderer - ->expects( $this->at( 5 ) ) - ->method( 'drawSymbol' ) - ->with( - $this->equalTo( ezcGraphColor::fromHex( '#CC0000' ) ), - $this->equalTo( new ezcGraphCoordinate( 476, 186 ) ), - $this->equalTo( 8 ), - $this->equalTo( 8 ), - $this->equalTo( ezcGraph::DIAMOND ) - ); - - $chart->renderer = $mockedRenderer; - - $chart->render( 500, 200 ); - } - catch ( Exception $e ) - { - $this->fail( $e->getMessage() ); - } + $chart = ezcGraph::create( 'Line' ); + $chart->sampleData = array( 'sample 1' => 234, 'sample 2' => 21, 'sample 3' => 324, 'sample 4' => 120, 'sample 5' => 1); + $chart->sampleData->color = '#CC0000'; + $chart->sampleData->symbol = ezcGraph::DIAMOND; + + $mockedRenderer = $this->getMock( 'ezcGraphRenderer2D', array( + 'drawSymbol', + ) ); + + $mockedRenderer + ->expects( $this->at( 1 ) ) + ->method( 'drawSymbol' ) + ->with( + $this->equalTo( ezcGraphColor::fromHex( '#CC0000' ) ), + $this->equalTo( new ezcGraphCoordinate( 116, 81 ) ), + $this->equalTo( 8 ), + $this->equalTo( 8 ), + $this->equalTo( ezcGraph::DIAMOND ) + ); + $mockedRenderer + ->expects( $this->at( 2 ) ) + ->method( 'drawSymbol' ) + ->with( + $this->equalTo( ezcGraphColor::fromHex( '#CC0000' ) ), + $this->equalTo( new ezcGraphCoordinate( 206, 177 ) ), + $this->equalTo( 8 ), + $this->equalTo( 8 ), + $this->equalTo( ezcGraph::DIAMOND ) + ); + $mockedRenderer + ->expects( $this->at( 3 ) ) + ->method( 'drawSymbol' ) + ->with( + $this->equalTo( ezcGraphColor::fromHex( '#CC0000' ) ), + $this->equalTo( new ezcGraphCoordinate( 296, 40 ) ), + $this->equalTo( 8 ), + $this->equalTo( 8 ), + $this->equalTo( ezcGraph::DIAMOND ) + ); + $mockedRenderer + ->expects( $this->at( 4 ) ) + ->method( 'drawSymbol' ) + ->with( + $this->equalTo( ezcGraphColor::fromHex( '#CC0000' ) ), + $this->equalTo( new ezcGraphCoordinate( 386, 132 ) ), + $this->equalTo( 8 ), + $this->equalTo( 8 ), + $this->equalTo( ezcGraph::DIAMOND ) + ); + $mockedRenderer + ->expects( $this->at( 5 ) ) + ->method( 'drawSymbol' ) + ->with( + $this->equalTo( ezcGraphColor::fromHex( '#CC0000' ) ), + $this->equalTo( new ezcGraphCoordinate( 476, 186 ) ), + $this->equalTo( 8 ), + $this->equalTo( 8 ), + $this->equalTo( ezcGraph::DIAMOND ) + ); + + $chart->renderer = $mockedRenderer; + + $chart->render( 500, 200 ); } public function testCompleteRendering() { - try - { - $chart = ezcGraph::create( 'Line' ); - $chart->title = 'Test graph'; - $chart->palette = 'Black'; + $filename = $this->tempDir . __FUNCTION__ . '.png'; - $this->addSampleData( $chart ); - $chart->driver = new ezcGraphGdDriver(); + $chart = ezcGraph::create( 'Line' ); + $chart->title = 'Test graph'; + $chart->palette = 'Black'; - $chart->options->font = $this->basePath . 'font.ttf'; - $chart->legend->font = $this->basePath . 'font2.ttf'; - $chart->render( 500, 200, 'test.png' ); - } - catch ( Exception $e ) - { - echo $e; - $this->fail( $e->getMessage() ); - } + $this->addSampleData( $chart ); + $chart->driver = new ezcGraphGdDriver(); + + $chart->options->font = $this->basePath . 'font.ttf'; + $chart->legend->font = $this->basePath . 'font2.ttf'; + $chart->render( 500, 200, $filename ); - $this->assertEquals( - $this->basePath . 'font.ttf', - $chart->options->font->font, - 'General font face should be the old one.' - ); - - $this->assertEquals( - $this->basePath . 'font.ttf', - $chart->title->font->font, - 'Font face for X axis should be the old one.' - ); - $this->assertTrue( - $chart->legend->font instanceof ezcGraphFontOptions, - 'No fontOptions object was created.' + file_exists( $filename ), + 'No image was generated.' ); $this->assertEquals( - $this->basePath . 'font2.ttf', - $chart->legend->font->font, - 'Font face for legend has not changed.' + '3e25cf259cb609c55f225ef1f5e3ed22', + md5_file( $filename ), + 'Incorrect image rendered.' ); } } diff --git a/tests/numeric_axis_test.php b/tests/numeric_axis_test.php index 6dd396a..e5378b2 100644 --- a/tests/numeric_axis_test.php +++ b/tests/numeric_axis_test.php @@ -47,23 +47,16 @@ class ezcGraphNumericAxisTest extends ezcTestCase $this->assertTrue( $chart->Y_axis instanceof ezcGraphChartElementNumericAxis - ); + ); } public function testManualScaling() { - try - { - $chart = ezcGraph::create( 'Line' ); - $chart->Y_axis->min = 10; - $chart->Y_axis->max = 50; - $chart->Y_axis->majorStep = 10; - $chart->Y_axis->minorStep = 1; - } - catch ( Exception $e ) - { - $this->fail( $e->getMessage() ); - } + $chart = ezcGraph::create( 'Line' ); + $chart->Y_axis->min = 10; + $chart->Y_axis->max = 50; + $chart->Y_axis->majorStep = 10; + $chart->Y_axis->minorStep = 1; $this->assertEquals( 10., @@ -88,18 +81,11 @@ class ezcGraphNumericAxisTest extends ezcTestCase public function testManualScalingPublicProperties() { - try - { - $chart = ezcGraph::create( 'Line' ); - $chart->Y_axis->min = 10; - $chart->Y_axis->max = 50; - $chart->Y_axis->majorStep = 10; - $chart->Y_axis->minorStep = 1; - } - catch ( Exception $e ) - { - $this->fail( $e->getMessage() ); - } + $chart = ezcGraph::create( 'Line' ); + $chart->Y_axis->min = 10; + $chart->Y_axis->max = 50; + $chart->Y_axis->majorStep = 10; + $chart->Y_axis->minorStep = 1; $this->assertEquals( 10., @@ -128,17 +114,9 @@ class ezcGraphNumericAxisTest extends ezcTestCase public function testAutomagicScalingSingle() { - try - { - $chart = ezcGraph::create( 'Line' ); - $chart->sample = array( 2000 => 20, 70, 12, 130 ); - $chart->sample->color = '#FF0000'; - $chart->render( 500, 200 ); - } - catch ( Exception $e ) - { - $this->fail( $e->getMessage() ); - } + $chart = ezcGraph::create( 'Line' ); + $chart->sample = array( 2000 => 20, 70, 12, 130 ); + $chart->render( 500, 200 ); $this->assertEquals( 0., @@ -167,17 +145,9 @@ class ezcGraphNumericAxisTest extends ezcTestCase public function testAutomagicScalingSingle2() { - try - { - $chart = ezcGraph::create( 'Line' ); - $chart->sample = array( 2000 => 1, 4.3, .2, 3.82 ); - $chart->sample->color = '#FF0000'; - $chart->render( 500, 200 ); - } - catch ( Exception $e ) - { - $this->fail( $e->getMessage() ); - } + $chart = ezcGraph::create( 'Line' ); + $chart->sample = array( 2000 => 1, 4.3, .2, 3.82 ); + $chart->render( 500, 200 ); $this->assertEquals( 0., @@ -206,17 +176,9 @@ class ezcGraphNumericAxisTest extends ezcTestCase public function testAutomagicScalingSingle3() { - try - { - $chart = ezcGraph::create( 'Line' ); - $chart->sample = array( 2000 => -1.8, 4.3, .2, 3.82 ); - $chart->sample->color = '#FF0000'; - $chart->render( 500, 200 ); - } - catch ( Exception $e ) - { - $this->fail( $e->getMessage() ); - } + $chart = ezcGraph::create( 'Line' ); + $chart->sample = array( 2000 => -1.8, 4.3, .2, 3.82 ); + $chart->render( 500, 200 ); $this->assertEquals( -2.5, @@ -245,17 +207,9 @@ class ezcGraphNumericAxisTest extends ezcTestCase public function testAutomagicScalingSingle4() { - try - { - $chart = ezcGraph::create( 'Line' ); - $chart->sample = array( 2000 => 1045, 1300, 1012, 1450 ); - $chart->sample->color = '#FF0000'; - $chart->render( 500, 200 ); - } - catch ( Exception $e ) - { - $this->fail( $e->getMessage() ); - } + $chart = ezcGraph::create( 'Line' ); + $chart->sample = array( 2000 => 1045, 1300, 1012, 1450 ); + $chart->render( 500, 200 ); $this->assertEquals( 1000., @@ -284,19 +238,10 @@ class ezcGraphNumericAxisTest extends ezcTestCase public function testAutomagicScalingMultiple() { - try - { - $chart = ezcGraph::create( 'Line' ); - $chart->sample = array( 2000 => 1045, 1300, 1012, 1450 ); - $chart->sample->color = '#FF0000'; - $chart->sample2 = array( 2000 => 1270, 1170, 1610, 1370 ); - $chart->sample2->color = '#00FF00'; - $chart->render( 500, 200 ); - } - catch ( Exception $e ) - { - $this->fail( $e->getMessage() ); - } + $chart = ezcGraph::create( 'Line' ); + $chart->sample = array( 2000 => 1045, 1300, 1012, 1450 ); + $chart->sample2 = array( 2000 => 1270, 1170, 1610, 1370 ); + $chart->render( 500, 200 ); $this->assertEquals( 1000., @@ -325,18 +270,10 @@ class ezcGraphNumericAxisTest extends ezcTestCase public function testMixedAutomagicAndManualScaling() { - try - { - $chart = ezcGraph::create( 'Line' ); - $chart->sample = array( 2000 => 1045, 1300, 1012, 1450 ); - $chart->sample->color = '#FF0000'; - $chart->Y_axis->majorStep = 50; - $chart->render( 500, 200 ); - } - catch ( Exception $e ) - { - $this->fail( $e->getMessage() ); - } + $chart = ezcGraph::create( 'Line' ); + $chart->sample = array( 2000 => 1045, 1300, 1012, 1450 ); + $chart->Y_axis->majorStep = 50; + $chart->render( 500, 200 ); $this->assertEquals( 1000., @@ -365,18 +302,10 @@ class ezcGraphNumericAxisTest extends ezcTestCase public function testPositionLeft() { - try - { - $chart = ezcGraph::create( 'Line' ); - $chart->sample = array( 2000 => 1045, 1300, 1012, 1450 ); - $chart->sample->color = '#FF0000'; - $chart->Y_axis->position = ezcGraph::LEFT; - $chart->render( 500, 200 ); - } - catch ( Exception $e ) - { - $this->fail( $e->getMessage() ); - } + $chart = ezcGraph::create( 'Line' ); + $chart->sample = array( 2000 => 1045, 1300, 1012, 1450 ); + $chart->Y_axis->position = ezcGraph::LEFT; + $chart->render( 500, 200 ); $testBoundings = new ezcGraphBoundings(); $testBoundings->x0 = 50; @@ -411,18 +340,10 @@ class ezcGraphNumericAxisTest extends ezcTestCase public function testPositionRight() { - try - { - $chart = ezcGraph::create( 'Line' ); - $chart->sample = array( 2000 => 1045, 1300, 1012, 1450 ); - $chart->sample->color = '#FF0000'; - $chart->Y_axis->position = ezcGraph::RIGHT; - $chart->render( 500, 200 ); - } - catch ( Exception $e ) - { - $this->fail( $e->getMessage() ); - } + $chart = ezcGraph::create( 'Line' ); + $chart->sample = array( 2000 => 1045, 1300, 1012, 1450 ); + $chart->Y_axis->position = ezcGraph::RIGHT; + $chart->render( 500, 200 ); $testBoundings = new ezcGraphBoundings(); $testBoundings->x0 = 50; @@ -457,18 +378,10 @@ class ezcGraphNumericAxisTest extends ezcTestCase public function testPositionTop() { - try - { - $chart = ezcGraph::create( 'Line' ); - $chart->sample = array( 2000 => 1045, 1300, 1012, 1450 ); - $chart->sample->color = '#FF0000'; - $chart->Y_axis->position = ezcGraph::TOP; - $chart->render( 500, 200 ); - } - catch ( Exception $e ) - { - $this->fail( $e->getMessage() ); - } + $chart = ezcGraph::create( 'Line' ); + $chart->sample = array( 2000 => 1045, 1300, 1012, 1450 ); + $chart->Y_axis->position = ezcGraph::TOP; + $chart->render( 500, 200 ); $testBoundings = new ezcGraphBoundings(); $testBoundings->x0 = 50; @@ -503,18 +416,10 @@ class ezcGraphNumericAxisTest extends ezcTestCase public function testPositionBottom() { - try - { - $chart = ezcGraph::create( 'Line' ); - $chart->sample = array( 2000 => 1045, 1300, 1012, 1450 ); - $chart->sample->color = '#FF0000'; - $chart->Y_axis->position = ezcGraph::BOTTOM; - $chart->render( 500, 200 ); - } - catch ( Exception $e ) - { - $this->fail( $e->getMessage() ); - } + $chart = ezcGraph::create( 'Line' ); + $chart->sample = array( 2000 => 1045, 1300, 1012, 1450 ); + $chart->Y_axis->position = ezcGraph::BOTTOM; + $chart->render( 500, 200 ); $testBoundings = new ezcGraphBoundings(); $testBoundings->x0 = 50; @@ -549,19 +454,11 @@ class ezcGraphNumericAxisTest extends ezcTestCase public function testPositionLeftNegativMinimum() { - try - { - $chart = ezcGraph::create( 'Line' ); - $chart->sample = array( 2000 => -300, 1300, 1012, 1450 ); - $chart->sample->color = '#FF0000'; - $chart->Y_axis->majorStep = 500; - $chart->Y_axis->position = ezcGraph::LEFT; - $chart->render( 500, 200 ); - } - catch ( Exception $e ) - { - $this->fail( $e->getMessage() ); - } + $chart = ezcGraph::create( 'Line' ); + $chart->sample = array( 2000 => -300, 1300, 1012, 1450 ); + $chart->Y_axis->majorStep = 500; + $chart->Y_axis->position = ezcGraph::LEFT; + $chart->render( 500, 200 ); $testBoundings = new ezcGraphBoundings(); $testBoundings->x0 = 50; @@ -596,21 +493,11 @@ class ezcGraphNumericAxisTest extends ezcTestCase public function testNullPositionMultipleDatasets() { - try - { - $chart = ezcGraph::create( 'Line' ); - $chart->sampleData = array( 'sample 1' => 234, 'sample 2' => -21, 'sample 3' => 324, 'sample 4' => 120, 'sample 5' => 1); - $chart->sampleData->color = '#CC0000'; - $chart->moreData = array( 'sample 1' => 112, 'sample 2' => 54, 'sample 3' => 12, 'sample 4' => -167, 'sample 5' => 329); - $chart->moreData->color = '#3465A4'; - $chart->evenMoreData = array( 'sample 1' => 300, 'sample 2' => -30, 'sample 3' => 220, 'sample 4' => 67, 'sample 5' => 450); - $chart->evenMoreData->color = '#73D216'; - $chart->render( 500, 200 ); - } - catch ( Exception $e ) - { - $this->fail( $e->getMessage() ); - } + $chart = ezcGraph::create( 'Line' ); + $chart->sampleData = array( 'sample 1' => 234, 'sample 2' => -21, 'sample 3' => 324, 'sample 4' => 120, 'sample 5' => 1); + $chart->moreData = array( 'sample 1' => 112, 'sample 2' => 54, 'sample 3' => 12, 'sample 4' => -167, 'sample 5' => 329); + $chart->evenMoreData = array( 'sample 1' => 300, 'sample 2' => -30, 'sample 3' => 220, 'sample 4' => 67, 'sample 5' => 450); + $chart->render( 500, 200 ); $testBoundings = new ezcGraphBoundings(); $testBoundings->x0 = 100; @@ -627,261 +514,216 @@ class ezcGraphNumericAxisTest extends ezcTestCase public function testRenderNumericAxisBase() { - try - { - $chart = ezcGraph::create( 'Line' ); - $chart->sample = array( 2000 => 1045, 1300, 1012, 1450 ); - $chart->sample->color = '#FF0000'; - $chart->sample2 = array( 2000 => 1270, 1170, 1610, 1370 ); - $chart->sample2->color = '#00FF00'; - - $mockedRenderer = $this->getMock( 'ezcGraphRenderer2D', array( - 'drawLine', - ) ); - - // Y-Axis - // Base line - $mockedRenderer - ->expects( $this->at( 5 ) ) - ->method( 'drawLine' ) - ->with( - $this->equalTo( ezcGraphColor::fromHex( '#2E3436' ) ), - $this->equalTo( new ezcGraphCoordinate( 120, 200 ) ), - $this->equalTo( new ezcGraphCoordinate( 120, 0 ) ), - $this->equalTo( false ) - ); - - $chart->renderer = $mockedRenderer; - - $chart->render( 500, 200 ); - } - catch ( Exception $e ) - { - $this->fail( $e->getMessage() ); - } + $chart = ezcGraph::create( 'Line' ); + $chart->sample = array( 2000 => 1045, 1300, 1012, 1450 ); + $chart->sample2 = array( 2000 => 1270, 1170, 1610, 1370 ); + + $mockedRenderer = $this->getMock( 'ezcGraphRenderer2D', array( + 'drawLine', + ) ); + + // Y-Axis + // Base line + $mockedRenderer + ->expects( $this->at( 5 ) ) + ->method( 'drawLine' ) + ->with( + $this->equalTo( ezcGraphColor::fromHex( '#2E3436' ) ), + $this->equalTo( new ezcGraphCoordinate( 120, 200 ) ), + $this->equalTo( new ezcGraphCoordinate( 120, 0 ) ), + $this->equalTo( false ) + ); + + $chart->renderer = $mockedRenderer; + + $chart->render( 500, 200 ); } public function testRenderNumericAxisArrowHead() { - try - { - $chart = ezcGraph::create( 'Line' ); - $chart->sample = array( 2000 => 1045, 1300, 1012, 1450 ); - $chart->sample->color = '#FF0000'; - $chart->sample2 = array( 2000 => 1270, 1170, 1610, 1370 ); - $chart->sample2->color = '#00FF00'; - - $mockedRenderer = $this->getMock( 'ezcGraphRenderer2D', array( - 'drawPolygon', - ) ); - - // X-Axis - $mockedRenderer - ->expects( $this->at( 1 ) ) - ->method( 'drawPolygon' ) - ->with( - $this->equalTo( array( - new ezcGraphCoordinate( 120, 0 ), - new ezcGraphCoordinate( 123, 5 ), - new ezcGraphCoordinate( 118, 5 ), - ) ), - $this->equalTo( ezcGraphColor::fromHex( '#2E3436' ) ), - $this->equalTo( true ) - ); - - $chart->renderer = $mockedRenderer; - - $chart->render( 500, 200 ); - } - catch ( Exception $e ) - { - $this->fail( $e->getMessage() ); - } + $chart = ezcGraph::create( 'Line' ); + $chart->sample = array( 2000 => 1045, 1300, 1012, 1450 ); + $chart->sample2 = array( 2000 => 1270, 1170, 1610, 1370 ); + + $mockedRenderer = $this->getMock( 'ezcGraphRenderer2D', array( + 'drawPolygon', + ) ); + + // X-Axis + $mockedRenderer + ->expects( $this->at( 1 ) ) + ->method( 'drawPolygon' ) + ->with( + $this->equalTo( array( + new ezcGraphCoordinate( 120, 0 ), + new ezcGraphCoordinate( 123, 5 ), + new ezcGraphCoordinate( 118, 5 ), + ) ), + $this->equalTo( ezcGraphColor::fromHex( '#2E3436' ) ), + $this->equalTo( true ) + ); + + $chart->renderer = $mockedRenderer; + + $chart->render( 500, 200 ); } public function testRenderNumericAxisMajor() { - try - { - $chart = ezcGraph::create( 'Line' ); - $chart->sample = array( 2000 => 1045, 1300, 1012, 1450 ); - $chart->sample->color = '#FF0000'; - $chart->sample2 = array( 2000 => 1270, 1170, 1610, 1370 ); - $chart->sample2->color = '#00FF00'; - - $mockedRenderer = $this->getMock( 'ezcGraphRenderer2D', array( - 'drawLine', - ) ); - - // Y-Axis - // Major step lines - $mockedRenderer - ->expects( $this->at( 6 ) ) - ->method( 'drawLine' ) - ->with( - $this->equalTo( ezcGraphColor::fromHex( '#2E3436' ) ), - $this->equalTo( new ezcGraphCoordinate( 124, 190 ) ), - $this->equalTo( new ezcGraphCoordinate( 116, 190 ) ), - $this->equalTo( false ) - ); - $mockedRenderer - ->expects( $this->at( 7 ) ) - ->method( 'drawLine' ) - ->with( - $this->equalTo( ezcGraphColor::fromHex( '#2E3436' ) ), - $this->equalTo( new ezcGraphCoordinate( 124, 130 ) ), - $this->equalTo( new ezcGraphCoordinate( 116, 130 ) ), - $this->equalTo( false ) - ); - $mockedRenderer - ->expects( $this->at( 8 ) ) - ->method( 'drawLine' ) - ->with( - $this->equalTo( ezcGraphColor::fromHex( '#2E3436' ) ), - $this->equalTo( new ezcGraphCoordinate( 124, 70 ) ), - $this->equalTo( new ezcGraphCoordinate( 116, 70 ) ), - $this->equalTo( false ) - ); - $mockedRenderer - ->expects( $this->at( 9 ) ) - ->method( 'drawLine' ) - ->with( - $this->equalTo( ezcGraphColor::fromHex( '#2E3436' ) ), - $this->equalTo( new ezcGraphCoordinate( 124, 10 ) ), - $this->equalTo( new ezcGraphCoordinate( 116, 10 ) ), - $this->equalTo( false ) - ); - - - $chart->renderer = $mockedRenderer; - - $chart->render( 500, 200 ); - } - catch ( Exception $e ) - { - $this->fail( $e->getMessage() ); - } + $chart = ezcGraph::create( 'Line' ); + $chart->sample = array( 2000 => 1045, 1300, 1012, 1450 ); + $chart->sample2 = array( 2000 => 1270, 1170, 1610, 1370 ); + + $mockedRenderer = $this->getMock( 'ezcGraphRenderer2D', array( + 'drawLine', + ) ); + + // Y-Axis + // Major step lines + $mockedRenderer + ->expects( $this->at( 6 ) ) + ->method( 'drawLine' ) + ->with( + $this->equalTo( ezcGraphColor::fromHex( '#2E3436' ) ), + $this->equalTo( new ezcGraphCoordinate( 124, 190 ) ), + $this->equalTo( new ezcGraphCoordinate( 116, 190 ) ), + $this->equalTo( false ) + ); + $mockedRenderer + ->expects( $this->at( 7 ) ) + ->method( 'drawLine' ) + ->with( + $this->equalTo( ezcGraphColor::fromHex( '#2E3436' ) ), + $this->equalTo( new ezcGraphCoordinate( 124, 130 ) ), + $this->equalTo( new ezcGraphCoordinate( 116, 130 ) ), + $this->equalTo( false ) + ); + $mockedRenderer + ->expects( $this->at( 8 ) ) + ->method( 'drawLine' ) + ->with( + $this->equalTo( ezcGraphColor::fromHex( '#2E3436' ) ), + $this->equalTo( new ezcGraphCoordinate( 124, 70 ) ), + $this->equalTo( new ezcGraphCoordinate( 116, 70 ) ), + $this->equalTo( false ) + ); + $mockedRenderer + ->expects( $this->at( 9 ) ) + ->method( 'drawLine' ) + ->with( + $this->equalTo( ezcGraphColor::fromHex( '#2E3436' ) ), + $this->equalTo( new ezcGraphCoordinate( 124, 10 ) ), + $this->equalTo( new ezcGraphCoordinate( 116, 10 ) ), + $this->equalTo( false ) + ); + + + $chart->renderer = $mockedRenderer; + + $chart->render( 500, 200 ); } public function testRenderNumericAxisMinor() { - try - { - $chart = ezcGraph::create( 'Line' ); - $chart->sample = array( 2000 => 1045, 1300, 1012, 1450 ); - $chart->sample->color = '#FF0000'; - $chart->sample2 = array( 2000 => 1270, 1170, 1610, 1370 ); - $chart->sample2->color = '#00FF00'; - - $mockedRenderer = $this->getMock( 'ezcGraphRenderer2D', array( - 'drawLine', - ) ); - - // Y-Axis - // Minor step lines - $mockedRenderer - ->expects( $this->at( 10 ) ) - ->method( 'drawLine' ) - ->with( - $this->equalTo( ezcGraphColor::fromHex( '#2E3436' ) ), - $this->equalTo( new ezcGraphCoordinate( 122, 190 ) ), - $this->equalTo( new ezcGraphCoordinate( 118, 190 ) ), - $this->equalTo( false ) - ); - $mockedRenderer - ->expects( $this->at( 11 ) ) - ->method( 'drawLine' ) - ->with( - $this->equalTo( ezcGraphColor::fromHex( '#2E3436' ) ), - $this->equalTo( new ezcGraphCoordinate( 122, 178 ) ), - $this->equalTo( new ezcGraphCoordinate( 118, 178 ) ), - $this->equalTo( false ) - ); - $mockedRenderer - ->expects( $this->at( 12 ) ) - ->method( 'drawLine' ) - ->with( - $this->equalTo( ezcGraphColor::fromHex( '#2E3436' ) ), - $this->equalTo( new ezcGraphCoordinate( 122, 166 ) ), - $this->equalTo( new ezcGraphCoordinate( 118, 166 ) ), - $this->equalTo( false ) - ); - - // Last minor step - $mockedRenderer - ->expects( $this->at( 24 ) ) - ->method( 'drawLine' ) - ->with( - $this->equalTo( ezcGraphColor::fromHex( '#2E3436' ) ), - $this->equalTo( new ezcGraphCoordinate( 122, 22 ) ), - $this->equalTo( new ezcGraphCoordinate( 118, 22 ) ), - $this->equalTo( false ) - ); - - $chart->renderer = $mockedRenderer; - - $chart->render( 500, 200 ); - } - catch ( Exception $e ) - { - $this->fail( $e->getMessage() ); - } + $chart = ezcGraph::create( 'Line' ); + $chart->sample = array( 2000 => 1045, 1300, 1012, 1450 ); + $chart->sample2 = array( 2000 => 1270, 1170, 1610, 1370 ); + + $mockedRenderer = $this->getMock( 'ezcGraphRenderer2D', array( + 'drawLine', + ) ); + + // Y-Axis + // Minor step lines + $mockedRenderer + ->expects( $this->at( 10 ) ) + ->method( 'drawLine' ) + ->with( + $this->equalTo( ezcGraphColor::fromHex( '#2E3436' ) ), + $this->equalTo( new ezcGraphCoordinate( 122, 190 ) ), + $this->equalTo( new ezcGraphCoordinate( 118, 190 ) ), + $this->equalTo( false ) + ); + $mockedRenderer + ->expects( $this->at( 11 ) ) + ->method( 'drawLine' ) + ->with( + $this->equalTo( ezcGraphColor::fromHex( '#2E3436' ) ), + $this->equalTo( new ezcGraphCoordinate( 122, 178 ) ), + $this->equalTo( new ezcGraphCoordinate( 118, 178 ) ), + $this->equalTo( false ) + ); + $mockedRenderer + ->expects( $this->at( 12 ) ) + ->method( 'drawLine' ) + ->with( + $this->equalTo( ezcGraphColor::fromHex( '#2E3436' ) ), + $this->equalTo( new ezcGraphCoordinate( 122, 166 ) ), + $this->equalTo( new ezcGraphCoordinate( 118, 166 ) ), + $this->equalTo( false ) + ); + + // Last minor step + $mockedRenderer + ->expects( $this->at( 24 ) ) + ->method( 'drawLine' ) + ->with( + $this->equalTo( ezcGraphColor::fromHex( '#2E3436' ) ), + $this->equalTo( new ezcGraphCoordinate( 122, 22 ) ), + $this->equalTo( new ezcGraphCoordinate( 118, 22 ) ), + $this->equalTo( false ) + ); + + $chart->renderer = $mockedRenderer; + + $chart->render( 500, 200 ); } public function testRenderNumericAxisLabels() { - try - { - $chart = ezcGraph::create( 'Line' ); - $chart->sample = array( 2000 => 1045, 1300, 1012, 1450 ); - $chart->sample->color = '#FF0000'; - $chart->sample2 = array( 2000 => 1270, 1170, 1610, 1370 ); - $chart->sample2->color = '#00FF00'; - - $mockedRenderer = $this->getMock( 'ezcGraphRenderer2D', array( - 'drawTextBox', - ) ); - - // Y-Axis - $mockedRenderer - ->expects( $this->at( 7 ) ) - ->method( 'drawTextBox' ) - ->with( - $this->equalTo( new ezcGraphCoordinate( 100, 130 ) ), - $this->equalTo( '1000' ), - $this->equalTo( 18 ), - $this->equalTo( 58 ), - $this->equalTo( ezcGraph::RIGHT | ezcGraph::BOTTOM ) - ); - $mockedRenderer - ->expects( $this->at( 8 ) ) - ->method( 'drawTextBox' ) - ->with( - $this->equalTo( new ezcGraphCoordinate( 100, 70 ) ), - $this->equalTo( '1250' ), - $this->equalTo( 18 ), - $this->equalTo( 58 ), - $this->equalTo( ezcGraph::RIGHT | ezcGraph::BOTTOM ) - ); - $mockedRenderer - ->expects( $this->at( 9 ) ) - ->method( 'drawTextBox' ) - ->with( - $this->equalTo( new ezcGraphCoordinate( 100, 10 ) ), - $this->equalTo( '1500' ), - $this->equalTo( 18 ), - $this->equalTo( 58 ), - $this->equalTo( ezcGraph::RIGHT | ezcGraph::BOTTOM ) - ); - - $chart->renderer = $mockedRenderer; - - $chart->render( 500, 200 ); - } - catch ( Exception $e ) - { - $this->fail( $e->getMessage() ); - } + $chart = ezcGraph::create( 'Line' ); + $chart->sample = array( 2000 => 1045, 1300, 1012, 1450 ); + $chart->sample2 = array( 2000 => 1270, 1170, 1610, 1370 ); + + $mockedRenderer = $this->getMock( 'ezcGraphRenderer2D', array( + 'drawTextBox', + ) ); + + // Y-Axis + $mockedRenderer + ->expects( $this->at( 7 ) ) + ->method( 'drawTextBox' ) + ->with( + $this->equalTo( new ezcGraphCoordinate( 100, 130 ) ), + $this->equalTo( '1000' ), + $this->equalTo( 18 ), + $this->equalTo( 58 ), + $this->equalTo( ezcGraph::RIGHT | ezcGraph::BOTTOM ) + ); + $mockedRenderer + ->expects( $this->at( 8 ) ) + ->method( 'drawTextBox' ) + ->with( + $this->equalTo( new ezcGraphCoordinate( 100, 70 ) ), + $this->equalTo( '1250' ), + $this->equalTo( 18 ), + $this->equalTo( 58 ), + $this->equalTo( ezcGraph::RIGHT | ezcGraph::BOTTOM ) + ); + $mockedRenderer + ->expects( $this->at( 9 ) ) + ->method( 'drawTextBox' ) + ->with( + $this->equalTo( new ezcGraphCoordinate( 100, 10 ) ), + $this->equalTo( '1500' ), + $this->equalTo( 18 ), + $this->equalTo( 58 ), + $this->equalTo( ezcGraph::RIGHT | ezcGraph::BOTTOM ) + ); + + $chart->renderer = $mockedRenderer; + + $chart->render( 500, 200 ); } } ?> diff --git a/tests/palette_test.php b/tests/palette_test.php index 2abe558..9cdbec3 100644 --- a/tests/palette_test.php +++ b/tests/palette_test.php @@ -43,14 +43,7 @@ class ezcGraphPaletteTest extends ezcTestCase public function testDefaultPalette() { - try - { - $chart = ezcGraph::create( 'Line' ); - } - catch ( Exception $e ) - { - $this->fail( $e->getMessage() ); - } + $chart = ezcGraph::create( 'Line' ); $this->assertTrue( $chart->palette instanceof ezcGraphPalette, @@ -65,15 +58,8 @@ class ezcGraphPaletteTest extends ezcTestCase public function testChangePalette() { - try - { - $chart = ezcGraph::create( 'Line' ); - $chart->palette = 'Black'; - } - catch ( Exception $e ) - { - $this->fail( $e->getMessage() ); - } + $chart = ezcGraph::create( 'Line' ); + $chart->palette = 'Black'; $this->assertTrue( $chart->palette instanceof ezcGraphPalette, @@ -97,24 +83,13 @@ class ezcGraphPaletteTest extends ezcTestCase { return true; } - catch ( Exception $e ) - { - $this->fail( $e->getMessage() ); - } $this->fail( 'Expected ezcGraphUnknownPaletteException.' ); } public function testChartBackgroundColor() { - try - { - $chart = ezcGraph::create( 'Line' ); - } - catch ( Exception $e ) - { - $this->fail( $e->getMessage() ); - } + $chart = ezcGraph::create( 'Line' ); $this->assertEquals( ezcGraphColor::fromHex( '#EEEEEC' ), @@ -125,14 +100,7 @@ class ezcGraphPaletteTest extends ezcTestCase public function testElementBackgroundColor() { - try - { - $chart = ezcGraph::create( 'Line' ); - } - catch ( Exception $e ) - { - $this->fail( $e->getMessage() ); - } + $chart = ezcGraph::create( 'Line' ); $this->assertEquals( ezcGraphColor::fromHex( '#000000FF' ), @@ -143,14 +111,7 @@ class ezcGraphPaletteTest extends ezcTestCase public function testAxisColor() { - try - { - $chart = ezcGraph::create( 'Line' ); - } - catch ( Exception $e ) - { - $this->fail( $e->getMessage() ); - } + $chart = ezcGraph::create( 'Line' ); $this->assertEquals( ezcGraphColor::fromHex( '#2E3436' ), @@ -161,14 +122,7 @@ class ezcGraphPaletteTest extends ezcTestCase public function testDataSetColor() { - try - { - $chart = ezcGraph::create( 'Line' ); - } - catch ( Exception $e ) - { - $this->fail( $e->getMessage() ); - } + $chart = ezcGraph::create( 'Line' ); $this->assertEquals( ezcGraphColor::fromHex( '#3465A4' ), @@ -227,14 +181,7 @@ class ezcGraphPaletteTest extends ezcTestCase public function testDataSetSymbol() { - try - { - $chart = ezcGraph::create( 'Line' ); - } - catch ( Exception $e ) - { - $this->fail( $e->getMessage() ); - } + $chart = ezcGraph::create( 'Line' ); $this->assertEquals( ezcGraph::NO_SYMBOL, @@ -251,14 +198,7 @@ class ezcGraphPaletteTest extends ezcTestCase public function testFontFace() { - try - { - $chart = ezcGraph::create( 'Line' ); - } - catch ( Exception $e ) - { - $this->fail( $e->getMessage() ); - } + $chart = ezcGraph::create( 'Line' ); $this->assertEquals( 'Vera.ttf', @@ -269,14 +209,7 @@ class ezcGraphPaletteTest extends ezcTestCase public function testFontColor() { - try - { - $chart = ezcGraph::create( 'Line' ); - } - catch ( Exception $e ) - { - $this->fail( $e->getMessage() ); - } + $chart = ezcGraph::create( 'Line' ); $this->assertEquals( ezcGraphColor::fromHex( '#555753' ), @@ -287,14 +220,7 @@ class ezcGraphPaletteTest extends ezcTestCase public function testChartBorderColor() { - try - { - $chart = ezcGraph::create( 'Line' ); - } - catch ( Exception $e ) - { - $this->fail( $e->getMessage() ); - } + $chart = ezcGraph::create( 'Line' ); $this->assertEquals( ezcGraphColor::fromHex( '#000000FF' ), @@ -305,14 +231,7 @@ class ezcGraphPaletteTest extends ezcTestCase public function testChartBorderWidth() { - try - { - $chart = ezcGraph::create( 'Line' ); - } - catch ( Exception $e ) - { - $this->fail( $e->getMessage() ); - } + $chart = ezcGraph::create( 'Line' ); $this->assertEquals( 0, @@ -323,14 +242,7 @@ class ezcGraphPaletteTest extends ezcTestCase public function testElementBorderColor() { - try - { - $chart = ezcGraph::create( 'Line' ); - } - catch ( Exception $e ) - { - $this->fail( $e->getMessage() ); - } + $chart = ezcGraph::create( 'Line' ); $this->assertEquals( ezcGraphColor::fromHex( '#000000FF' ), @@ -341,14 +253,7 @@ class ezcGraphPaletteTest extends ezcTestCase public function testElementBorderWidth() { - try - { - $chart = ezcGraph::create( 'Line' ); - } - catch ( Exception $e ) - { - $this->fail( $e->getMessage() ); - } + $chart = ezcGraph::create( 'Line' ); $this->assertEquals( 0, @@ -359,14 +264,7 @@ class ezcGraphPaletteTest extends ezcTestCase public function testPadding() { - try - { - $chart = ezcGraph::create( 'Line' ); - } - catch ( Exception $e ) - { - $this->fail( $e->getMessage() ); - } + $chart = ezcGraph::create( 'Line' ); $this->assertEquals( 1, @@ -377,14 +275,7 @@ class ezcGraphPaletteTest extends ezcTestCase public function testMargin() { - try - { - $chart = ezcGraph::create( 'Line' ); - } - catch ( Exception $e ) - { - $this->fail( $e->getMessage() ); - } + $chart = ezcGraph::create( 'Line' ); $this->assertEquals( 0, @@ -395,16 +286,9 @@ class ezcGraphPaletteTest extends ezcTestCase public function testDatasetAutomaticColorization() { - try - { - $chart = ezcGraph::create( 'Line' ); - $chart->income = array( 2000 => 2345.2, 2456.3, 2567.4 ); - $chart->spending = array( 2000 => 2347.2, 2458.3, 2569.4 ); - } - catch ( Exception $e ) - { - $this->fail( $e->getMessage() ); - } + $chart = ezcGraph::create( 'Line' ); + $chart->income = array( 2000 => 2345.2, 2456.3, 2567.4 ); + $chart->spending = array( 2000 => 2347.2, 2458.3, 2569.4 ); $this->assertEquals( ezcGraphColor::fromHex( '#3465A4' ), @@ -421,16 +305,9 @@ class ezcGraphPaletteTest extends ezcTestCase public function testChartBackground() { - try - { - $chart = ezcGraph::create( 'Line' ); - $chart->income = array( 2000 => 2345.2, 2456.3, 2567.4 ); - $chart->spending = array( 2000 => 2347.2, 2458.3, 2569.4 ); - } - catch ( Exception $e ) - { - $this->fail( $e->getMessage() ); - } + $chart = ezcGraph::create( 'Line' ); + $chart->income = array( 2000 => 2345.2, 2456.3, 2567.4 ); + $chart->spending = array( 2000 => 2347.2, 2458.3, 2569.4 ); $this->assertEquals( ezcGraphColor::fromHex( '#EEEEEC' ), @@ -441,16 +318,9 @@ class ezcGraphPaletteTest extends ezcTestCase public function testChartElementBorder() { - try - { - $chart = ezcGraph::create( 'Line' ); - $chart->income = array( 2000 => 2345.2, 2456.3, 2567.4 ); - $chart->spending = array( 2000 => 2347.2, 2458.3, 2569.4 ); - } - catch ( Exception $e ) - { - $this->fail( $e->getMessage() ); - } + $chart = ezcGraph::create( 'Line' ); + $chart->income = array( 2000 => 2345.2, 2456.3, 2567.4 ); + $chart->spending = array( 2000 => 2347.2, 2458.3, 2569.4 ); $this->assertEquals( ezcGraphColor::fromHex( '#000000FF' ), @@ -461,16 +331,9 @@ class ezcGraphPaletteTest extends ezcTestCase public function testChartElementBorderWidth() { - try - { - $chart = ezcGraph::create( 'Line' ); - $chart->income = array( 2000 => 2345.2, 2456.3, 2567.4 ); - $chart->spending = array( 2000 => 2347.2, 2458.3, 2569.4 ); - } - catch ( Exception $e ) - { - $this->fail( $e->getMessage() ); - } + $chart = ezcGraph::create( 'Line' ); + $chart->income = array( 2000 => 2345.2, 2456.3, 2567.4 ); + $chart->spending = array( 2000 => 2347.2, 2458.3, 2569.4 ); $this->assertEquals( 0, @@ -481,16 +344,9 @@ class ezcGraphPaletteTest extends ezcTestCase public function testChartElementAxisColor() { - try - { - $chart = ezcGraph::create( 'Line' ); - $chart->income = array( 2000 => 2345.2, 2456.3, 2567.4 ); - $chart->spending = array( 2000 => 2347.2, 2458.3, 2569.4 ); - } - catch ( Exception $e ) - { - $this->fail( $e->getMessage() ); - } + $chart = ezcGraph::create( 'Line' ); + $chart->income = array( 2000 => 2345.2, 2456.3, 2567.4 ); + $chart->spending = array( 2000 => 2347.2, 2458.3, 2569.4 ); $this->assertEquals( ezcGraphColor::fromHex( '#2E3436' ), diff --git a/tests/pie_test.php b/tests/pie_test.php index b4c6d22..bcfceee 100644 --- a/tests/pie_test.php +++ b/tests/pie_test.php @@ -43,18 +43,11 @@ class ezcGraphPieChartTest extends ezcTestCase public function testElementGenerationLegend() { - try - { - $chart = ezcGraph::create( 'Pie' ); - $chart->sampleData = array( 'sample 1' => 234, 'sample 2' => 21, 'sample 3' => 324, 'sample 4' => 120, 'sample 5' => 1); - $chart->sampleData->color = '#0000FF'; - $chart->sampleData->color['sample 3'] = '#FF0000'; - $chart->render( 500, 200 ); - } - catch ( Exception $e ) - { - $this->fail( $e->getMessage() ); - } + $chart = ezcGraph::create( 'Pie' ); + $chart->sampleData = array( 'sample 1' => 234, 'sample 2' => 21, 'sample 3' => 324, 'sample 4' => 120, 'sample 5' => 1); + $chart->sampleData->color = '#0000FF'; + $chart->sampleData->color['sample 3'] = '#FF0000'; + $chart->render( 500, 200 ); $legend = $this->getNonPublicProperty( $chart->legend, 'labels' ); diff --git a/tests/renderer_2d_test.php b/tests/renderer_2d_test.php index 9be5df6..5b236bb 100644 --- a/tests/renderer_2d_test.php +++ b/tests/renderer_2d_test.php @@ -34,25 +34,18 @@ class ezcGraphRenderer2dTest extends ezcTestCase */ public function setUp() { - try - { - $this->renderer = new ezcGraphRenderer2D(); - - $this->driver = $this->getMock( 'ezcGraphGdDriver', array( - 'drawPolygon', - 'drawLine', - 'drawTextBox', - 'drawCircleSector', - 'drawCircularArc', - 'drawCircle', - 'drawImage', - ) ); - $this->renderer->setDriver( $this->driver ); - } - catch ( Exception $e ) - { - $this->fail( $e->getMessage() ); - } + $this->renderer = new ezcGraphRenderer2D(); + + $this->driver = $this->getMock( 'ezcGraphGdDriver', array( + 'drawPolygon', + 'drawLine', + 'drawTextBox', + 'drawCircleSector', + 'drawCircularArc', + 'drawCircle', + 'drawImage', + ) ); + $this->renderer->setDriver( $this->driver ); } /** diff --git a/tests/text_test.php b/tests/text_test.php index 22e7986..8814dee 100644 --- a/tests/text_test.php +++ b/tests/text_test.php @@ -43,75 +43,59 @@ class ezcGraphTextTest extends ezcTestCase public function testRenderTextTop() { - try - { - $chart = ezcGraph::create( 'Line' ); - $chart->sample = array( 'foo' => 1, 'bar' => 10 ); - $chart->sample->color = '#FF0000'; - - $chart->title = 'Title of a chart'; - - $mockedRenderer = $this->getMock( 'ezcGraphRenderer2D', array( - 'drawTextBox', - ) ); - - // Y-Axis - $mockedRenderer - ->expects( $this->at( 0 ) ) - ->method( 'drawTextBox' ) - ->with( - $this->equalTo( new ezcGraphCoordinate( 1, 1 ) ), - $this->equalTo( 'Title of a chart' ), - $this->equalTo( 498 ), - $this->equalTo( 18 ), - $this->equalTo( ezcGraph::CENTER | ezcGraph::MIDDLE ) - ); - - $chart->renderer = $mockedRenderer; - - $chart->render( 500, 200 ); - } - catch ( Exception $e ) - { - $this->fail( $e->getMessage() ); - } + $chart = ezcGraph::create( 'Line' ); + $chart->sample = array( 'foo' => 1, 'bar' => 10 ); + + $chart->title = 'Title of a chart'; + + $mockedRenderer = $this->getMock( 'ezcGraphRenderer2D', array( + 'drawTextBox', + ) ); + + // Y-Axis + $mockedRenderer + ->expects( $this->at( 0 ) ) + ->method( 'drawTextBox' ) + ->with( + $this->equalTo( new ezcGraphCoordinate( 1, 1 ) ), + $this->equalTo( 'Title of a chart' ), + $this->equalTo( 498 ), + $this->equalTo( 18 ), + $this->equalTo( ezcGraph::CENTER | ezcGraph::MIDDLE ) + ); + + $chart->renderer = $mockedRenderer; + + $chart->render( 500, 200 ); } public function testRenderTextBottom() { - try - { - $chart = ezcGraph::create( 'Line' ); - $chart->sample = array( 'foo' => 1, 'bar' => 10 ); - $chart->sample->color = '#FF0000'; - - $chart->title = 'Title of a chart'; - $chart->title->position = ezcGraph::BOTTOM; - - $mockedRenderer = $this->getMock( 'ezcGraphRenderer2D', array( - 'drawTextBox', - ) ); - - // Y-Axis - $mockedRenderer - ->expects( $this->at( 0 ) ) - ->method( 'drawTextBox' ) - ->with( - $this->equalTo( new ezcGraphCoordinate( 1, 181 ) ), - $this->equalTo( 'Title of a chart' ), - $this->equalTo( 498 ), - $this->equalTo( 18 ), - $this->equalTo( ezcGraph::CENTER | ezcGraph::MIDDLE ) - ); - - $chart->renderer = $mockedRenderer; - - $chart->render( 500, 200 ); - } - catch ( Exception $e ) - { - $this->fail( $e->getMessage() ); - } + $chart = ezcGraph::create( 'Line' ); + $chart->sample = array( 'foo' => 1, 'bar' => 10 ); + + $chart->title = 'Title of a chart'; + $chart->title->position = ezcGraph::BOTTOM; + + $mockedRenderer = $this->getMock( 'ezcGraphRenderer2D', array( + 'drawTextBox', + ) ); + + // Y-Axis + $mockedRenderer + ->expects( $this->at( 0 ) ) + ->method( 'drawTextBox' ) + ->with( + $this->equalTo( new ezcGraphCoordinate( 1, 181 ) ), + $this->equalTo( 'Title of a chart' ), + $this->equalTo( 498 ), + $this->equalTo( 18 ), + $this->equalTo( ezcGraph::CENTER | ezcGraph::MIDDLE ) + ); + + $chart->renderer = $mockedRenderer; + + $chart->render( 500, 200 ); } } |