Remove `@access` annotations
[phpmyadmin.git] / test / classes / Gis / GisLineStringTest.php
blobfbfa38029f7bfd4356b5796facb0571066337df5
1 <?php
3 declare(strict_types=1);
5 namespace PhpMyAdmin\Tests\Gis;
7 use PhpMyAdmin\Gis\GisLineString;
8 use PhpMyAdmin\Image\ImageWrapper;
9 use TCPDF;
11 use function preg_match;
13 /**
14 * @covers \PhpMyAdmin\Gis\GisLineString
16 class GisLineStringTest extends GisGeomTestCase
18 /** @var GisLineString */
19 protected $object;
21 /**
22 * Sets up the fixture, for example, opens a network connection.
23 * This method is called before a test is executed.
25 protected function setUp(): void
27 parent::setUp();
28 $this->object = GisLineString::singleton();
31 /**
32 * Tears down the fixture, for example, closes a network connection.
33 * This method is called after a test is executed.
35 protected function tearDown(): void
37 parent::tearDown();
38 unset($this->object);
41 /**
42 * data provider for testGenerateWkt
44 * @return array data for testGenerateWkt
46 public function providerForTestGenerateWkt(): array
48 $temp1 = [
49 0 => [
50 'LINESTRING' => [
51 'no_of_points' => 2,
52 0 => [
53 'x' => 5.02,
54 'y' => 8.45,
56 1 => [
57 'x' => 6.14,
58 'y' => 0.15,
64 $temp2 = $temp1;
65 $temp2[0]['LINESTRING']['no_of_points'] = 3;
66 $temp2[0]['LINESTRING'][2] = ['x' => 1.56];
68 $temp3 = $temp2;
69 $temp3[0]['LINESTRING']['no_of_points'] = -1;
71 $temp4 = $temp3;
72 $temp4[0]['LINESTRING']['no_of_points'] = 3;
73 unset($temp4[0]['LINESTRING'][2]['x']);
75 return [
77 $temp1,
79 null,
80 'LINESTRING(5.02 8.45,6.14 0.15)',
82 // if a coordinate is missing, default is empty string
84 $temp2,
86 null,
87 'LINESTRING(5.02 8.45,6.14 0.15,1.56 )',
89 // if no_of_points is not valid, it is considered as 2
91 $temp3,
93 null,
94 'LINESTRING(5.02 8.45,6.14 0.15)',
96 // missing coordinates are replaced with provided values (3rd parameter)
98 $temp4,
100 '0',
101 'LINESTRING(5.02 8.45,6.14 0.15,0 0)',
107 * data provider for testGenerateParams
109 * @return array data for testGenerateParams
111 public function providerForTestGenerateParams(): array
113 $temp = [
114 'LINESTRING' => [
115 'no_of_points' => 2,
116 0 => [
117 'x' => '5.02',
118 'y' => '8.45',
120 1 => [
121 'x' => '6.14',
122 'y' => '0.15',
126 $temp1 = $temp;
127 $temp1['gis_type'] = 'LINESTRING';
129 return [
131 "'LINESTRING(5.02 8.45,6.14 0.15)',124",
132 null,
134 'srid' => '124',
135 0 => $temp,
139 'LINESTRING(5.02 8.45,6.14 0.15)',
141 [2 => $temp1],
147 * data provider for testScaleRow
149 * @return array data for testScaleRow
151 public function providerForTestScaleRow(): array
153 return [
155 'LINESTRING(12 35,48 75,69 23,25 45,14 53,35 78)',
157 'minX' => 12,
158 'maxX' => 69,
159 'minY' => 23,
160 'maxY' => 78,
167 * @requires extension gd
169 public function testPrepareRowAsPng(): void
171 $image = ImageWrapper::create(120, 150);
172 $this->assertNotNull($image);
173 $return = $this->object->prepareRowAsPng(
174 'LINESTRING(12 35,48 75,69 23,25 45,14 53,35 78)',
175 'image',
176 '#B02EE0',
177 ['x' => 12, 'y' => 69, 'scale' => 2, 'height' => 150],
178 $image
180 $this->assertEquals(120, $return->width());
181 $this->assertEquals(150, $return->height());
185 * test case for prepareRowAsPdf() method
187 * @param string $spatial GIS LINESTRING object
188 * @param string $label label for the GIS LINESTRING object
189 * @param string $line_color color for the GIS LINESTRING object
190 * @param array $scale_data array containing data related to scaling
191 * @param TCPDF $pdf TCPDF instance
193 * @dataProvider providerForPrepareRowAsPdf
195 public function testPrepareRowAsPdf(
196 string $spatial,
197 string $label,
198 string $line_color,
199 array $scale_data,
200 TCPDF $pdf
201 ): void {
202 $return = $this->object->prepareRowAsPdf($spatial, $label, $line_color, $scale_data, $pdf);
203 $this->assertInstanceOf(TCPDF::class, $return);
207 * data provider for testPrepareRowAsPdf() test case
209 * @return array test data for testPrepareRowAsPdf() test case
211 public function providerForPrepareRowAsPdf(): array
213 return [
215 'LINESTRING(12 35,48 75,69 23,25 45,14 53,35 78)',
216 'pdf',
217 '#B02EE0',
219 'x' => 12,
220 'y' => 69,
221 'scale' => 2,
222 'height' => 150,
224 new TCPDF(),
230 * test case for prepareRowAsSvg() method
232 * @param string $spatial GIS LINESTRING object
233 * @param string $label label for the GIS LINESTRING object
234 * @param string $lineColor color for the GIS LINESTRING object
235 * @param array $scaleData array containing data related to scaling
236 * @param string $output expected output
238 * @dataProvider providerForPrepareRowAsSvg
240 public function testPrepareRowAsSvg(
241 string $spatial,
242 string $label,
243 string $lineColor,
244 array $scaleData,
245 string $output
246 ): void {
247 $string = $this->object->prepareRowAsSvg($spatial, $label, $lineColor, $scaleData);
248 $this->assertEquals(1, preg_match($output, $string));
252 * data provider for testPrepareRowAsSvg() test case
254 * @return array test data for testPrepareRowAsSvg() test case
256 public function providerForPrepareRowAsSvg(): array
258 return [
260 'LINESTRING(12 35,48 75,69 23,25 45,14 53,35 78)',
261 'svg',
262 '#B02EE0',
264 'x' => 12,
265 'y' => 69,
266 'scale' => 2,
267 'height' => 150,
269 '/^(<polyline points="0,218 72,138 114,242 26,198 4,182 46,132 " '
270 . 'name="svg" id="svg)(\d+)(" class="linestring vector" fill="none" '
271 . 'stroke="#B02EE0" stroke-width="2"\/>)$/',
277 * test case for prepareRowAsOl() method
279 * @param string $spatial GIS LINESTRING object
280 * @param int $srid spatial reference ID
281 * @param string $label label for the GIS LINESTRING object
282 * @param array $line_color color for the GIS LINESTRING object
283 * @param array $scale_data array containing data related to scaling
284 * @param string $output expected output
286 * @dataProvider providerForPrepareRowAsOl
288 public function testPrepareRowAsOl(
289 string $spatial,
290 int $srid,
291 string $label,
292 array $line_color,
293 array $scale_data,
294 string $output
295 ): void {
296 $this->assertEquals(
297 $this->object->prepareRowAsOl(
298 $spatial,
299 $srid,
300 $label,
301 $line_color,
302 $scale_data
304 $output
309 * data provider for testPrepareRowAsOl() test case
311 * @return array test data for testPrepareRowAsOl() test case
313 public function providerForPrepareRowAsOl(): array
315 return [
317 'LINESTRING(12 35,48 75,69 23,25 45,14 53,35 78)',
318 4326,
319 'Ol',
320 [176, 46, 224],
322 'minX' => '0',
323 'minY' => '0',
324 'maxX' => '1',
325 'maxY' => '1',
327 'var style = new ol.style.Style({stroke: new ol.style.Stroke({"color":[176,46,224],'
328 . '"width":2}), text: new ol.style.Text({"text":"Ol"})});var minLoc = [0, 0];var ma'
329 . 'xLoc = [1, 1];var ext = ol.extent.boundingExtent([minLoc, maxLoc]);ext = ol.proj'
330 . '.transformExtent(ext, ol.proj.get("EPSG:4326"), ol.proj.get(\'EPSG:3857\'));map.'
331 . 'getView().fit(ext, map.getSize());var line = new ol.Feature({geometry: new ol.ge'
332 . 'om.LineString(new Array((new ol.geom.Point([12,35]).transform(ol.proj.get("EPSG:'
333 . '4326"), ol.proj.get(\'EPSG:3857\'))).getCoordinates(), (new ol.geom.Point([48,75'
334 . ']).transform(ol.proj.get("EPSG:4326"), ol.proj.get(\'EPSG:3857\'))).getCoordinat'
335 . 'es(), (new ol.geom.Point([69,23]).transform(ol.proj.get("EPSG:4326"), ol.proj.ge'
336 . 't(\'EPSG:3857\'))).getCoordinates(), (new ol.geom.Point([25,45]).transform(ol.pr'
337 . 'oj.get("EPSG:4326"), ol.proj.get(\'EPSG:3857\'))).getCoordinates(), (new ol.geom'
338 . '.Point([14,53]).transform(ol.proj.get("EPSG:4326"), ol.proj.get(\'EPSG:3857\')))'
339 . '.getCoordinates(), (new ol.geom.Point([35,78]).transform(ol.proj.get("EPSG:4326"'
340 . '), ol.proj.get(\'EPSG:3857\'))).getCoordinates()))});line.setStyle(style);vector'
341 . 'Layer.addFeature(line);',