Unit tests for PMA_GIS_Polygon class
[phpmyadmin/crack.git] / test / classes / gis / PMA_GIS_Polygon_test.php
blobd02fc659ad92539b8328c7a5323dcf3d39503efc
1 <?php
2 /**
3 * Test for PMA_GIS_Polygon
5 * @package phpMyAdmin-test
6 */
8 require_once 'libraries/gis/pma_gis_geometry.php';
9 require_once 'libraries/gis/pma_gis_polygon.php';
11 /**
12 * Tests for PMA_GIS_Polygon class
14 class PMA_GIS_PolygonTest extends PHPUnit_Framework_TestCase
16 /**
17 * @var PMA_GIS_Polygon
18 * @access protected
20 protected $object;
22 /**
23 * Sets up the fixture, for example, opens a network connection.
24 * This method is called before a test is executed.
26 * @access protected
27 * @return nothing
29 protected function setUp()
31 $this->object = PMA_GIS_Polygon::singleton();
34 /**
35 * Tears down the fixture, for example, closes a network connection.
36 * This method is called after a test is executed.
38 * @access protected
39 * @return nothing
41 protected function tearDown()
43 unset($this->object);
46 private function _getData()
48 return array(
49 'POLYGON' => array(
50 'no_of_lines' => 2,
51 0 => array(
52 'no_of_points' => 5,
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),
59 1 => array(
60 'no_of_points' => 4,
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),
70 /**
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
78 * @return nothing
79 * @dataProvider providerForTestGenerateWkt
81 public function testGenerateWkt($gis_data, $index, $empty, $wkt)
83 if ($empty == null) {
84 $this->assertEquals($this->object->generateWkt($gis_data, $index), $wkt);
85 } else {
86 $this->assertEquals(
87 $this->object->generateWkt($gis_data, $index, $empty),
88 $wkt
93 /**
94 * data provider for testGenerateWkt
96 * @return data for testGenerateWkt
98 public function providerForTestGenerateWkt()
100 $temp = array(
101 0 => $this->_getData()
104 $temp1 = $temp;
105 unset($temp1[0]['POLYGON'][1][3]['y']);
107 return array(
108 array(
109 $temp,
111 null,
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
115 array(
116 $temp,
118 null,
119 'POLYGON(( , , , ))'
121 // if a coordinate is missing, default is empty string
122 array(
123 $temp1,
125 null,
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)
129 array(
130 $temp1,
132 '0',
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
146 * @return nothing
148 public function testGenerateParams($wkt, $index, $params)
150 if ($index == null) {
151 $this->assertEquals($this->object->generateParams($wkt), $params);
152 } else {
153 $this->assertEquals(
154 $this->object->generateParams($wkt, $index),
155 $params
161 * data provider for testGenerateParams
163 * @return data for testGenerateParams
165 public function providerForTestGenerateParams()
167 $temp = $this->_getData();
169 $temp1 = $temp;
170 $temp1['gis_type'] = 'POLYGON';
172 return array(
173 array(
174 "'POLYGON((35 10,10 20,15 40,45 45,35 10),(20 30,35 32,30 20,20 30))',124",
175 null,
176 array(
177 'srid' => '124',
178 0 => $temp
181 array(
182 'POLYGON((35 10,10 20,15 40,45 45,35 10),(20 30,35 32,30 20,20 30))',
184 array(
185 2 => $temp1