3 * Test for PMA_GIS_Polygon
5 * @package phpMyAdmin-test
8 require_once 'libraries/gis/pma_gis_geometry.php';
9 require_once 'libraries/gis/pma_gis_polygon.php';
12 * Tests for PMA_GIS_Polygon class
14 class PMA_GIS_PolygonTest
extends PHPUnit_Framework_TestCase
17 * @var PMA_GIS_Polygon
23 * Sets up the fixture, for example, opens a network connection.
24 * This method is called before a test is executed.
29 protected function setUp()
31 $this->object = PMA_GIS_Polygon
::singleton();
35 * Tears down the fixture, for example, closes a network connection.
36 * This method is called after a test is executed.
41 protected function tearDown()
46 private function _getData()
53 0 => array('x' => 35, 'y' => 10),
54 1 => array('x' => 10, 'y' => 20),
55 2 => array('x' => 15, 'y' => 40),
56 3 => array('x' => 45, 'y' => 45),
57 4 => array('x' => 35, 'y' => 10),
61 0 => array('x' => 20, 'y' => 30),
62 1 => array('x' => 35, 'y' => 32),
63 2 => array('x' => 30, 'y' => 20),
64 3 => array('x' => 20, 'y' => 30),
71 * test generateWkt method
73 * @param array $gis_data array of GIS data
74 * @param int $index index
75 * @param string $empty string to be insterted in place of missing values
76 * @param string $wkt expected WKT
79 * @dataProvider providerForTestGenerateWkt
81 public function testGenerateWkt($gis_data, $index, $empty, $wkt)
84 $this->assertEquals($this->object->generateWkt($gis_data, $index), $wkt);
87 $this->object->generateWkt($gis_data, $index, $empty),
94 * data provider for testGenerateWkt
96 * @return data for testGenerateWkt
98 public function providerForTestGenerateWkt()
101 0 => $this->_getData()
105 unset($temp1[0]['POLYGON'][1][3]['y']);
112 'POLYGON((35 10,10 20,15 40,45 45,35 10),(20 30,35 32,30 20,20 30))'
114 // values at undefined index
121 // if a coordinate is missing, default is empty string
126 'POLYGON((35 10,10 20,15 40,45 45,35 10),(20 30,35 32,30 20,20 ))'
128 // missing coordinates are replaced with provided values (3rd parameter)
133 'POLYGON((35 10,10 20,15 40,45 45,35 10),(20 30,35 32,30 20,20 0))'
139 * test generateParams method
141 * @param string $wkt point in WKT form
142 * @param index $index index
143 * @param array $params expected output array
145 * @dataProvider providerForTestGenerateParams
148 public function testGenerateParams($wkt, $index, $params)
150 if ($index == null) {
151 $this->assertEquals($this->object->generateParams($wkt), $params);
154 $this->object->generateParams($wkt, $index),
161 * data provider for testGenerateParams
163 * @return data for testGenerateParams
165 public function providerForTestGenerateParams()
167 $temp = $this->_getData();
170 $temp1['gis_type'] = 'POLYGON';
174 "'POLYGON((35 10,10 20,15 40,45 45,35 10),(20 30,35 32,30 20,20 30))',124",
182 'POLYGON((35 10,10 20,15 40,45 45,35 10),(20 30,35 32,30 20,20 30))',