phpmyadmin/test/classes/UrlTest.php
Maurício Meneghini Fauth 47f0960dce Add return type declaration to test methods
Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
2020-07-07 11:31:33 -03:00

126 lines
3.1 KiB
PHP

<?php
/**
* Tests for methods in URL class
*/
declare(strict_types=1);
namespace PhpMyAdmin\Tests;
use PhpMyAdmin\Url;
use function htmlentities;
/**
* Tests for methods in URL class
*/
class UrlTest extends AbstractTestCase
{
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*
* @access protected
*/
protected function setUp(): void
{
parent::setUp();
parent::setLanguage();
unset($_COOKIE['pma_lang']);
}
/**
* Test for Url::getCommon for DB only
*/
public function testDbOnly(): void
{
$GLOBALS['server'] = 'x';
$GLOBALS['cfg']['ServerDefault'] = 'y';
$separator = Url::getArgSeparator();
$expected = 'server=x' . htmlentities($separator) . 'lang=en';
$expected = '?db=db'
. htmlentities($separator) . $expected;
$this->assertEquals($expected, Url::getCommon(['db' => 'db']));
}
/**
* Test for Url::getCommon with new style
*/
public function testNewStyle(): void
{
$GLOBALS['server'] = 'x';
$GLOBALS['cfg']['ServerDefault'] = 'y';
$separator = Url::getArgSeparator();
$expected = 'server=x' . htmlentities($separator) . 'lang=en';
$expected = '?db=db'
. htmlentities($separator) . 'table=table'
. htmlentities($separator) . $expected;
$params = [
'db' => 'db',
'table' => 'table',
];
$this->assertEquals($expected, Url::getCommon($params));
}
/**
* Test for Url::getCommon with alternate divider
*/
public function testWithAlternateDivider(): void
{
$GLOBALS['server'] = 'x';
$GLOBALS['cfg']['ServerDefault'] = 'y';
$separator = Url::getArgSeparator();
$expected = 'server=x' . $separator . 'lang=en';
$expected = '#ABC#db=db' . $separator . 'table=table' . $separator
. $expected;
$this->assertEquals(
$expected,
Url::getCommonRaw(
[
'db' => 'db',
'table' => 'table',
],
'#ABC#'
)
);
}
/**
* Test for Url::getCommon
*/
public function testDefault(): void
{
$GLOBALS['server'] = 'x';
$GLOBALS['cfg']['ServerDefault'] = 'y';
$separator = Url::getArgSeparator();
$expected = '?server=x' . htmlentities($separator) . 'lang=en';
$this->assertEquals($expected, Url::getCommon());
}
/**
* Test for Url::getFromRoute
*/
public function testGetFromRoute(): void
{
unset($GLOBALS['server']);
$generatedUrl = Url::getFromRoute('/test', [
'db' => '%3\$s',
'table' => '%2\$s',
'field' => '%1\$s',
'change_column' => 1,
]);
$this->assertEquals(
'index.php?route=/test&amp;db=%253%5C%24s&amp;table=%252%'
. '5C%24s&amp;field=%251%5C%24s&amp;change_column=1&amp;lang=en',
$generatedUrl
);
}
}