1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
|
<?php
declare(strict_types=1);
namespace PhpMyAdmin\Tests\Controllers\Sql;
use PhpMyAdmin\Controllers\Sql\EnumValuesController;
use PhpMyAdmin\Tests\AbstractTestCase;
/**
* @covers \PhpMyAdmin\Controllers\Sql\EnumValuesController
*/
#[\PHPUnit\Framework\Attributes\CoversClass(\PhpMyAdmin\Controllers\Sql\EnumValuesController::class)]
class EnumValuesControllerTest extends AbstractTestCase
{
protected function setUp(): void
{
parent::setUp();
parent::setGlobalDbi();
parent::loadContainerBuilder();
parent::loadDbiIntoContainerBuilder();
$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();
self::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();
self::assertSame([
'dropdown' => '<select>' . "\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"
. ' <option value="漢字">漢字</option>' . "\n"
. ' <option value="'">'</option>' . "\n"
. ' <option value="\">\</option>' . "\n"
. ' <option value=""\'">"\'</option>' . "\n"
. ' </select>' . "\n",
], $this->getResponseJsonResult());
}
}
|