310 lines
7.8 KiB
PHP
310 lines
7.8 KiB
PHP
<?php
|
|
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
|
/**
|
|
* Test for PMA\libraries\Util class
|
|
*
|
|
* @package PhpMyAdmin-test
|
|
*/
|
|
|
|
require_once 'test/PMATestCase.php';
|
|
|
|
/**
|
|
* Test for PMA\libraries\Util class
|
|
*
|
|
* @package PhpMyAdmin-test
|
|
*/
|
|
class UtilTest extends PMATestCase
|
|
{
|
|
|
|
/**
|
|
* Test for createGISData
|
|
*
|
|
* @return void
|
|
*/
|
|
public function testCreateGISData()
|
|
{
|
|
$this->assertEquals(
|
|
"abc",
|
|
PMA\libraries\Util::createGISData("abc")
|
|
);
|
|
$this->assertEquals(
|
|
"GeomFromText('POINT()',10)",
|
|
PMA\libraries\Util::createGISData("'POINT()',10")
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Test for getGISFunctions
|
|
*
|
|
* @return void
|
|
*/
|
|
public function testGetGISFunctions()
|
|
{
|
|
$funcs = PMA\libraries\Util::getGISFunctions();
|
|
$this->assertArrayHasKey(
|
|
'Dimension',
|
|
$funcs
|
|
);
|
|
$this->assertArrayHasKey(
|
|
'GeometryType',
|
|
$funcs
|
|
);
|
|
$this->assertArrayHasKey(
|
|
'MBRDisjoint',
|
|
$funcs
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Test for Page Selector
|
|
*
|
|
* @return void
|
|
*/
|
|
public function testPageSelector()
|
|
{
|
|
$this->assertContains(
|
|
'<select class="pageselector ajax" name="pma" >',
|
|
PMA\libraries\Util::pageselector("pma", 3)
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Test for isForeignKeyCheck
|
|
*
|
|
* @return void
|
|
*/
|
|
public function testIsForeignKeyCheck()
|
|
{
|
|
$GLOBALS['server'] = 1;
|
|
|
|
$GLOBALS['cfg']['DefaultForeignKeyChecks'] = 'enable';
|
|
$this->assertEquals(
|
|
true,
|
|
PMA\libraries\Util::isForeignKeyCheck()
|
|
);
|
|
|
|
$GLOBALS['cfg']['DefaultForeignKeyChecks'] = 'disable';
|
|
$this->assertEquals(
|
|
false,
|
|
PMA\libraries\Util::isForeignKeyCheck()
|
|
);
|
|
|
|
$GLOBALS['cfg']['DefaultForeignKeyChecks'] = 'default';
|
|
$this->assertEquals(
|
|
true,
|
|
PMA\libraries\Util::isForeignKeyCheck()
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Test for getCharsetQueryPart
|
|
*
|
|
* @param string $collation Collation
|
|
* @param string $expected Expected Charset Query
|
|
*
|
|
* @return void
|
|
* @test
|
|
* @dataProvider charsetQueryData
|
|
*/
|
|
public function testGenerateCharsetQueryPart($collation, $expected)
|
|
{
|
|
$this->assertEquals(
|
|
$expected,
|
|
PMA\libraries\Util::getCharsetQueryPart($collation)
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Data Provider for testgetCharsetQueryPart
|
|
*
|
|
* @return array test data
|
|
*/
|
|
public function charsetQueryData()
|
|
{
|
|
return array(
|
|
array("a_b_c_d", " CHARSET=a COLLATE a_b_c_d"),
|
|
array("a_", " CHARSET=a COLLATE a_"),
|
|
array("a", " CHARSET=a"),
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Test for isForeignKeySupported
|
|
*
|
|
* @return void
|
|
*/
|
|
public function testIsForeignKeySupported()
|
|
{
|
|
$GLOBALS['server'] = 1;
|
|
|
|
$this->assertTrue(
|
|
PMA\libraries\Util::isForeignKeySupported('innodb')
|
|
);
|
|
$this->assertFalse(
|
|
PMA\libraries\Util::isForeignKeySupported('myisam')
|
|
);
|
|
$this->assertTrue(
|
|
PMA\libraries\Util::isForeignKeySupported('ndb')
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Skip test if CURL extension is not installed
|
|
*
|
|
* @param boolean $ssl_flags Whether to check support for SSL flags
|
|
*
|
|
* @return void
|
|
*/
|
|
public function checkCurl($ssl_flags = false)
|
|
{
|
|
if (! function_exists('curl_init')) {
|
|
$this->markTestSkipped('curl not supported');
|
|
}
|
|
if ($ssl_flags) {
|
|
$curl = curl_version();
|
|
/*
|
|
* Some SSL engines in CURL do not support CURLOPT_CAPATH
|
|
* and CURLOPT_CAINFO flags, see
|
|
* https://curl.haxx.se/docs/ssl-compared.html
|
|
*/
|
|
if (stripos($curl['ssl_version'], 'WinSSL') !== false
|
|
|| stripos($curl['ssl_version'], 'SecureTransport') !== false
|
|
) {
|
|
$this->markTestSkipped('Not supported in CURL SSL backend: ' . $curl['ssl_version']);
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Test for http request using Curl
|
|
*
|
|
* @group medium
|
|
*
|
|
* @return void
|
|
*
|
|
* @dataProvider httpRequests
|
|
*
|
|
* @group network
|
|
*/
|
|
public function testHttpRequestCurl($url, $method, $return_only_status, $expected)
|
|
{
|
|
$this->checkCurl();
|
|
$result = PMA\libraries\Util::httpRequestCurl($url, $method, $return_only_status);
|
|
$this->validateHttp($result, $expected);
|
|
}
|
|
|
|
/**
|
|
* Test for http request using Curl with CURLOPT_CAPATH
|
|
*
|
|
* @group medium
|
|
*
|
|
* @return void
|
|
*
|
|
* @dataProvider httpRequests
|
|
*
|
|
* @group network
|
|
*/
|
|
public function testHttpRequestCurlCAPath($url, $method, $return_only_status, $expected)
|
|
{
|
|
$this->checkCurl(true);
|
|
$result = PMA\libraries\Util::httpRequestCurl($url, $method, $return_only_status, null, '', CURLOPT_CAPATH);
|
|
$this->validateHttp($result, $expected);
|
|
}
|
|
|
|
/**
|
|
* Test for http request using Curl with CURLOPT_CAINFO
|
|
*
|
|
* @group medium
|
|
*
|
|
* @return void
|
|
*
|
|
* @dataProvider httpRequests
|
|
*
|
|
* @group network
|
|
*/
|
|
public function testHttpRequestCurlCAInfo($url, $method, $return_only_status, $expected)
|
|
{
|
|
$this->checkCurl(true);
|
|
$result = PMA\libraries\Util::httpRequestCurl($url, $method, $return_only_status, null, '', CURLOPT_CAINFO);
|
|
$this->validateHttp($result, $expected);
|
|
}
|
|
|
|
/**
|
|
* Test for http request using fopen
|
|
*
|
|
* @group medium
|
|
*
|
|
* @return void
|
|
*
|
|
* @dataProvider httpRequests
|
|
*
|
|
* @group network
|
|
*/
|
|
public function testHttpRequestFopen($url, $method, $return_only_status, $expected)
|
|
{
|
|
if (! ini_get('allow_url_fopen')) {
|
|
$this->markTestSkipped('allow_url_fopen not supported');
|
|
}
|
|
$result = PMA\libraries\Util::httpRequestFopen($url, $method, $return_only_status);
|
|
$this->validateHttp($result, $expected);
|
|
}
|
|
|
|
|
|
/**
|
|
* Test for http request using generic interface
|
|
*
|
|
* @group medium
|
|
*
|
|
* @return void
|
|
*
|
|
* @dataProvider httpRequests
|
|
*
|
|
* @group network
|
|
*/
|
|
public function testHttpRequest($url, $method, $return_only_status, $expected)
|
|
{
|
|
if (! function_exists('curl_init') && ! ini_get('allow_url_fopen')) {
|
|
$this->markTestSkipped('neither curl nor allow_url_fopen are supported');
|
|
}
|
|
$result = PMA\libraries\Util::httpRequest($url, $method, $return_only_status);
|
|
$this->validateHttp($result, $expected);
|
|
}
|
|
|
|
/**
|
|
* Method to check http test results
|
|
*
|
|
* @param mixed $result Result of HTTP request
|
|
* @param mixed $expected Expected match
|
|
*
|
|
* @return void
|
|
*/
|
|
private function validateHttp($result, $expected)
|
|
{
|
|
if ($expected === true) {
|
|
$this->assertTrue($result);
|
|
} elseif ($expected === false) {
|
|
$this->assertFalse($result);
|
|
} elseif ($expected === null) {
|
|
$this->assertNull($result);
|
|
} else {
|
|
$this->assertContains($expected, $result);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Data provider for HTTP tests
|
|
*
|
|
* @return array
|
|
*/
|
|
public function httpRequests()
|
|
{
|
|
return array(
|
|
array("https://www.phpmyadmin.net/test/data", "GET", true, true),
|
|
array("https://www.phpmyadmin.net/test/data", "POST", true, null),
|
|
array("https://nonexisting.phpmyadmin.net/test/data", "GET", true, null),
|
|
array("https://www.phpmyadmin.net/test/data","GET", false, "TEST DATA"),
|
|
array("https://www.phpmyadmin.net/test/nothing","GET", true, false),
|
|
);
|
|
}
|
|
}
|