From 97c5c01a8764eafa2b4016bf3fee63090b084e97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maur=C3=ADcio=20Meneghini=20Fauth?= Date: Tue, 2 Aug 2022 14:43:13 -0300 Subject: Extract normalization 3NF create new tables action MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: MaurĂ­cio Meneghini Fauth --- .../CreateNewTablesControllerTest.php | 64 ++++++++++++++++++++++ .../Controllers/NormalizationControllerTest.php | 39 ------------- 2 files changed, 64 insertions(+), 39 deletions(-) create mode 100644 test/classes/Controllers/Normalization/ThirdNormalForm/CreateNewTablesControllerTest.php (limited to 'test') diff --git a/test/classes/Controllers/Normalization/ThirdNormalForm/CreateNewTablesControllerTest.php b/test/classes/Controllers/Normalization/ThirdNormalForm/CreateNewTablesControllerTest.php new file mode 100644 index 0000000000..a6980ce7ee --- /dev/null +++ b/test/classes/Controllers/Normalization/ThirdNormalForm/CreateNewTablesControllerTest.php @@ -0,0 +1,64 @@ + [ + 'event' => [ + 'pk' => 'eventID', + 'nonpk' => 'Start_time, DateOfEvent, NumberOfGuests, NameOfVenue, LocationOfVenue', + ], + 'table2' => ['pk' => 'Start_time', 'nonpk' => 'TypeOfEvent, period'], + ], + ]); + + // phpcs:disable Generic.Files.LineLength.TooLong + $dbiDummy = $this->createDbiDummy(); + $dbiDummy->addSelectDb('test_db'); + $dbiDummy->addResult('CREATE TABLE `event` SELECT DISTINCT `eventID`, `Start_time`, `DateOfEvent`, `NumberOfGuests`, `NameOfVenue`, `LocationOfVenue` FROM `test_table`;', []); + $dbiDummy->addResult('CREATE TABLE `table2` SELECT DISTINCT `Start_time`, `TypeOfEvent`, `period` FROM `test_table`;', []); + $dbiDummy->addResult('DROP TABLE `test_table`', []); + // phpcs:enable + + $dbi = $this->createDatabaseInterface($dbiDummy); + $GLOBALS['dbi'] = $dbi; + $response = new ResponseRenderer(); + $template = new Template(); + + $controller = new CreateNewTablesController( + $response, + $template, + new Normalization($dbi, new Relation($dbi), new Transformations(), $template) + ); + $controller($this->createStub(ServerRequest::class)); + + $this->assertSame([ + 'legendText' => 'End of step', + 'headText' => '

The third step of normalization is complete.

', + 'queryError' => false, + 'extra' => '', + ], $response->getJSONResult()); + } +} diff --git a/test/classes/Controllers/NormalizationControllerTest.php b/test/classes/Controllers/NormalizationControllerTest.php index e608c822dc..e884b255f7 100644 --- a/test/classes/Controllers/NormalizationControllerTest.php +++ b/test/classes/Controllers/NormalizationControllerTest.php @@ -16,7 +16,6 @@ use PhpMyAdmin\Tests\Stubs\ResponseRenderer; use PhpMyAdmin\Transformations; use function in_array; -use function json_encode; /** * @covers \PhpMyAdmin\Controllers\NormalizationController @@ -46,44 +45,6 @@ class NormalizationControllerTest extends AbstractTestCase $GLOBALS['table'] = 'test_tbl'; } - public function testCreateNewTables3NF(): void - { - $_POST['createNewTables3NF'] = 1; - $_POST['newTables'] = json_encode([ - 'test_tbl' => [ - 'event' => [ - 'pk' => 'eventID', - 'nonpk' => 'Start_time, DateOfEvent, NumberOfGuests, NameOfVenue, LocationOfVenue', - ], - 'table2' => [ - 'pk' => 'Start_time', - 'nonpk' => 'TypeOfEvent, period', - ], - ], - ]); - - $GLOBALS['goto'] = 'index.php?route=/sql'; - $GLOBALS['containerBuilder']->setParameter('db', $GLOBALS['db']); - $GLOBALS['containerBuilder']->setParameter('table', $GLOBALS['table']); - /** @var NormalizationController $normalizationController */ - $normalizationController = $GLOBALS['containerBuilder']->get(NormalizationController::class); - $this->dummyDbi->addSelectDb('my_db'); - $normalizationController($this->createStub(ServerRequest::class)); - $this->dummyDbi->assertAllSelectsConsumed(); - - $this->assertResponseWasSuccessfull(); - - $this->assertSame( - [ - 'legendText' => 'End of step', - 'headText' => '

The third step of normalization is complete.

', - 'queryError' => false, - 'extra' => '', - ], - $this->getResponseJsonResult() - ); - } - public function testNormalization(): void { $GLOBALS['db'] = 'test_db'; -- cgit v1.2.3