Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/phpmyadmin/phpmyadmin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorMaurício Meneghini Fauth <mauricio@fauth.dev>2021-09-11 21:20:46 +0300
committerMaurício Meneghini Fauth <mauricio@fauth.dev>2021-09-11 21:20:46 +0300
commitbfaf16f56b0bab26ab994802045cf89fbf945c7d (patch)
treeb09e728f68ef9f63f74e9f998ffdece5e6d41dbb /test
parent00cb1b366841d88621f6383f1b99638145424b7e (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.php120
-rw-r--r--test/classes/Controllers/Sql/SetValuesControllerTest.php119
-rw-r--r--test/classes/Controllers/SqlControllerTest.php212
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&amp\',\'\')',
+ '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="">&nbsp;</option>' . "\n"
+ . ' <option value="&lt;script&gt;alert(&quot;ok&quot;)&lt;/script&gt;">'
+ . '&lt;script&gt;alert(&quot;ok&quot;)&lt;/script&gt;</option>' . "\n"
+ . ' <option value="a&amp;b">a&amp;b</option>' . "\n"
+ . ' <option value="b&amp;c" selected>b&amp;c</option>' . "\n"
+ . ' <option value="vrai&amp;amp">vrai&amp;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&amp\',\'\')',
+ '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="&lt;script&gt;alert(&quot;ok&quot;)&lt;/script&gt;">'
+ . '&lt;script&gt;alert(&quot;ok&quot;)&lt;/script&gt;</option>' . "\n"
+ . ' <option value="a&amp;b">a&amp;b</option>' . "\n"
+ . ' <option value="b&amp;c" selected>b&amp;c</option>' . "\n"
+ . ' <option value="vrai&amp;amp">vrai&amp;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&amp\',\'\')',
- '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="&lt;script&gt;alert(&quot;ok&quot;)&lt;/script&gt;">'
- . '&lt;script&gt;alert(&quot;ok&quot;)&lt;/script&gt;</option>' . "\n"
- . ' <option value="a&amp;b">a&amp;b</option>' . "\n"
- . ' <option value="b&amp;c" selected>b&amp;c</option>' . "\n"
- . ' <option value="vrai&amp;amp">vrai&amp;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&amp\',\'\')',
- '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="">&nbsp;</option>' . "\n"
- . ' <option value="&lt;script&gt;alert(&quot;ok&quot;)&lt;/script&gt;">'
- . '&lt;script&gt;alert(&quot;ok&quot;)&lt;/script&gt;</option>' . "\n"
- . ' <option value="a&amp;b">a&amp;b</option>' . "\n"
- . ' <option value="b&amp;c" selected>b&amp;c</option>' . "\n"
- . ' <option value="vrai&amp;amp">vrai&amp;amp</option>' . "\n"
- . ' <option value=""></option>' . "\n"
- . ' </select>' . "\n",
- ],
- $this->getResponseJsonResult()
- );
- }
-}