PageRenderTime 36ms CodeModel.GetById 9ms RepoModel.GetById 0ms app.codeStats 0ms

/phpmyadmin/test/classes/gis/GISPointTest.php

https://gitlab.com/luyxtran264/myproject
PHP | 362 lines | 217 code | 18 blank | 127 comment | 0 complexity | e2cc92bd3197d87a6ac8fd00659120bd MD5 | raw file
  1. <?php
  2. /* vim: set expandtab sw=4 ts=4 sts=4: */
  3. /**
  4. * Test for PMA\libraries\gis\GISPoint
  5. *
  6. * @package PhpMyAdmin-test
  7. */
  8. use PMA\libraries\gis\GISPoint;
  9. require_once 'GISGeomTest.php';
  10. require_once 'libraries/tcpdf/tcpdf.php';
  11. /**
  12. * Tests for PMA\libraries\gis\GISPoint class.
  13. *
  14. * @package PhpMyAdmin-test
  15. */
  16. class GISPointTest extends GISGeomTest
  17. {
  18. /**
  19. * @var GISPoint
  20. * @access protected
  21. */
  22. protected $object;
  23. /**
  24. * Sets up the fixture, for example, opens a network connection.
  25. * This method is called before a test is executed.
  26. *
  27. * @access protected
  28. * @return void
  29. */
  30. protected function setUp()
  31. {
  32. $this->object = GISPoint::singleton();
  33. }
  34. /**
  35. * Tears down the fixture, for example, closes a network connection.
  36. * This method is called after a test is executed.
  37. *
  38. * @access protected
  39. * @return void
  40. */
  41. protected function tearDown()
  42. {
  43. unset($this->object);
  44. }
  45. /**
  46. * data provider for testGenerateWkt
  47. *
  48. * @return data for testGenerateWkt
  49. */
  50. public function providerForTestGenerateWkt()
  51. {
  52. return array(
  53. array(
  54. array(0 => array('POINT' => array('x' => 5.02, 'y' => 8.45))),
  55. 0,
  56. null,
  57. 'POINT(5.02 8.45)'
  58. ),
  59. array(
  60. array(0 => array('POINT' => array('x' => 5.02, 'y' => 8.45))),
  61. 1,
  62. null,
  63. 'POINT( )'
  64. ),
  65. array(
  66. array(0 => array('POINT' => array('x' => 5.02))),
  67. 0,
  68. null,
  69. 'POINT(5.02 )'
  70. ),
  71. array(
  72. array(0 => array('POINT' => array('y' => 8.45))),
  73. 0,
  74. null,
  75. 'POINT( 8.45)'
  76. ),
  77. array(
  78. array(0 => array('POINT' => array())),
  79. 0,
  80. null,
  81. 'POINT( )'
  82. ),
  83. );
  84. }
  85. /**
  86. * test getShape method
  87. *
  88. * @param array $row_data array of GIS data
  89. * @param string $shape expected shape in WKT
  90. *
  91. * @dataProvider providerForTestGetShape
  92. * @return void
  93. */
  94. public function testGetShape($row_data, $shape)
  95. {
  96. $this->assertEquals($this->object->getShape($row_data), $shape);
  97. }
  98. /**
  99. * data provider for testGetShape
  100. *
  101. * @return data for testGetShape
  102. */
  103. public function providerForTestGetShape()
  104. {
  105. return array(
  106. array(
  107. array('x' => 5.02, 'y' => 8.45),
  108. 'POINT(5.02 8.45)'
  109. )
  110. );
  111. }
  112. /**
  113. * data provider for testGenerateParams
  114. *
  115. * @return data for testGenerateParams
  116. */
  117. public function providerForTestGenerateParams()
  118. {
  119. return array(
  120. array(
  121. "'POINT(5.02 8.45)',124",
  122. null,
  123. array(
  124. 'srid' => '124',
  125. 0 => array(
  126. 'POINT' => array('x' => '5.02', 'y' => '8.45')
  127. ),
  128. )
  129. ),
  130. array(
  131. 'POINT(5.02 8.45)',
  132. 2,
  133. array(
  134. 2 => array(
  135. 'gis_type' => 'POINT',
  136. 'POINT' => array('x' => '5.02', 'y' => '8.45')
  137. ),
  138. )
  139. )
  140. );
  141. }
  142. /**
  143. * data provider for testScaleRow
  144. *
  145. * @return data for testScaleRow
  146. */
  147. public function providerForTestScaleRow()
  148. {
  149. return array(
  150. array(
  151. 'POINT(12 35)',
  152. array(
  153. 'minX' => 12,
  154. 'maxX' => 12,
  155. 'minY' => 35,
  156. 'maxY' => 35,
  157. )
  158. )
  159. );
  160. }
  161. /**
  162. * test case for prepareRowAsPng() method
  163. *
  164. * @param string $spatial GIS POINT object
  165. * @param string $label label for the GIS POINT object
  166. * @param string $point_color color for the GIS POINT object
  167. * @param array $scale_data array containing data related to scaling
  168. * @param object $image image object
  169. *
  170. * @return void
  171. * @dataProvider providerForPrepareRowAsPng
  172. */
  173. public function testPrepareRowAsPng(
  174. $spatial, $label, $point_color, $scale_data, $image
  175. ) {
  176. $return = $this->object->prepareRowAsPng(
  177. $spatial, $label, $point_color, $scale_data, $image
  178. );
  179. $this->assertImage($return);
  180. }
  181. /**
  182. * data provider for testPrepareRowAsPng() test case
  183. *
  184. * @return array test data for testPrepareRowAsPng() test case
  185. */
  186. public function providerForPrepareRowAsPng()
  187. {
  188. return array(
  189. array(
  190. 'POINT(12 35)',
  191. 'image',
  192. '#B02EE0',
  193. array(
  194. 'x' => 12,
  195. 'y' => 69,
  196. 'scale' => 2,
  197. 'height' => 150
  198. ),
  199. imagecreatetruecolor('120', '150')
  200. )
  201. );
  202. }
  203. /**
  204. * test case for prepareRowAsPdf() method
  205. *
  206. * @param string $spatial GIS POINT object
  207. * @param string $label label for the GIS POINT object
  208. * @param string $point_color color for the GIS POINT object
  209. * @param array $scale_data array containing data related to scaling
  210. * @param object $pdf TCPDF instance
  211. *
  212. * @return void
  213. * @dataProvider providerForPrepareRowAsPdf
  214. */
  215. public function testPrepareRowAsPdf(
  216. $spatial, $label, $point_color, $scale_data, $pdf
  217. ) {
  218. $return = $this->object->prepareRowAsPdf(
  219. $spatial, $label, $point_color, $scale_data, $pdf
  220. );
  221. $this->assertInstanceOf('TCPDF', $return);
  222. }
  223. /**
  224. * data provider for prepareRowAsPdf() test case
  225. *
  226. * @return array test data for prepareRowAsPdf() test case
  227. */
  228. public function providerForPrepareRowAsPdf()
  229. {
  230. return array(
  231. array(
  232. 'POINT(12 35)',
  233. 'pdf',
  234. '#B02EE0',
  235. array(
  236. 'x' => 12,
  237. 'y' => 69,
  238. 'scale' => 2,
  239. 'height' => 150
  240. ),
  241. new TCPDF(),
  242. )
  243. );
  244. }
  245. /**
  246. * test case for prepareRowAsSvg() method
  247. *
  248. * @param string $spatial GIS POINT object
  249. * @param string $label label for the GIS POINT object
  250. * @param string $point_color color for the GIS POINT object
  251. * @param array $scale_data array containing data related to scaling
  252. * @param string $output expected output
  253. *
  254. * @return void
  255. * @dataProvider providerForPrepareRowAsSvg
  256. */
  257. public function testPrepareRowAsSvg(
  258. $spatial, $label, $point_color, $scale_data, $output
  259. ) {
  260. $this->assertEquals(
  261. $output,
  262. $this->object->prepareRowAsSvg(
  263. $spatial, $label, $point_color, $scale_data
  264. )
  265. );
  266. }
  267. /**
  268. * data provider for prepareRowAsSvg() test case
  269. *
  270. * @return array test data for prepareRowAsSvg() test case
  271. */
  272. public function providerForPrepareRowAsSvg()
  273. {
  274. return array(
  275. array(
  276. 'POINT(12 35)',
  277. 'svg',
  278. '#B02EE0',
  279. array(
  280. 'x' => 12,
  281. 'y' => 69,
  282. 'scale' => 2,
  283. 'height' => 150
  284. ),
  285. ''
  286. )
  287. );
  288. }
  289. /**
  290. * test case for prepareRowAsOl() method
  291. *
  292. * @param string $spatial GIS POINT object
  293. * @param int $srid spatial reference ID
  294. * @param string $label label for the GIS POINT object
  295. * @param string $point_color color for the GIS POINT object
  296. * @param array $scale_data array containing data related to scaling
  297. * @param string $output expected output
  298. *
  299. * @return void
  300. * @dataProvider providerForPrepareRowAsOl
  301. */
  302. public function testPrepareRowAsOl(
  303. $spatial, $srid, $label, $point_color, $scale_data, $output
  304. ) {
  305. $this->assertEquals(
  306. $output,
  307. $this->object->prepareRowAsOl(
  308. $spatial, $srid, $label, $point_color, $scale_data
  309. )
  310. );
  311. }
  312. /**
  313. * data provider for testPrepareRowAsOl() test case
  314. *
  315. * @return array test data for testPrepareRowAsOl() test case
  316. */
  317. public function providerForPrepareRowAsOl()
  318. {
  319. return array(
  320. array(
  321. 'POINT(12 35)',
  322. 4326,
  323. 'Ol',
  324. '#B02EE0',
  325. array(
  326. 'minX' => '0',
  327. 'minY' => '0',
  328. 'maxX' => '1',
  329. 'maxY' => '1',
  330. ),
  331. 'bound = new OpenLayers.Bounds(); bound.extend(new OpenLayers.'
  332. . 'LonLat(0, 0).transform(new OpenLayers.Projection("EPSG:4326"), '
  333. . 'map.getProjectionObject())); bound.extend(new OpenLayers.LonLat'
  334. . '(1, 1).transform(new OpenLayers.Projection("EPSG:4326"), '
  335. . 'map.getProjectionObject()));vectorLayer.addFeatures(new Open'
  336. . 'Layers.Feature.Vector((new OpenLayers.Geometry.Point(12,35)).'
  337. . 'transform(new OpenLayers.Projection("EPSG:4326"), map.get'
  338. . 'ProjectionObject()), null, {"pointRadius":3,"fillColor":"#ffffff"'
  339. . ',"strokeColor":"#B02EE0","strokeWidth":2,"label":"Ol","labelY'
  340. . 'Offset":-8,"fontSize":10}));'
  341. )
  342. );
  343. }
  344. }