|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace PhpMyAdmin\Tests\Controllers\Database; |
| 6 | + |
| 7 | +use Fig\Http\Message\StatusCodeInterface; |
| 8 | +use PhpMyAdmin\Config; |
| 9 | +use PhpMyAdmin\ConfigStorage\Relation; |
| 10 | +use PhpMyAdmin\Controllers\Database\DataDictionaryController; |
| 11 | +use PhpMyAdmin\Current; |
| 12 | +use PhpMyAdmin\Http\Factory\ServerRequestFactory; |
| 13 | +use PhpMyAdmin\Tests\AbstractTestCase; |
| 14 | +use PhpMyAdmin\Tests\Stubs\ResponseRenderer; |
| 15 | +use PhpMyAdmin\Transformations; |
| 16 | +use PHPUnit\Framework\Attributes\CoversClass; |
| 17 | + |
| 18 | +#[CoversClass(DataDictionaryController::class)] |
| 19 | +final class DataDictionaryControllerTest extends AbstractTestCase |
| 20 | +{ |
| 21 | + public function testController(): void |
| 22 | + { |
| 23 | + $dbiDummy = $this->createDbiDummy(); |
| 24 | + $dbiDummy->addSelectDb('test_db'); |
| 25 | + $dbiDummy->addResult('SHOW TABLES FROM `test_db`;', [['test_table']], ['Tables_in_test_db']); |
| 26 | + |
| 27 | + // phpcs:disable Generic.Files.LineLength.TooLong |
| 28 | + $dbiDummy->addResult( |
| 29 | + 'SELECT *, `TABLE_SCHEMA` AS `Db`, `TABLE_NAME` AS `Name`, `TABLE_TYPE` AS `TABLE_TYPE`, `ENGINE` AS `Engine`, `ENGINE` AS `Type`, `VERSION` AS `Version`, `ROW_FORMAT` AS `Row_format`, `TABLE_ROWS` AS `Rows`, `AVG_ROW_LENGTH` AS `Avg_row_length`, `DATA_LENGTH` AS `Data_length`, `MAX_DATA_LENGTH` AS `Max_data_length`, `INDEX_LENGTH` AS `Index_length`, `DATA_FREE` AS `Data_free`, `AUTO_INCREMENT` AS `Auto_increment`, `CREATE_TIME` AS `Create_time`, `UPDATE_TIME` AS `Update_time`, `CHECK_TIME` AS `Check_time`, `TABLE_COLLATION` AS `Collation`, `CHECKSUM` AS `Checksum`, `CREATE_OPTIONS` AS `Create_options`, `TABLE_COMMENT` AS `Comment` FROM `information_schema`.`TABLES` t WHERE `TABLE_SCHEMA` COLLATE utf8_bin IN (\'test_db\') AND t.`TABLE_NAME` COLLATE utf8_bin = \'test_table\' ORDER BY Name ASC', |
| 30 | + [['ref', 'test_db', 'test_table', 'BASE TABLE', 'InnoDB', '10', 'Dynamic', '3', '5461', '16384', '0', '49152', '0', '4', '2021-11-07 15:21:00', null, null, 'utf8mb4_general_ci', null, '', '', '0', 'N', 'test_db', 'test_table', 'BASE TABLE', 'InnoDB', 'InnoDB', '10', 'Dynamic', '3', '5461', '16384', '0', '49152', '0', '4', '2021-11-07 15:21:00', null, null, 'utf8mb4_general_ci', null, '', '']], |
| 31 | + ['TABLE_CATALOG', 'TABLE_SCHEMA', 'TABLE_NAME', 'TABLE_TYPE', 'ENGINE', 'VERSION', 'ROW_FORMAT', 'TABLE_ROWS', 'AVG_ROW_LENGTH', 'DATA_LENGTH', 'MAX_DATA_LENGTH', 'INDEX_LENGTH', 'DATA_FREE', 'AUTO_INCREMENT', 'CREATE_TIME', 'UPDATE_TIME', 'CHECK_TIME', 'TABLE_COLLATION', 'CHECKSUM', 'CREATE_OPTIONS', 'TABLE_COMMENT', 'MAX_INDEX_LENGTH', 'TEMPORARY', 'Db', 'Name', 'TABLE_TYPE', 'Engine', 'Type', 'Version', 'Row_format', 'Rows', 'Avg_row_length', 'Data_length', 'Max_data_length', 'Index_length', 'Data_free', 'Auto_increment', 'Create_time', 'Update_time', 'Check_time', 'Collation', 'Checksum', 'Create_options', 'Comment'], |
| 32 | + ); |
| 33 | + // phpcs:enable |
| 34 | + |
| 35 | + $config = new Config(); |
| 36 | + $dbi = $this->createDatabaseInterface($dbiDummy, $config); |
| 37 | + $relation = new Relation($dbi, $config); |
| 38 | + |
| 39 | + Current::$database = 'test_db'; |
| 40 | + $request = ServerRequestFactory::create()->createServerRequest('GET', 'https://example.com/') |
| 41 | + ->withQueryParams(['route' => '/database/data-dictionary', 'db' => 'test_db']); |
| 42 | + |
| 43 | + $response = (new DataDictionaryController( |
| 44 | + new ResponseRenderer(), |
| 45 | + $relation, |
| 46 | + new Transformations($dbi, $relation), |
| 47 | + $dbi, |
| 48 | + ))($request); |
| 49 | + |
| 50 | + $dbiDummy->assertAllSelectsConsumed(); |
| 51 | + $dbiDummy->assertAllQueriesConsumed(); |
| 52 | + self::assertSame(StatusCodeInterface::STATUS_OK, $response->getStatusCode()); |
| 53 | + self::assertStringEqualsFile( |
| 54 | + __DIR__ . '/Fixtures/DataDictionary-testController.html', |
| 55 | + (string) $response->getBody(), |
| 56 | + ); |
| 57 | + } |
| 58 | +} |
0 commit comments