'jpeg.jpg', 'png' => 'png.png', ); public static function suite() { return new ezcTestSuite( "ezcGraphSvgDriverTest" ); } /** * setUp * * @access public */ public function setUp() { static $i = 0; $this->tempDir = $this->createTempDir( __CLASS__ . sprintf( '_%03d_', ++$i ) ) . '/'; $this->basePath = dirname( __FILE__ ) . '/data/'; $this->driver = new ezcGraphSvgDriver(); $this->driver->options->width = 200; $this->driver->options->height = 100; $this->driver->options->font->font = $this->basePath . 'font.ttf'; } /** * tearDown * * @access public */ public function tearDown() { unset( $this->driver ); $this->removeTempDir(); } /** * Compares a generated image with a stored file * * @param string $generated Filename of generated image * @param string $compare Filename of stored image * @return void */ protected function compare( $generated, $compare ) { $this->assertTrue( file_exists( $generated ), 'No image file has been created.' ); $this->assertTrue( file_exists( $compare ), 'Comparision image does not exist.' ); if ( md5_file( $generated ) !== md5_file( $compare ) ) { // Adding a diff makes no sense here, because created XML uses // only two lines $this->fail( 'Rendered image is not correct.'); } } public function testDrawLine() { $filename = $this->tempDir . __FUNCTION__ . '.svg'; $this->driver->drawLine( new ezcGraphCoordinate( 12, 45 ), new ezcGraphCoordinate( 134, 12 ), ezcGraphColor::fromHex( '#3465A4' ) ); $this->driver->render( $filename ); $this->compare( $filename, $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.svg' ); } public function testDrawPolygonThreePointsFilled() { $filename = $this->tempDir . __FUNCTION__ . '.svg'; $this->driver->drawPolygon( array( new ezcGraphCoordinate( 45, 12 ), new ezcGraphCoordinate( 122, 34 ), new ezcGraphCoordinate( 12, 71 ), ), ezcGraphColor::fromHex( '#3465A4' ), true ); $this->driver->render( $filename ); $this->compare( $filename, $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.svg' ); } public function testDrawPolygonThreePointsNotFilled() { $filename = $this->tempDir . __FUNCTION__ . '.svg'; $this->driver->drawPolygon( array( new ezcGraphCoordinate( 45, 12 ), new ezcGraphCoordinate( 122, 34 ), new ezcGraphCoordinate( 12, 71 ), ), ezcGraphColor::fromHex( '#3465A4' ), false ); $this->driver->render( $filename ); $this->compare( $filename, $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.svg' ); } public function testDrawPolygonFivePoints() { $filename = $this->tempDir . __FUNCTION__ . '.svg'; $this->driver->drawPolygon( array( new ezcGraphCoordinate( 45, 12 ), new ezcGraphCoordinate( 122, 34 ), new ezcGraphCoordinate( 12, 71 ), new ezcGraphCoordinate( 3, 45 ), new ezcGraphCoordinate( 60, 32 ), ), ezcGraphColor::fromHex( '#3465A4' ), true ); $this->driver->render( $filename ); $this->compare( $filename, $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.svg' ); } public function testDrawCircleSectorAcute() { $filename = $this->tempDir . __FUNCTION__ . '.svg'; $this->driver->drawCircleSector( new ezcGraphCoordinate( 100, 50 ), 80, 40, 12.5, 25, ezcGraphColor::fromHex( '#3465A4' ) ); $this->driver->render( $filename ); $this->compare( $filename, $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.svg' ); } public function testDrawCircleSectorAcuteNonFilled() { $filename = $this->tempDir . __FUNCTION__ . '.svg'; $this->driver->drawCircleSector( new ezcGraphCoordinate( 100, 50 ), 80, 40, 12.5, 45, ezcGraphColor::fromHex( '#3465A4' ), false ); $this->driver->render( $filename ); $this->compare( $filename, $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.svg' ); } public function testDrawCircleSectorAcuteReverse() { $filename = $this->tempDir . __FUNCTION__ . '.svg'; $this->driver->drawCircleSector( new ezcGraphCoordinate( 100, 50 ), 80, 40, 25, 12.5, ezcGraphColor::fromHex( '#3465A4' ) ); $this->driver->render( $filename ); $this->compare( $filename, $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.svg' ); } public function testDrawCircleSectorObtuse() { $filename = $this->tempDir . __FUNCTION__ . '.svg'; $this->driver->drawCircleSector( new ezcGraphCoordinate( 100, 50 ), 80, 40, 25, 273, ezcGraphColor::fromHex( '#3465A4' ) ); $this->driver->render( $filename ); $this->compare( $filename, $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.svg' ); } public function testDrawCircularArcAcute() { $filename = $this->tempDir . __FUNCTION__ . '.svg'; $this->driver->drawCircularArc( new ezcGraphCoordinate( 100, 50 ), 150, 80, 10, 12.5, 55, ezcGraphColor::fromHex( '#3465A4' ) ); $this->driver->render( $filename ); $this->compare( $filename, $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.svg' ); } public function testDrawCircularArcAcuteReverse() { $filename = $this->tempDir . __FUNCTION__ . '.svg'; $this->driver->drawCircularArc( new ezcGraphCoordinate( 100, 50 ), 150, 80, 10, 55, 12.5, ezcGraphColor::fromHex( '#3465A4' ) ); $this->driver->render( $filename ); $this->compare( $filename, $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.svg' ); } public function testDrawCircularArcObtuse() { $filename = $this->tempDir . __FUNCTION__ . '.svg'; $this->driver->drawCircularArc( new ezcGraphCoordinate( 100, 50 ), 150, 80, 10, 25, 300, ezcGraphColor::fromHex( '#3465A4' ) ); $this->driver->render( $filename ); $this->compare( $filename, $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.svg' ); } public function testDrawCircleFilled() { $filename = $this->tempDir . __FUNCTION__ . '.svg'; $this->driver->drawCircle( new ezcGraphCoordinate( 100, 50 ), 80, 40, ezcGraphColor::fromHex( '#3465A4' ) ); $this->driver->render( $filename ); $this->compare( $filename, $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.svg' ); } public function testDrawCircleNonFilled() { $filename = $this->tempDir . __FUNCTION__ . '.svg'; $this->driver->drawCircle( new ezcGraphCoordinate( 100, 50 ), 80, 40, ezcGraphColor::fromHex( '#3465A4' ), false ); $this->driver->render( $filename ); $this->compare( $filename, $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.svg' ); } public function testDrawImageJpeg() { $filename = $this->tempDir . __FUNCTION__ . '.svg'; $this->driver->drawImage( $this->basePath . $this->testFiles['jpeg'], new ezcGraphCoordinate( 10, 10 ), 100, 50 ); $this->driver->render( $filename ); $this->compare( $filename, $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.svg' ); } public function testDrawImagePng() { $filename = $this->tempDir . __FUNCTION__ . '.svg'; $this->driver->drawImage( $this->basePath . $this->testFiles['png'], new ezcGraphCoordinate( 10, 10 ), 100, 50 ); $this->driver->render( $filename ); $this->compare( $filename, $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.svg' ); } public function testDrawTextBoxShortString() { $filename = $this->tempDir . __FUNCTION__ . '.svg'; $this->driver->drawPolygon( array( new ezcGraphCoordinate( 10, 10 ), new ezcGraphCoordinate( 160, 10 ), new ezcGraphCoordinate( 160, 80 ), new ezcGraphCoordinate( 10, 80 ), ), ezcGraphColor::fromHex( '#eeeeec' ), true ); $this->driver->drawTextBox( 'Short', new ezcGraphCoordinate( 10, 10 ), 150, 70, ezcGraph::LEFT ); $this->driver->render( $filename ); $this->compare( $filename, $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.svg' ); } public function testDrawTextBoxLongString() { $filename = $this->tempDir . __FUNCTION__ . '.svg'; $this->driver->drawPolygon( array( new ezcGraphCoordinate( 10, 10 ), new ezcGraphCoordinate( 160, 10 ), new ezcGraphCoordinate( 160, 80 ), new ezcGraphCoordinate( 10, 80 ), ), ezcGraphColor::fromHex( '#eeeeec' ), true ); $this->driver->drawTextBox( 'ThisIsAPrettyLongString', new ezcGraphCoordinate( 10, 10 ), 150, 70, ezcGraph::LEFT ); $this->driver->render( $filename ); $this->compare( $filename, $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.svg' ); } public function testDrawTextBoxLongSpacedString() { $filename = $this->tempDir . __FUNCTION__ . '.svg'; $this->driver->drawPolygon( array( new ezcGraphCoordinate( 10, 10 ), new ezcGraphCoordinate( 160, 10 ), new ezcGraphCoordinate( 160, 80 ), new ezcGraphCoordinate( 10, 80 ), ), ezcGraphColor::fromHex( '#eeeeec' ), true ); $this->driver->drawTextBox( 'This Is A Pretty Long String', new ezcGraphCoordinate( 10, 10 ), 150, 70, ezcGraph::LEFT ); $this->driver->render( $filename ); $this->compare( $filename, $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.svg' ); } public function testDrawTextBoxManualBreak() { $filename = $this->tempDir . __FUNCTION__ . '.svg'; $this->driver->drawPolygon( array( new ezcGraphCoordinate( 10, 10 ), new ezcGraphCoordinate( 160, 10 ), new ezcGraphCoordinate( 160, 80 ), new ezcGraphCoordinate( 10, 80 ), ), ezcGraphColor::fromHex( '#eeeeec' ), true ); $this->driver->drawTextBox( "New\nLine", new ezcGraphCoordinate( 10, 10 ), 150, 70, ezcGraph::LEFT ); $this->driver->render( $filename ); $this->compare( $filename, $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.svg' ); } public function testDrawTextBoxStringSampleRight() { $filename = $this->tempDir . __FUNCTION__ . '.svg'; $this->driver->drawPolygon( array( new ezcGraphCoordinate( 20, 20 ), new ezcGraphCoordinate( 110, 20 ), new ezcGraphCoordinate( 110, 30 ), new ezcGraphCoordinate( 20, 30 ), ), ezcGraphColor::fromHex( '#eeeeec' ), true ); $this->driver->drawTextBox( 'sample 4', new ezcGraphCoordinate( 21, 21 ), 88, 8, ezcGraph::RIGHT ); $this->driver->render( $filename ); $this->compare( $filename, $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.svg' ); } public function testDrawTextBoxStringRight() { $filename = $this->tempDir . __FUNCTION__ . '.svg'; $this->driver->drawPolygon( array( new ezcGraphCoordinate( 10, 10 ), new ezcGraphCoordinate( 160, 10 ), new ezcGraphCoordinate( 160, 80 ), new ezcGraphCoordinate( 10, 80 ), ), ezcGraphColor::fromHex( '#eeeeec' ), true ); $this->driver->drawTextBox( 'ThisIsAPrettyLongString', new ezcGraphCoordinate( 10, 10 ), 150, 70, ezcGraph::RIGHT ); $this->driver->render( $filename ); $this->compare( $filename, $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.svg' ); } public function testDrawTextBoxLongSpacedStringRight() { $filename = $this->tempDir . __FUNCTION__ . '.svg'; $this->driver->drawPolygon( array( new ezcGraphCoordinate( 10, 10 ), new ezcGraphCoordinate( 160, 10 ), new ezcGraphCoordinate( 160, 80 ), new ezcGraphCoordinate( 10, 80 ), ), ezcGraphColor::fromHex( '#eeeeec' ), true ); $this->driver->drawTextBox( 'This Is A Pretty Long String', new ezcGraphCoordinate( 10, 10 ), 150, 70, ezcGraph::RIGHT ); $this->driver->render( $filename ); $this->compare( $filename, $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.svg' ); } public function testDrawTextBoxStringCenter() { $filename = $this->tempDir . __FUNCTION__ . '.svg'; $this->driver->drawPolygon( array( new ezcGraphCoordinate( 10, 10 ), new ezcGraphCoordinate( 160, 10 ), new ezcGraphCoordinate( 160, 80 ), new ezcGraphCoordinate( 10, 80 ), ), ezcGraphColor::fromHex( '#eeeeec' ), true ); $this->driver->drawTextBox( 'ThisIsAPrettyLongString', new ezcGraphCoordinate( 10, 10 ), 150, 70, ezcGraph::CENTER ); $this->driver->render( $filename ); $this->compare( $filename, $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.svg' ); } public function testDrawTextBoxLongSpacedStringCenter() { $filename = $this->tempDir . __FUNCTION__ . '.svg'; $this->driver->drawPolygon( array( new ezcGraphCoordinate( 10, 10 ), new ezcGraphCoordinate( 160, 10 ), new ezcGraphCoordinate( 160, 80 ), new ezcGraphCoordinate( 10, 80 ), ), ezcGraphColor::fromHex( '#eeeeec' ), true ); $this->driver->drawTextBox( 'This Is A Pretty Long String', new ezcGraphCoordinate( 10, 10 ), 150, 70, ezcGraph::CENTER ); $this->driver->render( $filename ); $this->compare( $filename, $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.svg' ); } public function testDrawTextBoxStringRightBottom() { $filename = $this->tempDir . __FUNCTION__ . '.svg'; $this->driver->drawPolygon( array( new ezcGraphCoordinate( 10, 10 ), new ezcGraphCoordinate( 160, 10 ), new ezcGraphCoordinate( 160, 80 ), new ezcGraphCoordinate( 10, 80 ), ), ezcGraphColor::fromHex( '#eeeeec' ), true ); $this->driver->drawTextBox( 'ThisIsAPrettyLongString', new ezcGraphCoordinate( 10, 10 ), 150, 70, ezcGraph::RIGHT | ezcGraph::BOTTOM ); $this->driver->render( $filename ); $this->compare( $filename, $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.svg' ); } public function testDrawTextBoxLongSpacedStringRightMiddle() { $filename = $this->tempDir . __FUNCTION__ . '.svg'; $this->driver->drawPolygon( array( new ezcGraphCoordinate( 10, 10 ), new ezcGraphCoordinate( 160, 10 ), new ezcGraphCoordinate( 160, 80 ), new ezcGraphCoordinate( 10, 80 ), ), ezcGraphColor::fromHex( '#eeeeec' ), true ); $this->driver->drawTextBox( 'This Is A Pretty Long String', new ezcGraphCoordinate( 10, 10 ), 150, 70, ezcGraph::RIGHT | ezcGraph::MIDDLE ); $this->driver->render( $filename ); $this->compare( $filename, $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.svg' ); } public function testDrawTextBoxStringCenterMiddle() { $filename = $this->tempDir . __FUNCTION__ . '.svg'; $this->driver->drawPolygon( array( new ezcGraphCoordinate( 10, 10 ), new ezcGraphCoordinate( 160, 10 ), new ezcGraphCoordinate( 160, 80 ), new ezcGraphCoordinate( 10, 80 ), ), ezcGraphColor::fromHex( '#eeeeec' ), true ); $this->driver->drawTextBox( 'ThisIsAPrettyLongString', new ezcGraphCoordinate( 10, 10 ), 150, 70, ezcGraph::CENTER | ezcGraph::MIDDLE ); $this->driver->render( $filename ); $this->compare( $filename, $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.svg' ); } public function testDrawTextBoxLongSpacedStringCenterBottom() { $filename = $this->tempDir . __FUNCTION__ . '.svg'; $this->driver->drawPolygon( array( new ezcGraphCoordinate( 10, 10 ), new ezcGraphCoordinate( 160, 10 ), new ezcGraphCoordinate( 160, 80 ), new ezcGraphCoordinate( 10, 80 ), ), ezcGraphColor::fromHex( '#eeeeec' ), true ); $this->driver->drawTextBox( 'This Is A Pretty Long String', new ezcGraphCoordinate( 10, 10 ), 150, 70, ezcGraph::CENTER | ezcGraph::BOTTOM ); $this->driver->render( $filename ); $this->compare( $filename, $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.svg' ); } public function testDrawStringWithSpecialChars() { $filename = $this->tempDir . __FUNCTION__ . '.svg'; $this->driver->drawPolygon( array( new ezcGraphCoordinate( 47, 54 ), new ezcGraphCoordinate( 47, 84 ), new ezcGraphCoordinate( 99, 84 ), new ezcGraphCoordinate( 99, 54 ), ), ezcGraphColor::fromHex( '#DDDDDD' ), true ); $this->driver->drawTextBox( 'Safari (13.8%)', new ezcGraphCoordinate( 47, 54 ), 52, 30, ezcGraph::LEFT ); $this->driver->render( $filename ); $this->compare( $filename, $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.svg' ); } public function testDrawChartInTemplate() { $filename = $this->tempDir . __FUNCTION__ . '.svg'; $chart = new ezcGraphPieChart(); $chart->data['sample'] = new ezcGraphArrayDataSet( array( 'Mozilla' => 4375, 'IE' => 345, 'Opera' => 1204, 'wget' => 231, 'Safari' => 987, ) ); $chart->driver = new ezcGraphSvgDriver(); $chart->driver->options->templateDocument = dirname( __FILE__ ) . '/data/template.svg'; $chart->renderer = new ezcGraphRenderer3d(); $chart->render( 500, 300, $filename ); $this->compare( $filename, $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.svg' ); } public function testDrawChartInTemplateCustomGroup() { $filename = $this->tempDir . __FUNCTION__ . '.svg'; $chart = new ezcGraphPieChart(); $chart->data['sample'] = new ezcGraphArrayDataSet( array( 'Mozilla' => 4375, 'IE' => 345, 'Opera' => 1204, 'wget' => 231, 'Safari' => 987, ) ); $chart->driver = new ezcGraphSvgDriver(); $chart->driver->options->templateDocument = dirname( __FILE__ ) . '/data/template.svg'; $chart->driver->options->insertIntoGroup = 'graph_root_node'; $chart->driver->options->graphOffset = new ezcGraphCoordinate( 50, 70 ); $chart->renderer = new ezcGraphRenderer3d(); $chart->render( 500, 300, $filename ); $this->compare( $filename, $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.svg' ); } } ?>