From 81667ad578c52a47071394bb4baba5e51be7ac0d Mon Sep 17 00:00:00 2001 From: Madhura Jayaratne Date: Thu, 11 Aug 2011 21:45:24 +0530 Subject: [PATCH] Unit tests for PMA_GIS_Point class --- test/classes/gis/PMA_GIS_Point_test.php | 179 ++++++++++++++++++++++++ 1 file changed, 179 insertions(+) create mode 100644 test/classes/gis/PMA_GIS_Point_test.php diff --git a/test/classes/gis/PMA_GIS_Point_test.php b/test/classes/gis/PMA_GIS_Point_test.php new file mode 100644 index 0000000000..b6bbd208fc --- /dev/null +++ b/test/classes/gis/PMA_GIS_Point_test.php @@ -0,0 +1,179 @@ +object = PMA_GIS_Point::singleton(); + } + + /** + * Tears down the fixture, for example, closes a network connection. + * This method is called after a test is executed. + * + * @access protected + * @return nothing + */ + protected function tearDown() + { + unset($this->object); + } + + /** + * test generateWkt method + * + * @param array $gis_data array containing the GIS data + * @param int $index index to the array + * @param string $wkt expected Well Known Text + * + * @dataProvider providerForTestGenerateWkt + * @return nothing + */ + public function testGenerateWkt($gis_data, $index, $wkt) + { + $this->assertEquals($this->object->generateWkt($gis_data, $index), $wkt); + } + + /** + * data provider for testGenerateWkt + * + * @return data for testGenerateWkt + */ + public function providerForTestGenerateWkt() + { + return array( + array( + array(0 => array('POINT' => array('x' => 5.02, 'y' => 8.45))), + 0, + 'POINT(5.02 8.45)' + ), + array( + array(0 => array('POINT' => array('x' => 5.02, 'y' => 8.45))), + 1, + 'POINT( )' + ), + array( + array(0 => array('POINT' => array('x' => 5.02))), + 0, + 'POINT(5.02 )' + ), + array( + array(0 => array('POINT' => array('y' => 8.45))), + 0, + 'POINT( 8.45)' + ), + array( + array(0 => array('POINT' => array())), + 0, + 'POINT( )' + ), + ); + } + + /** + * test getShape method + * + * @param array $row_data array of GIS data + * @param string $shape expected shape in WKT + * + * @dataProvider providerForTestGetShape + * @return nothing + */ + public function testGetShape($row_data, $shape) + { + $this->assertEquals($this->object->getShape($row_data), $shape); + } + + /** + * data provider for testGetShape + * + * @return data for testGetShape + */ + public function providerForTestGetShape() + { + return array( + array( + array('x' => 5.02, 'y' => 8.45), + 'POINT(5.02 8.45)' + ) + ); + } + + /** + * test generateParams method + * + * @param string $wkt point in WKT form + * @param array $params expected output array + * @param index $index index + * + * @dataProvider providerForTestGenerateParams + * @return nothing + */ + public function testGenerateParams($wkt, $params, $index) + { + if ($index == 0) { + $this->assertEquals($this->object->generateParams($wkt), $params); + } else { + $this->assertEquals( + $this->object->generateParams($wkt, $index), + $params + ); + } + } + + /** + * data provider for testGenerateParams + * + * @return data for testGenerateParams + */ + public function providerForTestGenerateParams() + { + return array( + array( + "'POINT(5.02 8.45)',124", + array( + 'srid' => '124', + 0 => array( + 'POINT' => array('x' => '5.02', 'y' => '8.45') + ), + ), + 0 + ), + array( + 'POINT(5.02 8.45)', + array( + 2 => array( + 'gis_type' => 'POINT', + 'POINT' => array('x' => '5.02', 'y' => '8.45') + ), + ), + 2 + ) + ); + } +} +?> \ No newline at end of file