createDbiDummy(); $dummyDbi->addSelectDb('test_db'); $dummyDbi->addResult( 'SELECT * FROM `gis_all` LIMIT 0, 0', [['POINT', 'POINT(100 250)']], ['name', 'shape'], [ FieldHelper::fromArray(['type' => MYSQLI_TYPE_VAR_STRING]), FieldHelper::fromArray(['type' => MYSQLI_TYPE_GEOMETRY]), ], ); $dummyDbi->addResult( 'SELECT ST_ASTEXT(`shape`) AS `shape`, ST_SRID(`shape`) AS `srid`' . ' FROM (SELECT * FROM `gis_all`) AS `temp_gis` LIMIT 25', [['POINT(100 250)', '0']], ['shape', 'srid'], ); $dbi = $this->createDatabaseInterface($dummyDbi); DatabaseInterface::$instance = $dbi; $params = [ 'goto' => 'index.php?route=/database/structure&server=2&lang=en', 'back' => 'index.php?route=/sql&server=2&lang=en', 'sql_query' => 'SELECT * FROM `gis_all`', 'sql_signature' => Core::signSqlQuery('SELECT * FROM `gis_all`'), ]; $downloadParams = [ 'saveToFile' => true, 'session_max_rows' => 25, 'pos' => 0, 'visualizationSettings[spatialColumn]' => 'shape', 'visualizationSettings[labelColumn]' => null, ]; $downloadUrl = Url::getFromRoute('/table/gis-visualization', $downloadParams + $params); $config = new Config(); $template = new Template($config); $expected = $template->render('table/gis_visualization/gis_visualization', [ 'url_params' => $params, 'download_url' => $downloadUrl, 'label_candidates' => ['name'], 'spatial_candidates' => ['shape'], 'spatialColumn' => 'shape', 'labelColumn' => null, 'width' => 600, 'height' => 450, 'start_and_number_of_rows_fieldset' => [ 'pos' => 0, 'unlim_num_rows' => 0, 'rows' => 25, 'sql_query' => 'SELECT * FROM `gis_all`', ], 'visualization' => '' . "\n" . '', 'open_layers_data' => [ [ 'geometry' => ['type' => 'Point', 'coordinates' => [100.0, 250.0], 'srid' => 0], 'style' => [ 'circle' => [ 'fill' => ['color' => 'white'], 'stroke' => ['color' => [176, 46, 224], 'width' => 2], 'radius' => 3, ], ], ], ], ]); $request = ServerRequestFactory::create()->createServerRequest('POST', 'http://example.com/') ->withQueryParams(['db' => 'test_db', 'table' => 'test_table']); $responseRenderer = new ResponseRenderer(); $controller = new GisVisualizationController( $responseRenderer, $template, $dbi, new DbTableExists($dbi), ResponseFactory::create(), $config, ); $response = $controller($request); self::assertSame(StatusCodeInterface::STATUS_OK, $response->getStatusCode()); self::assertSame($expected, $responseRenderer->getHTMLResult()); $dummyDbi->assertAllSelectsConsumed(); $dummyDbi->assertAllQueriesConsumed(); } }