213 lines
6.6 KiB
PHP
213 lines
6.6 KiB
PHP
<?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()
|
|
);
|
|
}
|
|
}
|