diff options
author | Maurício Meneghini Fauth <mauricio@fauth.dev> | 2022-07-30 06:36:58 +0300 |
---|---|---|
committer | Maurício Meneghini Fauth <mauricio@fauth.dev> | 2022-07-30 06:36:58 +0300 |
commit | dd25695569bc86f66e6be393bf92394229639549 (patch) | |
tree | 33c01835e897b2caace218b8bcd339e76acd2acc /test | |
parent | 51db9db3ddc06e0bfc2909abb7585325885d2e7d (diff) |
Extract normalization 2NF 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/NewTablesControllerTest.php | 48 | ||||
-rw-r--r-- | test/classes/Controllers/NormalizationControllerTest.php | 22 |
2 files changed, 48 insertions, 22 deletions
diff --git a/test/classes/Controllers/Normalization/SecondNormalForm/NewTablesControllerTest.php b/test/classes/Controllers/Normalization/SecondNormalForm/NewTablesControllerTest.php new file mode 100644 index 0000000000..e019257735 --- /dev/null +++ b/test/classes/Controllers/Normalization/SecondNormalForm/NewTablesControllerTest.php @@ -0,0 +1,48 @@ +<?php + +declare(strict_types=1); + +namespace PhpMyAdmin\Tests\Controllers\Normalization\SecondNormalForm; + +use PhpMyAdmin\ConfigStorage\Relation; +use PhpMyAdmin\Controllers\Normalization\SecondNormalForm\NewTablesController; +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\NewTablesController + */ +class NewTablesControllerTest extends AbstractTestCase +{ + public function testDefault(): void + { + $GLOBALS['db'] = 'test_db'; + $GLOBALS['table'] = 'test_table'; + $_POST['pd'] = json_encode(['ID, task' => [], 'task' => ['timestamp']]); + + $dbi = $this->createDatabaseInterface(); + $GLOBALS['dbi'] = $dbi; + $response = new ResponseRenderer(); + $template = new Template(); + + $controller = new NewTablesController( + $response, + $template, + new Normalization($dbi, new Relation($dbi), new Transformations(), $template) + ); + $controller($this->createStub(ServerRequest::class)); + + // phpcs:disable Generic.Files.LineLength.TooLong + $this->assertSame( + '<p><b>In order to put the original table \'test_table\' into Second normal form we need to create the following tables:</b></p><p><input type="text" name="ID, task" value="test_table">( <u>ID, task</u> )<p><input type="text" name="task" value="table2">( <u>task</u>, timestamp )', + $response->getHTMLResult() + ); + // phpcs:enable + } +} diff --git a/test/classes/Controllers/NormalizationControllerTest.php b/test/classes/Controllers/NormalizationControllerTest.php index 31a87b0676..6e8ca6e76d 100644 --- a/test/classes/Controllers/NormalizationControllerTest.php +++ b/test/classes/Controllers/NormalizationControllerTest.php @@ -117,28 +117,6 @@ class NormalizationControllerTest extends AbstractTestCase $this->expectOutputString($data); } - public function testGetNewTables2NF(): void - { - $_POST['getNewTables2NF'] = 1; - $_POST['pd'] = json_encode([ - 'ID, task' => [], - 'task' => ['timestamp'], - ]); - - $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); - $normalizationController($this->createStub(ServerRequest::class)); - $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 { $_POST['createNewTables2NF'] = 1; |