From de32a92b7126005c8c9ded704444fe14ebbf1d63 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Maur=C3=ADcio=20Meneghini=20Fauth?= Date: Mon, 21 Feb 2022 14:53:32 -0300 Subject: [PATCH] Add more tests for `Display\Results::getTable` method MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: MaurĂ­cio Meneghini Fauth --- test/classes/Display/ResultsTest.php | 223 +++++++++++++++++++++++++++++++++++ 1 file changed, 223 insertions(+) diff --git a/test/classes/Display/ResultsTest.php b/test/classes/Display/ResultsTest.php index 10308de72a..46feae4570 100644 --- a/test/classes/Display/ResultsTest.php +++ b/test/classes/Display/ResultsTest.php @@ -1642,4 +1642,227 @@ class ResultsTest extends AbstractTestCase $this->assertEquals($tableTemplate, $actual); } + + public function testGetTable2(): void + { + global $db, $table; + + $GLOBALS['cfg']['Server']['DisableIS'] = true; + + $db = 'test_db'; + $table = 'test_table'; + $query = 'SELECT COUNT(*) AS `Rows`, `name` FROM `test_table` GROUP BY `name` ORDER BY `name`'; + + $object = new DisplayResults($this->dbi, $db, $table, 1, '', $query); + $object->properties['unique_id'] = 1234567890; + + [$analyzedSqlResults] = ParseAnalyze::sqlQuery($query, $db); + $fieldsMeta = [ + new FieldMetadata( + MYSQLI_TYPE_LONG, + MYSQLI_NUM_FLAG | MYSQLI_NOT_NULL_FLAG, + (object) ['name' => 'Rows'] + ), + new FieldMetadata(MYSQLI_TYPE_STRING, MYSQLI_NOT_NULL_FLAG, (object) ['name' => 'name']), + ]; + + $this->dummyDbi->addResult($query, [['2', 'abcd'], ['1', 'foo']], ['Rows', 'name'], $fieldsMeta); + + $object->setProperties( + 2, + $fieldsMeta, + $analyzedSqlResults['is_count'], + $analyzedSqlResults['is_export'], + $analyzedSqlResults['is_func'], + $analyzedSqlResults['is_analyse'], + 2, + count($fieldsMeta), + 1.234, + 'ltr', + $analyzedSqlResults['is_maint'], + $analyzedSqlResults['is_explain'], + $analyzedSqlResults['is_show'], + null, + null, + true, + true + ); + + $_SESSION = ['tmpval' => [], ' PMA_token ' => 'token']; + $_SESSION['tmpval']['geoOption'] = ''; + $_SESSION['tmpval']['hide_transformation'] = false; + $_SESSION['tmpval']['display_blob'] = ''; + $_SESSION['tmpval']['display_binary'] = ''; + $_SESSION['tmpval']['relational_display'] = ''; + $_SESSION['tmpval']['possible_as_geometry'] = ''; + $_SESSION['tmpval']['pftext'] = ''; + $_SESSION['tmpval']['max_rows'] = 25; + $_SESSION['tmpval']['pos'] = 0; + $_SESSION['tmpval']['repeat_cells'] = 0; + $_SESSION['tmpval']['query']['f2a8e80312ca180031ad773b573adbe1']['max_rows'] = 25; + + $dtResult = $this->dbi->tryQuery($query); + + $displayParts = DisplayParts::fromArray([ + 'hasEditLink' => false, + 'deleteLink' => DisplayParts::NO_DELETE, + 'hasSortLink' => true, + 'hasNavigationBar' => true, + 'hasBookmarkForm' => true, + 'hasTextButton' => false, + 'hasPrintLink' => true, + ]); + + $this->assertNotFalse($dtResult); + $actual = $object->getTable($dtResult, $displayParts, $analyzedSqlResults); + + $template = new Template(); + + $tableHeadersForColumns = $template->render('display/results/table_headers_for_columns', [ + 'is_sortable' => true, + 'columns' => [ + [ + 'column_name' => 'Rows', + 'order_link' => 'Rows' . "\n" + . '', + 'comments' => '', + 'is_browse_pointer_enabled' => true, + 'is_browse_marker_enabled' => true, + 'is_column_hidden' => false, + 'is_column_numeric' => true, + ], + [ + 'column_name' => 'name', + 'order_link' => 'name Ascending Descending 1' . "\n" . '', + 'comments' => '', + 'is_browse_pointer_enabled' => true, + 'is_browse_marker_enabled' => true, + 'is_column_hidden' => false, + 'is_column_numeric' => false, + ], + ], + ]); + + $tableTemplate = $template->render('display/results/table', [ + 'sql_query_message' => Generator::getMessage( + Message::success('Showing rows 0 - 1 (2 total, Query took 1.2340 seconds.)'), + $query, + 'success' + ), + 'navigation' => [ + 'move_backward_buttons' => '', + 'page_selector' => '', + 'move_forward_buttons' => '', + 'number_total_page' => 1, + 'has_show_all' => true, + 'hidden_fields' => [ + 'db' => $db, + 'table' => $table, + 'server' => 1, + 'sql_query' => $query, + 'is_browse_distinct' => true, + 'goto' => '', + ], + 'session_max_rows' => 'all', + 'is_showing_all' => false, + 'max_rows' => 25, + 'pos' => 0, + 'sort_by_key' => [], + ], + 'headers' => [ + 'column_order' => [], + 'options' => '$optionsBlock', + 'has_bulk_actions_form' => false, + 'button' => '' . "\n", + 'table_headers_for_columns' => $tableHeadersForColumns, + 'column_at_right_side' => "\n" . '', + ], + 'body' => '2' . "\n" + . 'abcd' . "\n" + . '' . "\n" + . '1' . "\n" + . 'foo' . "\n" + . '' . "\n", + 'bulk_links' => [], + 'operations' => [ + 'has_procedure' => false, + 'has_geometry' => false, + 'has_print_link' => true, + 'has_export_link' => true, + 'url_params' => [ + 'db' => $db, + 'table' => $table, + 'printview' => '1', + 'sql_query' => $query, + 'single_table' => 'true', + 'unlim_num_rows' => 2, + ], + ], + 'db' => $db, + 'table' => $table, + 'unique_id' => 1234567890, + 'sql_query' => $query, + 'goto' => '', + 'unlim_num_rows' => 2, + 'displaywork' => false, + 'relwork' => false, + 'save_cells_at_once' => false, + 'default_sliders_state' => 'closed', + 'text_dir' => 'ltr', + ]); + + $this->assertEquals($tableTemplate, $actual); + } } -- 2.11.4.GIT