diff options
author | Maurício Meneghini Fauth <mauricio@fauth.dev> | 2022-08-02 19:47:03 +0300 |
---|---|---|
committer | Maurício Meneghini Fauth <mauricio@fauth.dev> | 2022-08-02 19:47:03 +0300 |
commit | c9bccf3b3d4ea402e0accd5ae2625fe2b107f81a (patch) | |
tree | 4d80ba7b34a2e0d83b71f33b65f578b36bd9336a /test | |
parent | b92e95d062b126c99ebee0369d4a827dc3e0ff1d (diff) |
Extract normalization 2NF create new tables action
Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
Diffstat (limited to 'test')
-rw-r--r-- | test/classes/Controllers/Normalization/SecondNormalForm/CreateNewTablesControllerTest.php | 55 | ||||
-rw-r--r-- | test/classes/Controllers/NormalizationControllerTest.php | 34 |
2 files changed, 55 insertions, 34 deletions
diff --git a/test/classes/Controllers/Normalization/SecondNormalForm/CreateNewTablesControllerTest.php b/test/classes/Controllers/Normalization/SecondNormalForm/CreateNewTablesControllerTest.php new file mode 100644 index 0000000000..e9feec843c --- /dev/null +++ b/test/classes/Controllers/Normalization/SecondNormalForm/CreateNewTablesControllerTest.php @@ -0,0 +1,55 @@ +<?php + +declare(strict_types=1); + +namespace PhpMyAdmin\Tests\Controllers\Normalization\SecondNormalForm; + +use PhpMyAdmin\ConfigStorage\Relation; +use PhpMyAdmin\Controllers\Normalization\SecondNormalForm\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\SecondNormalForm\CreateNewTablesController + */ +class CreateNewTablesControllerTest extends AbstractTestCase +{ + public function testDefault(): void + { + $GLOBALS['db'] = 'test_db'; + $GLOBALS['table'] = 'test_table'; + $_POST['pd'] = json_encode(['ID, task' => [], 'task' => ['timestamp']]); + $_POST['newTablesName'] = json_encode(['ID, task' => 'batch_log2', 'task' => 'table2']); + + $dbiDummy = $this->createDbiDummy(); + $dbiDummy->addSelectDb('test_db'); + $dbiDummy->addResult('CREATE TABLE `batch_log2` SELECT DISTINCT `ID`, `task` FROM `test_table`;', []); + $dbiDummy->addResult('CREATE TABLE `table2` SELECT DISTINCT `task`, `timestamp` FROM `test_table`;', []); + $dbiDummy->addResult('DROP TABLE `test_table`', []); + + $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 second step of normalization is complete for table \'test_table\'.</h3>', + 'queryError' => false, + 'extra' => '', + ], $response->getJSONResult()); + } +} diff --git a/test/classes/Controllers/NormalizationControllerTest.php b/test/classes/Controllers/NormalizationControllerTest.php index 173243b2e3..e608c822dc 100644 --- a/test/classes/Controllers/NormalizationControllerTest.php +++ b/test/classes/Controllers/NormalizationControllerTest.php @@ -46,40 +46,6 @@ class NormalizationControllerTest extends AbstractTestCase $GLOBALS['table'] = 'test_tbl'; } - public function testCreateNewTables2NF(): void - { - $_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'; - $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 second step of normalization is complete for table \'test_tbl\'.</h3>', - 'queryError' => false, - 'extra' => '', - ], - $this->getResponseJsonResult() - ); - } - public function testCreateNewTables3NF(): void { $_POST['createNewTables3NF'] = 1; |