diff options
author | William Desportes <williamdes@wdes.fr> | 2021-04-30 00:18:16 +0300 |
---|---|---|
committer | William Desportes <williamdes@wdes.fr> | 2021-04-30 00:36:05 +0300 |
commit | 2ccf568132713762bd9bed02e34c822bedd15b8c (patch) | |
tree | 6f01aef54d8038c7061be12324a420b66edf5f14 /test/classes | |
parent | f700e56e42419a9b25a63631cdb3c1017d11bb92 (diff) |
Fix #16871 - normalization step 2 errors
Fixes: #16870
Signed-off-by: William Desportes <williamdes@wdes.fr>
Diffstat (limited to 'test/classes')
-rw-r--r-- | test/classes/Controllers/NormalizationControllerTest.php | 55 | ||||
-rw-r--r-- | test/classes/NormalizationTest.php | 16 | ||||
-rw-r--r-- | test/classes/Stubs/DbiDummy.php | 16 |
3 files changed, 79 insertions, 8 deletions
diff --git a/test/classes/Controllers/NormalizationControllerTest.php b/test/classes/Controllers/NormalizationControllerTest.php index 354d13df53..65dd4a90a8 100644 --- a/test/classes/Controllers/NormalizationControllerTest.php +++ b/test/classes/Controllers/NormalizationControllerTest.php @@ -96,6 +96,61 @@ class NormalizationControllerTest extends AbstractTestCase $this->expectOutputString($data); } + public function testGetNewTables2NF(): void + { + global $containerBuilder; + + $_POST['getNewTables2NF'] = 1; + $_POST['pd'] = json_encode([ + 'ID, task' => [], + 'task' => ['timestamp'], + ]); + + $GLOBALS['goto'] = 'index.php?route=/sql'; + $containerBuilder->setParameter('db', $GLOBALS['db']); + $containerBuilder->setParameter('table', $GLOBALS['table']); + /** @var NormalizationController $normalizationController */ + $normalizationController = $containerBuilder->get(NormalizationController::class); + $normalizationController->index(); + $this->expectOutputString( + '<p><b>In order to put the original table \'test_tbl\' into Second normal' + . ' form we need to create the following tables:</b></p><p><input type="text" ' + . 'name="ID, task" value="test_tbl">( <u>ID, task</u> )<p><input type="text" name="task"' + . ' value="table2">( <u>task</u>, timestamp )' + ); + } + + public function testCreateNewTables2NF(): void + { + global $containerBuilder; + + $_POST['createNewTables2NF'] = 1; + $_POST['pd'] = json_encode([ + 'ID, task' => [], + 'task' => ['timestamp'], + ]); + $_POST['newTablesName'] = json_encode([ + 'ID, task' => 'batch_log2', + 'task' => 'table2', + ]); + + $GLOBALS['goto'] = 'index.php?route=/sql'; + $containerBuilder->setParameter('db', $GLOBALS['db']); + $containerBuilder->setParameter('table', $GLOBALS['table']); + /** @var NormalizationController $normalizationController */ + $normalizationController = $containerBuilder->get(NormalizationController::class); + $normalizationController->index(); + $this->assertSame( + $this->getResponseJsonResult(), + [ + 'legendText' => 'End of step', + 'headText' => '<h3>The second step of normalization is complete for table \'test_tbl\'.</h3>', + 'queryError' => false, + 'extra' => '', + ], + ); + } + public function testCreateNewTables3NF(): void { global $containerBuilder; diff --git a/test/classes/NormalizationTest.php b/test/classes/NormalizationTest.php index 47d4f14119..cb979fb948 100644 --- a/test/classes/NormalizationTest.php +++ b/test/classes/NormalizationTest.php @@ -405,16 +405,16 @@ class NormalizationTest extends AbstractTestCase public function testCreateNewTablesFor3NF(): void { $db = 'PMA_db'; - $cols = new stdClass(); - $cols->pk = 'id'; - $cols->nonpk = 'col1, col2'; - $cols1 = new stdClass(); - $cols1->pk = 'col2'; - $cols1->nonpk = 'col3, col4'; $newTables = [ 'PMA_table' => [ - 'PMA_table' => $cols, - 'table1' => $cols1, + 'PMA_table' => [ + 'pk' => 'id', + 'nonpk' => 'col1, col2', + ], + 'table1' => [ + 'pk' => 'col2', + 'nonpk' => 'col3, col4', + ], ], ]; $result = $this->normalization->createNewTablesFor3NF( diff --git a/test/classes/Stubs/DbiDummy.php b/test/classes/Stubs/DbiDummy.php index 3882065624..c27d2db387 100644 --- a/test/classes/Stubs/DbiDummy.php +++ b/test/classes/Stubs/DbiDummy.php @@ -2454,6 +2454,22 @@ class DbiDummy implements DbiExtension 'query' => 'DROP TABLE `test_tbl`', 'result' => [], ], + [ + 'query' => 'CREATE TABLE `batch_log2` SELECT DISTINCT `ID`, `task` FROM `test_tbl`;', + 'result' => [], + ], + [ + 'query' => 'ALTER TABLE `batch_log2` ADD PRIMARY KEY(`ID`, `task`);', + 'result' => [], + ], + [ + 'query' => 'CREATE TABLE `table2` SELECT DISTINCT `task`, `timestamp` FROM `test_tbl`;', + 'result' => [], + ], + [ + 'query' => 'ALTER TABLE `table2` ADD PRIMARY KEY(`task`);', + 'result' => [], + ], ]; /** * Current database. |