diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/classes/Controllers/Normalization/ThirdNormalForm/CreateNewTablesControllerTest.php | 64 | ||||
-rw-r--r-- | test/classes/Controllers/NormalizationControllerTest.php | 39 |
2 files changed, 64 insertions, 39 deletions
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 @@ +<?php + +declare(strict_types=1); + +namespace PhpMyAdmin\Tests\Controllers\Normalization\ThirdNormalForm; + +use PhpMyAdmin\ConfigStorage\Relation; +use PhpMyAdmin\Controllers\Normalization\ThirdNormalForm\CreateNewTablesController; +use PhpMyAdmin\Http\ServerRequest; +use PhpMyAdmin\Normalization; +use PhpMyAdmin\Template; +use PhpMyAdmin\Tests\AbstractTestCase; +use PhpMyAdmin\Tests\Stubs\ResponseRenderer; +use PhpMyAdmin\Transformations; + +use function json_encode; + +/** + * @covers \PhpMyAdmin\Controllers\Normalization\ThirdNormalForm\CreateNewTablesController + */ +class CreateNewTablesControllerTest extends AbstractTestCase +{ + public function testDefault(): void + { + $GLOBALS['db'] = 'test_db'; + $GLOBALS['table'] = 'test_table'; + $_POST['newTables'] = json_encode([ + 'test_table' => [ + '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' => '<h3>The third step of normalization is complete.</h3>', + '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' => '<h3>The third step of normalization is complete.</h3>', - 'queryError' => false, - 'extra' => '', - ], - $this->getResponseJsonResult() - ); - } - public function testNormalization(): void { $GLOBALS['db'] = 'test_db'; |