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); $responseRenderer = new ResponseRenderer(); $controller = new GisVisualizationController( $responseRenderer, $template, $dbi, new DbTableExists($dbi), ResponseFactory::create(), $config, ); /** @var list $downloadOptions */ $downloadOptions = (new ReflectionMethod(GisVisualizationController::class, 'getDownloadOptions')) ->invoke($controller); $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' => [ 'geometries' => [['wkt' => 'POINT(100 250)']], 'colors' => [ [176, 46, 224], [224, 100, 46], [224, 214, 46], [46, 151, 224], [188, 224, 46], [224, 46, 117], [92, 224, 46], [224, 176, 46], [0, 34, 224], [114, 108, 177], [72, 26, 54], [186, 198, 88], [18, 114, 36], [130, 81, 25], [35, 140, 116], [76, 72, 155], [135, 201, 191], ], ], 'download_options' => $downloadOptions, ]); $request = ServerRequestFactory::create()->createServerRequest('POST', 'http://example.com/') ->withQueryParams(['db' => 'test_db', 'table' => 'test_table']); $response = $controller($request); self::assertSame(StatusCodeInterface::STATUS_OK, $response->getStatusCode()); self::assertSame($expected, $responseRenderer->getHTMLResult()); $dummyDbi->assertAllSelectsConsumed(); $dummyDbi->assertAllQueriesConsumed(); } }