phpmyadmin/test/classes/UrlTest.php
Maurício Meneghini Fauth 676f48349a Reference global funcs and consts via use statement
Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
2020-01-21 22:13:36 -03:00

115 lines
2.7 KiB
PHP

<?php
/**
* Tests for methods in URL class
*/
declare(strict_types=1);
namespace PhpMyAdmin\Tests;
use PhpMyAdmin\Url;
use PHPUnit\Framework\TestCase;
use function htmlentities;
/**
* Tests for methods in URL class
*/
class UrlTest extends TestCase
{
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*
* @return void
*
* @access protected
*/
protected function setUp(): void
{
unset($_COOKIE['pma_lang']);
}
/**
* Test for Url::getCommon for DB only
*
* @return void
*/
public function testDbOnly()
{
$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
*
* @return void
*/
public function testNewStyle()
{
$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
*
* @return void
*/
public function testWithAlternateDivider()
{
$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
*
* @return void
*/
public function testDefault()
{
$GLOBALS['server'] = 'x';
$GLOBALS['cfg']['ServerDefault'] = 'y';
$separator = Url::getArgSeparator();
$expected = '?server=x' . htmlentities($separator) . 'lang=en';
$this->assertEquals($expected, Url::getCommon());
}
}