Skip to content

Commit 99b0604

Browse files
committed
Add basic test for Table\StructureController
Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
1 parent 4e5e288 commit 99b0604

2 files changed

Lines changed: 146 additions & 0 deletions

File tree

Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace PhpMyAdmin\Tests\Controllers\Table;
6+
7+
use PhpMyAdmin\Config\PageSettings;
8+
use PhpMyAdmin\ConfigStorage\Relation;
9+
use PhpMyAdmin\ConfigStorage\RelationCleanup;
10+
use PhpMyAdmin\Controllers\Table\StructureController;
11+
use PhpMyAdmin\CreateAddField;
12+
use PhpMyAdmin\FlashMessages;
13+
use PhpMyAdmin\Index;
14+
use PhpMyAdmin\Template;
15+
use PhpMyAdmin\Tests\AbstractTestCase;
16+
use PhpMyAdmin\Tests\Stubs\ResponseRenderer;
17+
use PhpMyAdmin\Transformations;
18+
use PhpMyAdmin\Util;
19+
20+
/**
21+
* @covers \PhpMyAdmin\Controllers\Table\StructureController
22+
*/
23+
class StructureControllerTest extends AbstractTestCase
24+
{
25+
public function testStructureController(): void
26+
{
27+
$GLOBALS['server'] = 2;
28+
$GLOBALS['db'] = 'test_db';
29+
$GLOBALS['table'] = 'test_table';
30+
$GLOBALS['text_dir'] = 'ltr';
31+
$GLOBALS['lang'] = 'en';
32+
$GLOBALS['PMA_PHP_SELF'] = 'index.php';
33+
$GLOBALS['cfg']['Server'] = $GLOBALS['config']->defaultServer;
34+
$GLOBALS['cfg']['Server']['DisableIS'] = true;
35+
$GLOBALS['cfg']['ShowStats'] = false;
36+
$GLOBALS['cfg']['ShowPropertyComments'] = false;
37+
$_GET['route'] = '/table/structure';
38+
$_SESSION['relation'] = [];
39+
40+
$this->dummyDbi->addSelectDb('test_db');
41+
$this->dummyDbi->addSelectDb('test_db');
42+
$this->dummyDbi->addResult(
43+
'SHOW COLLATION',
44+
[
45+
['utf8mb4_general_ci', 'utf8mb4', '45', 'Yes', 'Yes', '1'],
46+
['armscii8_general_ci', 'armscii8', '32', 'Yes', 'Yes', '1'],
47+
['utf8_general_ci', 'utf8', '33', 'Yes', 'Yes', '1'],
48+
['utf8_bin', 'utf8', '83', '', 'Yes', '1'],
49+
['latin1_swedish_ci', 'latin1', '8', 'Yes', 'Yes', '1'],
50+
],
51+
['Collation', 'Charset', 'Id', 'Default', 'Compiled', 'Sortlen']
52+
);
53+
// phpcs:disable Generic.Files.LineLength.TooLong
54+
$this->dummyDbi->addResult(
55+
'SELECT * FROM `information_schema`.`PARTITIONS` WHERE `TABLE_SCHEMA` = \'test_db\' AND `TABLE_NAME` = \'test_table\'',
56+
[
57+
['def', 'test_db', 'test_table', null, null, null, null, null, null, null, null, null, '3', '5461', '16384', null, '0', '0', '2022-02-21 13:34:11', null, null, null, '', '', null],
58+
],
59+
['TABLE_CATALOG', 'TABLE_SCHEMA', 'TABLE_NAME', 'PARTITION_NAME', 'SUBPARTITION_NAME', 'PARTITION_ORDINAL_POSITION', 'SUBPARTITION_ORDINAL_POSITION', 'PARTITION_METHOD', 'SUBPARTITION_METHOD', 'PARTITION_EXPRESSION', 'SUBPARTITION_EXPRESSION', 'PARTITION_DESCRIPTION', 'TABLE_ROWS', 'AVG_ROW_LENGTH', 'DATA_LENGTH', 'MAX_DATA_LENGTH', 'INDEX_LENGTH', 'DATA_FREE', 'CREATE_TIME', 'UPDATE_TIME', 'CHECK_TIME', 'CHECKSUM', 'PARTITION_COMMENT', 'NODEGROUP', 'TABLESPACE_NAME']
60+
);
61+
$this->dummyDbi->addResult(
62+
'SELECT DISTINCT `PARTITION_NAME` FROM `information_schema`.`PARTITIONS` WHERE `TABLE_SCHEMA` = \'test_db\' AND `TABLE_NAME` = \'test_table\'',
63+
[[null]],
64+
['PARTITION_NAME']
65+
);
66+
// phpcs:enable
67+
68+
$pageSettings = new PageSettings('TableStructure');
69+
$fields = $this->dbi->getColumns($GLOBALS['db'], $GLOBALS['table'], true);
70+
71+
$response = new ResponseRenderer();
72+
$relation = new Relation($this->dbi);
73+
$template = new Template();
74+
(new StructureController(
75+
$response,
76+
$template,
77+
$relation,
78+
new Transformations(),
79+
new CreateAddField($this->dbi),
80+
new RelationCleanup($this->dbi, $relation),
81+
$this->dbi,
82+
new FlashMessages()
83+
))();
84+
85+
$expected = $pageSettings->getHTML();
86+
$expected .= $template->render('table/structure/display_structure', [
87+
'collations' => [
88+
'utf8mb4_general_ci' => [
89+
'name' => 'utf8mb4_general_ci',
90+
'description' => 'Unicode (UCA 4.0.0), case-insensitive',
91+
],
92+
],
93+
'is_foreign_key_supported' => true,
94+
'indexes' => Index::getFromTable($GLOBALS['table'], $GLOBALS['db']),
95+
'indexes_duplicates' => Index::findDuplicates($GLOBALS['table'], $GLOBALS['db']),
96+
'relation_parameters' => $relation->getRelationParameters(),
97+
'hide_structure_actions' => true,
98+
'db' => 'test_db',
99+
'table' => 'test_table',
100+
'db_is_system_schema' => false,
101+
'tbl_is_view' => false,
102+
'mime_map' => [],
103+
'tbl_storage_engine' => 'INNODB',
104+
'primary' => Index::getPrimary($GLOBALS['table'], $GLOBALS['db']),
105+
'columns_with_unique_index' => [],
106+
'columns_list' => ['id', 'name', 'datetimefield'],
107+
'table_stats' => null,
108+
'fields' => $fields,
109+
'extracted_columnspecs' => [
110+
1 => Util::extractColumnSpec((string) $fields['id']['Type']),
111+
2 => Util::extractColumnSpec((string) $fields['name']['Type']),
112+
3 => Util::extractColumnSpec((string) $fields['datetimefield']['Type']),
113+
],
114+
'columns_with_index' => [],
115+
'central_list' => [],
116+
'comments_map' => [],
117+
'browse_mime' => true,
118+
'show_column_comments' => true,
119+
'show_stats' => false,
120+
'mysql_int_version' => $this->dbi->getVersion(),
121+
'is_mariadb' => $this->dbi->isMariaDB(),
122+
'text_dir' => 'ltr',
123+
'is_active' => false,
124+
'have_partitioning' => true,
125+
'partitions' => [],
126+
'partition_names' => [0 => null],
127+
'default_sliders_state' => 'closed',
128+
'attributes' => [1 => ' ', 2 => ' ', 3 => ' '],
129+
'displayed_fields' => [
130+
1 => [
131+
'text' => 'id',
132+
'icon' => '<img src="themes/dot.gif" title="Primary" alt="Primary" class="icon ic_b_primary">',
133+
],
134+
2 => ['text' => 'name', 'icon' => ''],
135+
3 => ['text' => 'datetimefield', 'icon' => ''],
136+
],
137+
'row_comments' => [1 => '', 2 => '', 3 => ''],
138+
'route' => '/table/structure',
139+
]);
140+
141+
$this->assertSame($expected, $response->getHTMLResult());
142+
$this->assertAllQueriesConsumed();
143+
}
144+
}

test/classes/Database/CentralColumnsTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414

1515
/**
1616
* @covers \PhpMyAdmin\Database\CentralColumns
17+
* @runTestsInSeparateProcesses
18+
* @preserveGlobalState disabled
1719
*/
1820
class CentralColumnsTest extends AbstractTestCase
1921
{

0 commit comments

Comments
 (0)