diff options
author | Maurício Meneghini Fauth <mauricio@fauth.dev> | 2021-09-11 21:20:46 +0300 |
---|---|---|
committer | Maurício Meneghini Fauth <mauricio@fauth.dev> | 2021-09-11 21:20:46 +0300 |
commit | bfaf16f56b0bab26ab994802045cf89fbf945c7d (patch) | |
tree | b09e728f68ef9f63f74e9f998ffdece5e6d41dbb /test | |
parent | 00cb1b366841d88621f6383f1b99638145424b7e (diff) |
Use only callable controllers
Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
Diffstat (limited to 'test')
-rw-r--r-- | test/classes/Controllers/Sql/EnumValuesControllerTest.php | 120 | ||||
-rw-r--r-- | test/classes/Controllers/Sql/SetValuesControllerTest.php | 119 | ||||
-rw-r--r-- | test/classes/Controllers/SqlControllerTest.php | 212 |
3 files changed, 239 insertions, 212 deletions
diff --git a/test/classes/Controllers/Sql/EnumValuesControllerTest.php b/test/classes/Controllers/Sql/EnumValuesControllerTest.php new file mode 100644 index 0000000000..eea7d4fadf --- /dev/null +++ b/test/classes/Controllers/Sql/EnumValuesControllerTest.php @@ -0,0 +1,120 @@ +<?php + +declare(strict_types=1); + +namespace PhpMyAdmin\Tests\Controllers\Sql; + +use PhpMyAdmin\Controllers\Sql\EnumValuesController; +use PhpMyAdmin\Tests\AbstractTestCase; + +/** + * @covers \PhpMyAdmin\Controllers\Sql\EnumValuesController + */ +class EnumValuesControllerTest extends AbstractTestCase +{ + protected function setUp(): void + { + parent::setUp(); + parent::setGlobalDbi(); + parent::loadContainerBuilder(); + parent::loadDbiIntoContainerBuilder(); + parent::loadDefaultConfig(); + $GLOBALS['server'] = 1; + $GLOBALS['text_dir'] = 'ltr'; + $GLOBALS['PMA_PHP_SELF'] = 'index.php'; + parent::loadResponseIntoContainerBuilder(); + } + + public function testGetEnumValuesError(): void + { + global $containerBuilder, $_POST; + + $this->dummyDbi->addResult( + 'SHOW COLUMNS FROM `cvv`.`enums` LIKE \'set\'', + false + ); + + $_POST = [ + 'ajax_request' => true, + 'db' => 'cvv', + 'table' => 'enums', + 'column' => 'set', + 'curr_value' => 'b&c', + ]; + $GLOBALS['db'] = $_POST['db']; + $GLOBALS['table'] = $_POST['table']; + + $containerBuilder->setParameter('db', $GLOBALS['db']); + $containerBuilder->setParameter('table', $GLOBALS['table']); + /** @var EnumValuesController $sqlController */ + $sqlController = $containerBuilder->get(EnumValuesController::class); + $sqlController(); + + $this->assertResponseWasNotSuccessfull(); + + $this->assertSame( + ['message' => 'Error in processing request'], + $this->getResponseJsonResult() + ); + } + + public function testGetEnumValuesSuccess(): void + { + global $containerBuilder, $_POST; + + $this->dummyDbi->addResult( + 'SHOW COLUMNS FROM `cvv`.`enums` LIKE \'set\'', + [ + [ + 'set', + 'set(\'<script>alert("ok")</script>\',\'a&b\',\'b&c\',\'vrai&\',\'\')', + 'No', + '', + 'NULL', + '', + ], + ], + [ + 'Field', + 'Type', + 'Null', + 'Key', + 'Default', + 'Extra', + ] + ); + + $_POST = [ + 'ajax_request' => true, + 'db' => 'cvv', + 'table' => 'enums', + 'column' => 'set', + 'curr_value' => 'b&c', + ]; + $GLOBALS['db'] = $_POST['db']; + $GLOBALS['table'] = $_POST['table']; + + $containerBuilder->setParameter('db', $GLOBALS['db']); + $containerBuilder->setParameter('table', $GLOBALS['table']); + /** @var EnumValuesController $sqlController */ + $sqlController = $containerBuilder->get(EnumValuesController::class); + $sqlController(); + + $this->assertResponseWasSuccessfull(); + + $this->assertSame( + [ + 'dropdown' => '<select>' . "\n" + . ' <option value=""> </option>' . "\n" + . ' <option value="<script>alert("ok")</script>">' + . '<script>alert("ok")</script></option>' . "\n" + . ' <option value="a&b">a&b</option>' . "\n" + . ' <option value="b&c" selected>b&c</option>' . "\n" + . ' <option value="vrai&amp">vrai&amp</option>' . "\n" + . ' <option value=""></option>' . "\n" + . ' </select>' . "\n", + ], + $this->getResponseJsonResult() + ); + } +} diff --git a/test/classes/Controllers/Sql/SetValuesControllerTest.php b/test/classes/Controllers/Sql/SetValuesControllerTest.php new file mode 100644 index 0000000000..7a908d29dc --- /dev/null +++ b/test/classes/Controllers/Sql/SetValuesControllerTest.php @@ -0,0 +1,119 @@ +<?php + +declare(strict_types=1); + +namespace PhpMyAdmin\Tests\Controllers\Sql; + +use PhpMyAdmin\Controllers\Sql\SetValuesController; +use PhpMyAdmin\Tests\AbstractTestCase; + +/** + * @covers \PhpMyAdmin\Controllers\Sql\SetValuesController + */ +class SetValuesControllerTest extends AbstractTestCase +{ + protected function setUp(): void + { + parent::setUp(); + parent::setGlobalDbi(); + parent::loadContainerBuilder(); + parent::loadDbiIntoContainerBuilder(); + parent::loadDefaultConfig(); + $GLOBALS['server'] = 1; + $GLOBALS['text_dir'] = 'ltr'; + $GLOBALS['PMA_PHP_SELF'] = 'index.php'; + parent::loadResponseIntoContainerBuilder(); + } + + public function testError(): void + { + global $containerBuilder, $_POST; + + $this->dummyDbi->addResult( + 'SHOW COLUMNS FROM `cvv`.`enums` LIKE \'set\'', + false + ); + + $_POST = [ + 'ajax_request' => true, + 'db' => 'cvv', + 'table' => 'enums', + 'column' => 'set', + 'curr_value' => 'b&c', + ]; + $GLOBALS['db'] = $_POST['db']; + $GLOBALS['table'] = $_POST['table']; + + $containerBuilder->setParameter('db', $GLOBALS['db']); + $containerBuilder->setParameter('table', $GLOBALS['table']); + /** @var SetValuesController $sqlController */ + $sqlController = $containerBuilder->get(SetValuesController::class); + $sqlController(); + + $this->assertResponseWasNotSuccessfull(); + + $this->assertSame( + ['message' => 'Error in processing request'], + $this->getResponseJsonResult() + ); + } + + public function testSuccess(): void + { + global $containerBuilder, $_POST; + + $this->dummyDbi->addResult( + 'SHOW COLUMNS FROM `cvv`.`enums` LIKE \'set\'', + [ + [ + 'set', + 'set(\'<script>alert("ok")</script>\',\'a&b\',\'b&c\',\'vrai&\',\'\')', + 'No', + '', + 'NULL', + '', + ], + ], + [ + 'Field', + 'Type', + 'Null', + 'Key', + 'Default', + 'Extra', + ] + ); + + $_POST = [ + 'ajax_request' => true, + 'db' => 'cvv', + 'table' => 'enums', + 'column' => 'set', + 'curr_value' => 'b&c', + ]; + $GLOBALS['db'] = $_POST['db']; + $GLOBALS['table'] = $_POST['table']; + + $containerBuilder->setParameter('db', $GLOBALS['db']); + $containerBuilder->setParameter('table', $GLOBALS['table']); + /** @var SetValuesController $sqlController */ + $sqlController = $containerBuilder->get(SetValuesController::class); + $sqlController(); + + $this->assertResponseWasSuccessfull(); + + $this->assertSame( + [ + 'select' => '<select class="resize-vertical" size="5" multiple>' . "\n" + . ' <option value="<script>alert("ok")</script>">' + . '<script>alert("ok")</script></option>' . "\n" + . ' <option value="a&b">a&b</option>' . "\n" + . ' <option value="b&c" selected>b&c</option>' . "\n" + . ' <option value="vrai&amp">vrai&amp</option>' . "\n" + . ' <option value=""></option>' . "\n" + . ' </select>' . "\n", + ], + $this->getResponseJsonResult() + ); + } +} diff --git a/test/classes/Controllers/SqlControllerTest.php b/test/classes/Controllers/SqlControllerTest.php deleted file mode 100644 index 10d9d2c032..0000000000 --- a/test/classes/Controllers/SqlControllerTest.php +++ /dev/null @@ -1,212 +0,0 @@ -<?php - -declare(strict_types=1); - -namespace PhpMyAdmin\Tests\Controllers; - -use PhpMyAdmin\Controllers\SqlController; -use PhpMyAdmin\Tests\AbstractTestCase; - -/** - * @covers \PhpMyAdmin\Controllers\SqlController - */ -class SqlControllerTest extends AbstractTestCase -{ - protected function setUp(): void - { - parent::setUp(); - parent::setGlobalDbi(); - parent::loadContainerBuilder(); - parent::loadDbiIntoContainerBuilder(); - parent::loadDefaultConfig(); - $GLOBALS['server'] = 1; - $GLOBALS['text_dir'] = 'ltr'; - $GLOBALS['PMA_PHP_SELF'] = 'index.php'; - parent::loadResponseIntoContainerBuilder(); - } - - public function testGetSetValuesError(): void - { - global $containerBuilder, $_POST; - - $this->dummyDbi->addResult( - 'SHOW COLUMNS FROM `cvv`.`enums` LIKE \'set\'', - false - ); - - $_POST = [ - 'ajax_request' => true, - 'db' => 'cvv', - 'table' => 'enums', - 'column' => 'set', - 'curr_value' => 'b&c', - ]; - $GLOBALS['db'] = $_POST['db']; - $GLOBALS['table'] = $_POST['table']; - - $containerBuilder->setParameter('db', $GLOBALS['db']); - $containerBuilder->setParameter('table', $GLOBALS['table']); - /** @var SqlController $sqlController */ - $sqlController = $containerBuilder->get(SqlController::class); - $sqlController->getSetValues(); - - $this->assertResponseWasNotSuccessfull(); - - $this->assertSame( - ['message' => 'Error in processing request'], - $this->getResponseJsonResult() - ); - } - - public function testGetSetValuesSuccess(): void - { - global $containerBuilder, $_POST; - - $this->dummyDbi->addResult( - 'SHOW COLUMNS FROM `cvv`.`enums` LIKE \'set\'', - [ - [ - 'set', - 'set(\'<script>alert("ok")</script>\',\'a&b\',\'b&c\',\'vrai&\',\'\')', - 'No', - '', - 'NULL', - '', - ], - ], - [ - 'Field', - 'Type', - 'Null', - 'Key', - 'Default', - 'Extra', - ] - ); - - $_POST = [ - 'ajax_request' => true, - 'db' => 'cvv', - 'table' => 'enums', - 'column' => 'set', - 'curr_value' => 'b&c', - ]; - $GLOBALS['db'] = $_POST['db']; - $GLOBALS['table'] = $_POST['table']; - - $containerBuilder->setParameter('db', $GLOBALS['db']); - $containerBuilder->setParameter('table', $GLOBALS['table']); - /** @var SqlController $sqlController */ - $sqlController = $containerBuilder->get(SqlController::class); - $sqlController->getSetValues(); - - $this->assertResponseWasSuccessfull(); - - $this->assertSame( - [ - 'select' => '<select class="resize-vertical" size="5" multiple>' . "\n" - . ' <option value="<script>alert("ok")</script>">' - . '<script>alert("ok")</script></option>' . "\n" - . ' <option value="a&b">a&b</option>' . "\n" - . ' <option value="b&c" selected>b&c</option>' . "\n" - . ' <option value="vrai&amp">vrai&amp</option>' . "\n" - . ' <option value=""></option>' . "\n" - . ' </select>' . "\n", - ], - $this->getResponseJsonResult() - ); - } - - public function testGetEnumValuesError(): void - { - global $containerBuilder, $_POST; - - $this->dummyDbi->addResult( - 'SHOW COLUMNS FROM `cvv`.`enums` LIKE \'set\'', - false - ); - - $_POST = [ - 'ajax_request' => true, - 'db' => 'cvv', - 'table' => 'enums', - 'column' => 'set', - 'curr_value' => 'b&c', - ]; - $GLOBALS['db'] = $_POST['db']; - $GLOBALS['table'] = $_POST['table']; - - $containerBuilder->setParameter('db', $GLOBALS['db']); - $containerBuilder->setParameter('table', $GLOBALS['table']); - /** @var SqlController $sqlController */ - $sqlController = $containerBuilder->get(SqlController::class); - $sqlController->getEnumValues(); - - $this->assertResponseWasNotSuccessfull(); - - $this->assertSame( - ['message' => 'Error in processing request'], - $this->getResponseJsonResult() - ); - } - - public function testGetEnumValuesSuccess(): void - { - global $containerBuilder, $_POST; - - $this->dummyDbi->addResult( - 'SHOW COLUMNS FROM `cvv`.`enums` LIKE \'set\'', - [ - [ - 'set', - 'set(\'<script>alert("ok")</script>\',\'a&b\',\'b&c\',\'vrai&\',\'\')', - 'No', - '', - 'NULL', - '', - ], - ], - [ - 'Field', - 'Type', - 'Null', - 'Key', - 'Default', - 'Extra', - ] - ); - - $_POST = [ - 'ajax_request' => true, - 'db' => 'cvv', - 'table' => 'enums', - 'column' => 'set', - 'curr_value' => 'b&c', - ]; - $GLOBALS['db'] = $_POST['db']; - $GLOBALS['table'] = $_POST['table']; - - $containerBuilder->setParameter('db', $GLOBALS['db']); - $containerBuilder->setParameter('table', $GLOBALS['table']); - /** @var SqlController $sqlController */ - $sqlController = $containerBuilder->get(SqlController::class); - $sqlController->getEnumValues(); - - $this->assertResponseWasSuccessfull(); - - $this->assertSame( - [ - 'dropdown' => '<select>' . "\n" - . ' <option value=""> </option>' . "\n" - . ' <option value="<script>alert("ok")</script>">' - . '<script>alert("ok")</script></option>' . "\n" - . ' <option value="a&b">a&b</option>' . "\n" - . ' <option value="b&c" selected>b&c</option>' . "\n" - . ' <option value="vrai&amp">vrai&amp</option>' . "\n" - . ' <option value=""></option>' . "\n" - . ' </select>' . "\n", - ], - $this->getResponseJsonResult() - ); - } -} |