diff options
author | Maurício Meneghini Fauth <mauricio@fauth.dev> | 2022-08-02 21:31:41 +0300 |
---|---|---|
committer | Maurício Meneghini Fauth <mauricio@fauth.dev> | 2022-08-02 21:31:41 +0300 |
commit | a5024edcc5c259fd6d48920e19e0fa4cd7097998 (patch) | |
tree | 63f41f6bcc40881a60bf90412c736251ef140e0b /test | |
parent | 97c5c01a8764eafa2b4016bf3fee63090b084e97 (diff) |
Extract normalization's move repeating group action
Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
Diffstat (limited to 'test')
-rw-r--r-- | test/classes/Controllers/Normalization/MoveRepeatingGroupTest.php | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/test/classes/Controllers/Normalization/MoveRepeatingGroupTest.php b/test/classes/Controllers/Normalization/MoveRepeatingGroupTest.php new file mode 100644 index 0000000000..b7ff21a73a --- /dev/null +++ b/test/classes/Controllers/Normalization/MoveRepeatingGroupTest.php @@ -0,0 +1,53 @@ +<?php + +declare(strict_types=1); + +namespace PhpMyAdmin\Tests\Controllers\Normalization; + +use PhpMyAdmin\ConfigStorage\Relation; +use PhpMyAdmin\Controllers\Normalization\MoveRepeatingGroup; +use PhpMyAdmin\Http\ServerRequest; +use PhpMyAdmin\Message; +use PhpMyAdmin\Normalization; +use PhpMyAdmin\Template; +use PhpMyAdmin\Tests\AbstractTestCase; +use PhpMyAdmin\Tests\Stubs\ResponseRenderer; +use PhpMyAdmin\Transformations; + +/** + * @covers \PhpMyAdmin\Controllers\Normalization\MoveRepeatingGroup + */ +class MoveRepeatingGroupTest extends AbstractTestCase +{ + public function testDefault(): void + { + $GLOBALS['db'] = 'test_db'; + $GLOBALS['table'] = 'test_table'; + $_POST['repeatingColumns'] = 'col1, col2'; + $_POST['newTable'] = 'new_table'; + $_POST['newColumn'] = 'new_column'; + $_POST['primary_columns'] = 'id,col1'; + + // phpcs:disable Generic.Files.LineLength.TooLong + $dbiDummy = $this->createDbiDummy(); + $dbiDummy->addSelectDb('test_db'); + $dbiDummy->addResult('CREATE TABLE `new_table` SELECT `id`,`col1`,`col1` as `new_column` FROM `test_table` UNION SELECT `id`,`col1`,`col2` as `new_column` FROM `test_table`', []); + $dbiDummy->addResult('ALTER TABLE `test_table` DROP `col1`, DROP `col2`', []); + // phpcs:enable + + $dbi = $this->createDatabaseInterface($dbiDummy); + $GLOBALS['dbi'] = $dbi; + $response = new ResponseRenderer(); + $template = new Template(); + + $controller = new MoveRepeatingGroup( + $response, + $template, + new Normalization($dbi, new Relation($dbi), new Transformations(), $template) + ); + $controller($this->createStub(ServerRequest::class)); + + $message = Message::success('Selected repeating group has been moved to the table \'test_table\''); + $this->assertSame(['queryError' => false, 'message' => $message->getDisplay()], $response->getJSONResult()); + } +} |