diff options
author | Kore Nordmann <github@kore-nordmann.de> | 2006-08-09 08:08:43 +0000 |
---|---|---|
committer | Kore Nordmann <github@kore-nordmann.de> | 2006-08-09 08:08:43 +0000 |
commit | 7590db4ae7a46bf9fdf71813a4e00ce3eb1c67f9 (patch) | |
tree | 6368608582d5932a1dc8a8568cebc8a7fdb52471 /tests/date_axis_test.php | |
parent | 63b5d5f3f2dee22c890d219aeb8e4cc7fd228f41 (diff) | |
download | zetacomponents-graph-7590db4ae7a46bf9fdf71813a4e00ce3eb1c67f9.zip zetacomponents-graph-7590db4ae7a46bf9fdf71813a4e00ce3eb1c67f9.tar.gz |
- Added date axis
Diffstat (limited to 'tests/date_axis_test.php')
-rw-r--r-- | tests/date_axis_test.php | 354 |
1 files changed, 354 insertions, 0 deletions
diff --git a/tests/date_axis_test.php b/tests/date_axis_test.php new file mode 100644 index 0000000..a78f1cc --- /dev/null +++ b/tests/date_axis_test.php @@ -0,0 +1,354 @@ +<?php +/** + * ezcGraphDateAxisTest + * + * @package Graph + * @version //autogen// + * @subpackage Tests + * @copyright Copyright (C) 2005, 2006 eZ systems as. All rights reserved. + * @license http://ez.no/licenses/new_bsd New BSD License + */ + +/** + * Tests for ezcGraph class. + * + * @package ImageAnalysis + * @subpackage Tests + */ +class ezcGraphDateAxisTest extends ezcTestCase +{ + + protected $chart; + + public static function suite() + { + return new ezcTestSuite( "ezcGraphDateAxisTest" ); + } + + /** + * setUp + * + * @access public + */ + public function setUp() + { + date_default_timezone_set( 'Europe/Berlin' ); + + $this->chart = new ezcGraphLineChart(); + $this->chart->xAxis = new ezcGraphChartElementDateAxis(); + } + + /** + * tearDown + * + * @access public + */ + public function tearDown() + { + unset( $this->chart ); + } + + public function testManualScaling() + { + $this->chart->xAxis->startDate = 0; + $this->chart->xAxis->endDate = 100; + $this->chart->xAxis->interval = 10; + + $this->chart['some data'] = array( 10 => 12, 37 => 235, 43 => 17, 114 => 39 ); + + $this->chart->render( 500, 200 ); + + $this->assertEquals( + 0, + $this->getNonPublicProperty( $this->chart->xAxis, 'startDate' ), + 'Wrong starting date. ' + ); + + $this->assertEquals( + 100, + $this->getNonPublicProperty( $this->chart->xAxis, 'endDate' ), + 'Wrong end date. ' + ); + + $this->assertEquals( + 10, + $this->getNonPublicProperty( $this->chart->xAxis, 'interval' ), + 'Wrong interval. ' + ); + } + + public function testManualBoundingsForScaling() + { + $this->chart->xAxis->startDate = 0; + $this->chart->xAxis->endDate = 100; + + $this->chart['some data'] = array( 10 => 12, 37 => 235, 43 => 17, 114 => 39 ); + + $this->chart->render( 500, 200 ); + + $this->assertEquals( + 0, + $this->getNonPublicProperty( $this->chart->xAxis, 'startDate' ), + 'Wrong starting date. ' + ); + + $this->assertEquals( + 100, + $this->getNonPublicProperty( $this->chart->xAxis, 'endDate' ), + 'Wrong end date. ' + ); + + $this->assertEquals( + 10, + $this->getNonPublicProperty( $this->chart->xAxis, 'interval' ), + 'Wrong interval. ' + ); + } + + public function testManualIntervalForScaling() + { + $this->chart->xAxis->interval = 10; + + $this->chart['some data'] = array( 10 => 12, 37 => 235, 43 => 17, 114 => 39 ); + + $this->chart->render( 500, 200 ); + + $this->assertEquals( + 10, + $this->getNonPublicProperty( $this->chart->xAxis, 'startDate' ), + 'Wrong starting date. ' + ); + + $this->assertEquals( + 120, + $this->getNonPublicProperty( $this->chart->xAxis, 'endDate' ), + 'Wrong end date. ' + ); + + $this->assertEquals( + 10, + $this->getNonPublicProperty( $this->chart->xAxis, 'interval' ), + 'Wrong interval. ' + ); + } + + public function testAutomagicScalingSingle1() + { + $this->chart['some data'] = array( 10 => 12, 37 => 235, 43 => 17, 114 => 39 ); + $this->chart->render( 500, 200 ); + + $this->assertEquals( + 0, + $this->getNonPublicProperty( $this->chart->xAxis, 'startDate' ), + 'Wrong starting date. ' + ); + + $this->assertEquals( + 120, + $this->getNonPublicProperty( $this->chart->xAxis, 'endDate' ), + 'Wrong end date. ' + ); + + $this->assertEquals( + 30, + $this->getNonPublicProperty( $this->chart->xAxis, 'interval' ), + 'Wrong interval. ' + ); + } + + public function testAutomagicScalingSingle2() + { + $this->chart['some data'] = array( 30010 => 12, 30037 => 235, 30043 => 17, 30114 => 39 ); + $this->chart->render( 500, 200 ); + + $this->assertEquals( + 30000, + $this->getNonPublicProperty( $this->chart->xAxis, 'startDate' ), + 'Wrong starting date. ' + ); + + $this->assertEquals( + 30120, + $this->getNonPublicProperty( $this->chart->xAxis, 'endDate' ), + 'Wrong end date. ' + ); + + $this->assertEquals( + 30, + $this->getNonPublicProperty( $this->chart->xAxis, 'interval' ), + 'Wrong interval. ' + ); + } + + public function testAutomagicScalingSingle3() + { + $this->chart['some data'] = array( + mktime( 10, 13, 57, 5, 7, 2006 ) => 324, + mktime( 10, 46, 13, 5, 7, 2006 ) => 324, + mktime( 11, 15, 45, 5, 7, 2006 ) => 324, + mktime( 12, 32, 01, 5, 7, 2006 ) => 324, + ); + $this->chart->render( 500, 200 ); + + $this->assertEquals( + 'Sun, 07 May 2006 10:00:00 +0200', + date( 'r', $this->getNonPublicProperty( $this->chart->xAxis, 'startDate' ) ), + 'Wrong starting date. ' + ); + + $this->assertEquals( + 'Sun, 07 May 2006 13:00:00 +0200', + date( 'r', $this->getNonPublicProperty( $this->chart->xAxis, 'endDate' ) ), + 'Wrong end date. ' + ); + + $this->assertEquals( + 1800, + $this->getNonPublicProperty( $this->chart->xAxis, 'interval' ), + 'Wrong interval. ' + ); + } + + public function testAutomagicScalingSingle4() + { + $this->chart['some data'] = array( + mktime( 10, 13, 57, 5, 7, 2006 ) => 324, + mktime( 17, 46, 13, 5, 7, 2006 ) => 324, + mktime( 11, 15, 45, 5, 8, 2006 ) => 324, + mktime( 20, 32, 1, 5, 8, 2006 ) => 324, + mktime( 8, 43, 19, 5, 9, 2006 ) => 324, + ); + $this->chart->render( 500, 200 ); + + $this->assertEquals( + 'Sun, 07 May 2006 06:00:00 +0200', + date( 'r', $this->getNonPublicProperty( $this->chart->xAxis, 'startDate' ) ), + 'Wrong starting date. ' + ); + + $this->assertEquals( + 'Tue, 09 May 2006 12:00:00 +0200', + date( 'r', $this->getNonPublicProperty( $this->chart->xAxis, 'endDate' ) ), + 'Wrong end date. ' + ); + + $this->assertEquals( + 21600, + $this->getNonPublicProperty( $this->chart->xAxis, 'interval' ), + 'Wrong interval. ' + ); + } + + public function testAutomagicScalingSingle5() + { + $this->chart['some data'] = array( + mktime( 1, 0, 0, 1, 1, 2001 ) => 324, + mktime( 1, 0, 0, 1, 1, 2002 ) => 324, + mktime( 1, 0, 0, 1, 1, 2003 ) => 324, + mktime( 1, 0, 0, 1, 1, 2004 ) => 324, + ); + $this->chart->render( 500, 200 ); + + $this->assertEquals( + 'Mon, 01 Jan 2001 01:00:00 +0100', + date( 'r', $this->getNonPublicProperty( $this->chart->xAxis, 'startDate' ) ), + 'Wrong starting date. ' + ); + + $this->assertEquals( + 'Thu, 01 Jan 2004 01:00:00 +0100', + date( 'r', $this->getNonPublicProperty( $this->chart->xAxis, 'endDate' ) ), + 'Wrong end date. ' + ); + + $this->assertEquals( + 31536000, + $this->getNonPublicProperty( $this->chart->xAxis, 'interval' ), + 'Wrong interval. ' + ); + } + + public function testPositionLeft() + { + $this->chart['some data'] = array( + mktime( 10, 13, 57, 5, 7, 2006 ) => 324, + mktime( 17, 46, 13, 5, 7, 2006 ) => 324, + mktime( 11, 15, 45, 5, 8, 2006 ) => 324, + mktime( 20, 32, 1, 5, 8, 2006 ) => 324, + mktime( 8, 43, 19, 5, 9, 2006 ) => 324, + ); + $this->chart->xAxis->position = ezcGraph::LEFT; + $this->chart->render( 500, 200 ); + + $this->assertEquals( + 0., + $this->chart->xAxis->getCoordinate( false ), + 'Wrong initial axis position. ', + .05 + ); + + $this->assertEquals( + 0., + $this->chart->xAxis->getCoordinate( mktime( 6, 0, 0, 5, 7, 2006 ) ), + 'Wrong minimal value. ', + .05 + ); + + $this->assertEquals( + .575, + $this->chart->xAxis->getCoordinate( mktime( 13, 1, 34, 5, 8, 2006 ) ), + 'Wrong mid value. ', + .05 + ); + + $this->assertEquals( + 1., + $this->chart->xAxis->getCoordinate( mktime( 12, 0, 0, 5, 9, 2006 ) ), + 'Wrong maximum value. ', + .05 + ); + } + + public function testPositionRight() + { + $this->chart['some data'] = array( + mktime( 10, 13, 57, 5, 7, 2006 ) => 324, + mktime( 17, 46, 13, 5, 7, 2006 ) => 324, + mktime( 11, 15, 45, 5, 8, 2006 ) => 324, + mktime( 20, 32, 1, 5, 8, 2006 ) => 324, + mktime( 8, 43, 19, 5, 9, 2006 ) => 324, + ); + $this->chart->xAxis->position = ezcGraph::RIGHT; + $this->chart->render( 500, 200 ); + + $this->assertEquals( + 1., + $this->chart->xAxis->getCoordinate( false ), + 'Wrong initial axis position. ', + .05 + ); + + $this->assertEquals( + 1., + $this->chart->xAxis->getCoordinate( mktime( 6, 0, 0, 5, 7, 2006 ) ), + 'Wrong minimal value. ', + .05 + ); + + $this->assertEquals( + .425, + $this->chart->xAxis->getCoordinate( mktime( 13, 1, 34, 5, 8, 2006 ) ), + 'Wrong mid value. ', + .05 + ); + + $this->assertEquals( + 0., + $this->chart->xAxis->getCoordinate( mktime( 12, 0, 0, 5, 9, 2006 ) ), + 'Wrong maximum value. ', + .05 + ); + } +} + +?> |