|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace PhpMyAdmin\Tests\Controllers\Table; |
| 6 | + |
| 7 | +use PhpMyAdmin\Controllers\Table\GisVisualizationController; |
| 8 | +use PhpMyAdmin\Core; |
| 9 | +use PhpMyAdmin\FieldMetadata; |
| 10 | +use PhpMyAdmin\Template; |
| 11 | +use PhpMyAdmin\Tests\AbstractTestCase; |
| 12 | +use PhpMyAdmin\Tests\Stubs\ResponseRenderer; |
| 13 | +use PhpMyAdmin\Url; |
| 14 | + |
| 15 | +use function array_merge; |
| 16 | + |
| 17 | +use const MYSQLI_TYPE_GEOMETRY; |
| 18 | +use const MYSQLI_TYPE_VAR_STRING; |
| 19 | + |
| 20 | +/** |
| 21 | + * @covers \PhpMyAdmin\Controllers\Table\GisVisualizationController |
| 22 | + */ |
| 23 | +class GisVisualizationControllerTest extends AbstractTestCase |
| 24 | +{ |
| 25 | + public function testGisVisualizationController(): void |
| 26 | + { |
| 27 | + $GLOBALS['server'] = 2; |
| 28 | + $GLOBALS['lang'] = 'en'; |
| 29 | + $GLOBALS['db'] = 'test_db'; |
| 30 | + $GLOBALS['table'] = 'test_table'; |
| 31 | + $_GET['sql_query'] = null; |
| 32 | + $_POST['sql_query'] = 'SELECT * FROM `gis_all`'; |
| 33 | + $_POST['pos'] = 0; |
| 34 | + $_REQUEST['pos'] = 0; |
| 35 | + $_REQUEST['unlim_num_rows'] = null; |
| 36 | + $_SESSION['tmpval'] = []; |
| 37 | + $_SESSION['tmpval']['max_rows'] = 'all'; |
| 38 | + |
| 39 | + $this->dummyDbi->addSelectDb('test_db'); |
| 40 | + $this->dummyDbi->addResult( |
| 41 | + 'SELECT * FROM `gis_all`', |
| 42 | + [['POINT', 'POINT(100 250)']], |
| 43 | + ['name', 'shape'], |
| 44 | + [ |
| 45 | + new FieldMetadata(MYSQLI_TYPE_VAR_STRING, 0, (object) []), |
| 46 | + new FieldMetadata(MYSQLI_TYPE_GEOMETRY, 0, (object) []), |
| 47 | + ] |
| 48 | + ); |
| 49 | + $this->dummyDbi->addResult( |
| 50 | + 'SELECT ST_ASTEXT(`shape`) AS `shape`, ST_SRID(`shape`) AS `srid`' |
| 51 | + . ' FROM (SELECT * FROM `gis_all`) AS `temp_gis` LIMIT 0, 25', |
| 52 | + [['POINT(100 250)', '0']], |
| 53 | + ['shape', 'srid'] |
| 54 | + ); |
| 55 | + |
| 56 | + $params = [ |
| 57 | + 'goto' => 'index.php?route=/database/structure&server=2&lang=en', |
| 58 | + 'back' => 'index.php?route=/sql&server=2&lang=en', |
| 59 | + 'sql_query' => 'SELECT * FROM `gis_all`', |
| 60 | + 'sql_signature' => Core::signSqlQuery('SELECT * FROM `gis_all`'), |
| 61 | + ]; |
| 62 | + $downloadUrl = Url::getFromRoute('/table/gis-visualization', array_merge($params, [ |
| 63 | + 'saveToFile' => true, |
| 64 | + 'session_max_rows' => 25, |
| 65 | + 'pos' => 0, |
| 66 | + 'visualizationSettings[spatialColumn]' => 'shape', |
| 67 | + 'visualizationSettings[labelColumn]' => '', |
| 68 | + ])); |
| 69 | + |
| 70 | + $template = new Template(); |
| 71 | + $expected = $template->render('table/gis_visualization/gis_visualization', [ |
| 72 | + 'url_params' => $params, |
| 73 | + 'download_url' => $downloadUrl, |
| 74 | + 'label_candidates' => ['name'], |
| 75 | + 'spatial_candidates' => ['shape'], |
| 76 | + 'visualization_settings' => [ |
| 77 | + 'spatialColumn' => 'shape', |
| 78 | + 'labelColumn' => '', |
| 79 | + 'width' => '600', |
| 80 | + 'height' => '450', |
| 81 | + ], |
| 82 | + 'start_and_number_of_rows_fieldset' => [ |
| 83 | + 'pos' => 0, |
| 84 | + 'unlim_num_rows' => 0, |
| 85 | + 'rows' => 25, |
| 86 | + 'sql_query' => 'SELECT * FROM `gis_all`', |
| 87 | + ], |
| 88 | + 'visualization' => '<?xml version="1.0" encoding="UTF-8" standalone="no"?>' . "\n" |
| 89 | + . '<svg version="1.1" xmlns:svg="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg"' |
| 90 | + . ' width="600" height="450"><g id="groupPanel"><circle cx="15" cy="240" r="3" name=""' |
| 91 | + . ' id="1234567890" class="point vector" fill="white" stroke="#B02EE0" stroke-width="2"/></g></svg>', |
| 92 | + 'draw_ol' => 'function drawOpenLayers() {if (typeof ol !== "undefined") {var olCss =' |
| 93 | + . ' "js/vendor/openlayers/theme/ol.css";$(\'head\').append(\'<link rel="stylesheet" type="text/css"' |
| 94 | + . ' href=\'+olCss+\'>\');var vectorLayer = new ol.source.Vector({});var map = new ol.Map({target:' |
| 95 | + . ' \'openlayersmap\',layers: [new ol.layer.Tile({source: new ol.source.OSM()}),new ol.layer.' |
| 96 | + . 'Vector({source: vectorLayer})],view: new ol.View({center: ol.proj.fromLonLat([37.41, 8.82]),' |
| 97 | + . 'zoom: 4}),controls: [new ol.control.MousePosition({coordinateFormat: ol.coordinate.' |
| 98 | + . 'createStringXY(4),projection: \'EPSG:4326\'}),new ol.control.Zoom,new ol.control.Attribution' |
| 99 | + . ']});var fill = new ol.style.Fill({"color":"white"});var stroke = new ol.style.Stroke({"color"' |
| 100 | + . ':[176,46,224],"width":2});var style = new ol.style.Style({image: new ol.style.Circle({fill:' |
| 101 | + . ' fill,stroke: stroke,radius: 3}),fill: fill,stroke: stroke});var minLoc = [100, 250];var' |
| 102 | + . ' maxLoc = [100, 250];var ext = ol.extent.boundingExtent([minLoc, maxLoc]);ext = ol.proj.' |
| 103 | + . 'transformExtent(ext, ol.proj.get("EPSG:4326"), ol.proj.get(\'EPSG:3857\'));map.getView().' |
| 104 | + . 'fit(ext, map.getSize());var point = new ol.Feature({geometry: (new ol.geom.Point([100,250]).' |
| 105 | + . 'transform(ol.proj.get("EPSG:4326"), ol.proj.get(\'EPSG:3857\')))});point.setStyle(style);' |
| 106 | + . 'vectorLayer.addFeature(point);return map;}return undefined;}', |
| 107 | + ]); |
| 108 | + |
| 109 | + $response = new ResponseRenderer(); |
| 110 | + (new GisVisualizationController($response, $template, $this->dbi))(); |
| 111 | + $this->assertSame($expected, $response->getHTMLResult()); |
| 112 | + } |
| 113 | +} |
0 commit comments