Initial commit

This commit is contained in:
2022-11-21 09:47:28 +01:00
commit 76cec83d26
11652 changed files with 1980467 additions and 0 deletions

View File

@ -0,0 +1,76 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* Test for PMA\libraries\Util::getBrowseUploadFileBlock from common.lib
*
* @package PhpMyAdmin-test
* @group common.lib-tests
*/
/*
* Include to test.
*/
/**
* Test for PMA\libraries\Util::getBrowseUploadFileBlock from common.lib
*
* @package PhpMyAdmin-test
* @group common.lib-tests
*/
class PMA_GetBrowseUploadFileBlock_Test extends PHPUnit_Framework_TestCase
{
/**
* Set up
*
* @return void
*/
protected function setUp()
{
$GLOBALS['is_upload'] = false;
}
/**
* Data provider for test
*
* @return array
*/
public function dataProvider()
{
return array(
array(10, __('B'), "10"),
array(100, __('B'), "100"),
array(1024, __('B'), "1,024"),
array(102400, __('KiB'), "100"),
array(10240000, __('MiB'), "10"),
array(2147483648, __('MiB'), "2,048"),
array(21474836480, __('GiB'), "20")
);
}
/**
* Test for PMA\libraries\Util::getBrowseUploadFileBlock
*
* @param int $size Size
* @param string $unit Unit
* @param string $res Result
*
* @return void
*
* @dataProvider dataProvider
*/
function testBrowseUploadFile($size, $unit, $res)
{
$this->assertEquals(
PMA\libraries\Util::getBrowseUploadFileBlock($size),
'<label for="input_import_file">' . __("Browse your computer:")
. '</label>'
. '<div id="upload_form_status" style="display: none;"></div>'
. '<div id="upload_form_status_info" style="display: none;"></div>'
. '<input type="file" name="import_file" id="input_import_file" />'
. "(" . __('Max: ') . $res . $unit . ")" . "\n"
. '<input type="hidden" name="MAX_FILE_SIZE" value="'
. $size . '" />' . "\n"
);
}
}

View File

@ -0,0 +1,69 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* Test for PMA\libraries\Util::buildActionTitles from common.lib
*
* @package PhpMyAdmin-test
* @group common.lib-tests
*/
/*
* Include to test.
*/
use PMA\libraries\Theme;
/**
* Test for PMA\libraries\Util::buildActionTitles from common.lib
*
* @package PhpMyAdmin-test
* @group common.lib-tests
*/
class PMA_BuildActionTitles_Test extends PHPUnit_Framework_TestCase
{
/**
* Set up
*
* @return void
*/
function setup()
{
$_SESSION['PMA_Theme'] = Theme::load('./themes/pmahomme');
$GLOBALS['cfg'] = array('ActionLinksMode' => 'both');
$GLOBALS['pmaThemeImage'] = 'theme/';
}
/**
* Test for buildActionTitles
*
* @return void
*/
function testBuildActionTitles()
{
$titles = array();
$titles['Browse'] = PMA\libraries\Util::getIcon('b_browse.png', __('Browse'));
$titles['NoBrowse'] = PMA\libraries\Util::getIcon('bd_browse.png', __('Browse'));
$titles['Search'] = PMA\libraries\Util::getIcon('b_select.png', __('Search'));
$titles['NoSearch'] = PMA\libraries\Util::getIcon('bd_select.png', __('Search'));
$titles['Insert'] = PMA\libraries\Util::getIcon('b_insrow.png', __('Insert'));
$titles['NoInsert'] = PMA\libraries\Util::getIcon('bd_insrow.png', __('Insert'));
$titles['Structure'] = PMA\libraries\Util::getIcon('b_props.png', __('Structure'));
$titles['Drop'] = PMA\libraries\Util::getIcon('b_drop.png', __('Drop'));
$titles['NoDrop'] = PMA\libraries\Util::getIcon('bd_drop.png', __('Drop'));
$titles['Empty'] = PMA\libraries\Util::getIcon('b_empty.png', __('Empty'));
$titles['NoEmpty'] = PMA\libraries\Util::getIcon('bd_empty.png', __('Empty'));
$titles['Edit'] = PMA\libraries\Util::getIcon('b_edit.png', __('Edit'));
$titles['NoEdit'] = PMA\libraries\Util::getIcon('bd_edit.png', __('Edit'));
$titles['Export'] = PMA\libraries\Util::getIcon('b_export.png', __('Export'));
$titles['NoExport'] = PMA\libraries\Util::getIcon('bd_export.png', __('Export'));
$titles['Execute'] = PMA\libraries\Util::getIcon('b_nextpage.png', __('Execute'));
$titles['NoExecute'] = PMA\libraries\Util::getIcon('bd_nextpage.png', __('Execute'));
$titles['Favorite'] = PMA\libraries\Util::getIcon('b_favorite.png', '');
$titles['NoFavorite'] = PMA\libraries\Util::getIcon('b_no_favorite.png', '');
$this->assertEquals($titles, PMA\libraries\Util::buildActionTitles());
}
}

View File

@ -0,0 +1,136 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* Test for caching data in session
*
* @package PhpMyAdmin-test
* @group common.lib-tests
*/
/*
* Include to test.
*/
/**
* Test for caching data in session
*
* @package PhpMyAdmin-test
* @group common.lib-tests
*/
class PMA_Cache_Test extends PHPUnit_Framework_TestCase
{
/**
* @var array temporary variable for globals array
*/
protected $tmpGlobals;
/**
* @var array temporary variable for session array
*/
protected $tmpSession;
/**
* storing globals and session
*
* @return void
*/
public function setUp()
{
$this->tmpGlobals = $GLOBALS;
$this->tmpSession = $_SESSION;
}
/**
* Test if cached data is available after set
*
* @return void
*/
public function testCacheExists()
{
$GLOBALS['server'] = 'server';
PMA\libraries\Util::cacheSet('test_data', 5);
PMA\libraries\Util::cacheSet('test_data_2', 5);
$this->assertTrue(PMA\libraries\Util::cacheExists('test_data'));
$this->assertTrue(PMA\libraries\Util::cacheExists('test_data_2'));
$this->assertFalse(PMA\libraries\Util::cacheExists('fake_data_2'));
}
/**
* Test if PMA\libraries\Util::cacheGet does not return data for non existing cache entries
*
* @return void
*/
public function testCacheGet()
{
$GLOBALS['server'] = 'server';
PMA\libraries\Util::cacheSet('test_data', 5);
PMA\libraries\Util::cacheSet('test_data_2', 5);
$this->assertNotNull(PMA\libraries\Util::cacheGet('test_data'));
$this->assertNotNull(PMA\libraries\Util::cacheGet('test_data_2'));
$this->assertNull(PMA\libraries\Util::cacheGet('fake_data_2'));
}
/**
* Test retrieval of cached data
*
* @return void
*/
public function testCacheSetGet()
{
$GLOBALS['server'] = 'server';
PMA\libraries\Util::cacheSet('test_data', 25);
PMA\libraries\Util::cacheSet('test_data', 5);
$this->assertEquals(5, $_SESSION['cache']['server_server']['test_data']);
PMA\libraries\Util::cacheSet('test_data_3', 3);
$this->assertEquals(3, $_SESSION['cache']['server_server']['test_data_3']);
}
/**
* Test clearing cached values
*
* @return void
*/
public function testCacheUnSet()
{
$GLOBALS['server'] = 'server';
PMA\libraries\Util::cacheSet('test_data', 25);
PMA\libraries\Util::cacheSet('test_data_2', 25);
PMA\libraries\Util::cacheUnset('test_data');
$this->assertArrayNotHasKey(
'test_data',
$_SESSION['cache']['server_server']
);
PMA\libraries\Util::cacheUnset('test_data_2');
$this->assertArrayNotHasKey(
'test_data_2',
$_SESSION['cache']['server_server']
);
}
/**
* Test clearing user cache
*
* @return void
*/
public function testClearUserCache()
{
$GLOBALS['server'] = 'server';
PMA\libraries\Util::cacheSet('is_superuser', 'yes');
$this->assertEquals(
'yes',
$_SESSION['cache']['server_server']['is_superuser']
);
PMA\libraries\Util::clearUserCache();
$this->assertArrayNotHasKey(
'is_superuser',
$_SESSION['cache']['server_server']
);
}
}

View File

@ -0,0 +1,76 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
** Test for PMA\libraries\Util::checkParameters from Util.php
*
* @package PhpMyAdmin-test
* @group common.lib-tests
*/
/*
* Include to test.
*/
use PMA\libraries\Theme;
require_once 'libraries/sanitizing.lib.php';
/**
** Test for PMA\libraries\Util::checkParameters from Util.php
*
* @package PhpMyAdmin-test
* @group common.lib-tests
*/
class PMA_CheckParameters_Test extends PHPUnit_Framework_TestCase
{
/**
* Set up
*
* @return void
*/
function setup()
{
$GLOBALS['PMA_Config'] = new PMA\libraries\Config();
$_SESSION['PMA_Theme'] = new Theme();
$GLOBALS['cfg'] = array('ServerDefault' => 1);
$GLOBALS['pmaThemeImage'] = 'theme/';
$GLOBALS['text_dir'] = 'ltr';
}
/**
* Test for checkParameters
*
* @return void
*/
function testCheckParameterMissing()
{
$GLOBALS['PMA_PHP_SELF'] = PMA_getenv('PHP_SELF');
$GLOBALS['pmaThemePath'] = $_SESSION['PMA_Theme']->getPath();
$this->expectOutputRegex("/Missing parameter: field/");
PMA\libraries\Util::checkParameters(
array('db', 'table', 'field')
);
}
/**
* Test for checkParameters
*
* @return void
*/
function testCheckParameter()
{
$GLOBALS['PMA_PHP_SELF'] = PMA_getenv('PHP_SELF');
$GLOBALS['pmaThemePath'] = $_SESSION['PMA_Theme']->getPath();
$GLOBALS['db'] = "dbDatabase";
$GLOBALS['table'] = "tblTable";
$GLOBALS['field'] = "test_field";
$GLOBALS['sql_query'] = "SELECT * FROM tblTable;";
$this->expectOutputString("");
PMA\libraries\Util::checkParameters(
array('db', 'table', 'field', 'sql_query')
);
}
}

View File

@ -0,0 +1,56 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
** Test for PMA\libraries\Util::containsNonPrintableAscii from common.lib
*
* @package PhpMyAdmin-test
* @group common.lib-tests
*/
/*
* Include to test.
*/
/**
** Test for PMA\libraries\Util::containsNonPrintableAscii from common.lib
*
* @package PhpMyAdmin-test
* @group common.lib-tests
*/
class PMA_ContainsNonPrintableAsciiTest extends PHPUnit_Framework_TestCase
{
/**
* data provider for testContainsNonPrintableAscii
*
* @return array
*/
public function dataProvider()
{
return array(
array("normal string", 0),
array("new\nline", 1),
array("tab\tspace", 1),
array("escape" . chr(27) . "char", 1),
array("chars%$\r\n", 1),
);
}
/**
* Test for containsNonPrintableAscii
*
* @param string $str Value
* @param bool $res Expected value
*
* @return void
*
* @dataProvider dataProvider
*/
public function testContainsNonPrintableAscii($str, $res)
{
$this->assertEquals(
$res, PMA\libraries\Util::containsNonPrintableAscii($str)
);
}
}

View File

@ -0,0 +1,57 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
** Test for PMA\libraries\Util::convertBitDefaultValue from common.lib
*
* @package PhpMyAdmin-test
* @group common.lib-tests
*/
/*
* Include to test.
*/
/**
** Test for PMA\libraries\Util::convertBitDefaultValue from common.lib
*
* @package PhpMyAdmin-test
* @group common.lib-tests
*/
class PMA_ConvertBitDefaultValueTest extends PHPUnit_Framework_TestCase
{
/**
* Provider for testConvertBitDefaultValueTest
*
* @return array
*
* @dataProvider dataProvider
*/
public function dataProvider()
{
return array(
array("b'",""),
array("b'01'","01"),
array("b'010111010'","010111010")
);
}
/**
* Test for convertBitDefaultValue
*
* @param string $bit Value
* @param string $val Expected value
*
* @return void
*
* @dataProvider dataProvider
*/
public function testConvertBitDefaultValueTest($bit, $val)
{
$this->assertEquals(
$val, PMA\libraries\Util::convertBitDefaultValue($bit)
);
}
}

View File

@ -0,0 +1,75 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* Test for MySQL Wildcards escaping/unescaping
*
* @package PhpMyAdmin-test
* @group common.lib-tests
*/
/*
* Include to test.
*/
/**
* Test for MySQL Wildcards escaping/unescaping
*
* @package PhpMyAdmin-test
* @group common.lib-tests
*/
class PMA_EscapeMySqlWildcardsTest extends PHPUnit_Framework_TestCase
{
/**
* data provider for testEscape and testUnEscape
*
* @return array
*/
public function escapeDataProvider()
{
return array(
array('\_test', '_test'),
array('\_\\', '_\\'),
array('\\_\%', '_%'),
array('\\\_', '\_'),
array('\\\_\\\%', '\_\%'),
array('\_\\%\_\_\%', '_%__%'),
array('\%\_', '%_'),
array('\\\%\\\_', '\%\_')
);
}
/**
* PMA\libraries\Util::escapeMysqlWildcards tests
*
* @param string $a String to escape
* @param string $b Expected value
*
* @return void
*
* @dataProvider escapeDataProvider
*/
public function testEscape($a, $b)
{
$this->assertEquals(
$a, PMA\libraries\Util::escapeMysqlWildcards($b)
);
}
/**
* PMA\libraries\Util::unescapeMysqlWildcards tests
*
* @param string $a String to escape
* @param string $b Expected value
*
* @return void
*
* @dataProvider escapeDataProvider
*/
public function testUnEscape($a, $b)
{
$this->assertEquals(
$b, PMA\libraries\Util::unescapeMysqlWildcards($a)
);
}
}

View File

@ -0,0 +1,98 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
** Test for PMA\libraries\Util::expandUserString from Util.php
*
* @package PhpMyAdmin-test
* @group common.lib-tests
*/
/*
* Include to test.
*/
/**
** Test for PMA\libraries\Util::expandUserString function.
*
* @package PhpMyAdmin-test
*/
class PMA_ExpandUserString_Test extends PHPUnit_Framework_TestCase
{
/**
* Setup variables needed by test.
*
* @return void
*/
public function setup()
{
$GLOBALS['PMA_Config'] = new PMA\libraries\Config();
$GLOBALS['PMA_Config']->enableBc();
$GLOBALS['cfg'] = array(
'Server' => array(
'host' => 'host&',
'verbose' => 'verbose',
)
);
$GLOBALS['db'] = 'database';
$GLOBALS['table'] = 'table';
}
/**
* Test case for expanding strings
*
* @param string $in string to evaluate
* @param string $out expected output
*
* @return void
*
* @dataProvider provider
*/
public function testExpand($in, $out)
{
$out = str_replace('PMA_VERSION', PMA_VERSION, $out);
$this->assertEquals(
$out, PMA\libraries\Util::expandUserString($in)
);
}
/**
* Test case for expanding strings with escaping
*
* @param string $in string to evaluate
* @param string $out expected output
*
* @return void
*
* @dataProvider provider
*/
public function testExpandEscape($in, $out)
{
$out = str_replace('PMA_VERSION', PMA_VERSION, $out);
$this->assertEquals(
htmlspecialchars($out),
PMA\libraries\Util::expandUserString(
$in, 'htmlspecialchars'
)
);
}
/**
* Data provider
*
* @return array
*/
public function provider()
{
return array(
array('@SERVER@', 'host&'),
array('@VSERVER@', 'verbose'),
array('@DATABASE@', 'database'),
array('@TABLE@', 'table'),
array('@IGNORE@', '@IGNORE@'),
array('@PHPMYADMIN@', 'phpMyAdmin PMA_VERSION'),
);
}
}

View File

@ -0,0 +1,164 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
** Test for PMA\libraries\Util::extractColumnSpec from Util.php
*
* @package PhpMyAdmin-test
* @group common.lib-tests
*/
/*
* Include to test.
*/
/**
** Test for PMA\libraries\Util::extractColumnSpec function.
*
* @package PhpMyAdmin-test
*/
class PMA_ExtractColumnSpec_Test extends PHPUnit_Framework_TestCase
{
/**
* Set up
*
* @return void
*/
protected function setUp()
{
$GLOBALS['cfg']['LimitChars'] = 1000;
}
/**
* Test case for parsing SHOW COLUMNS output
*
* @param string $in Column specification
* @param array $out Expected value
*
* @return void
*
* @dataProvider provider
*/
public function testParsing($in, $out)
{
$this->assertEquals(
$out, PMA\libraries\Util::extractColumnSpec($in)
);
}
/**
* Data provider
*
* @return array
*/
public function provider()
{
return array(
array(
"SET('a','b')",
array(
'type' => 'set',
'print_type' => "set('a', 'b')",
'binary' => false,
'unsigned' => false,
'zerofill' => false,
'spec_in_brackets' => "'a','b'",
'enum_set_values' => array('a', 'b'),
'attribute' => ' ',
'can_contain_collation' => true,
'displayed_type' => "set('a', 'b')"
),
),
array(
"SET('\'a','b')",
array(
'type' => 'set',
'print_type' => "set('\'a', 'b')",
'binary' => false,
'unsigned' => false,
'zerofill' => false,
'spec_in_brackets' => "'\'a','b'",
'enum_set_values' => array("'a", 'b'),
'attribute' => ' ',
'can_contain_collation' => true,
'displayed_type' => "set('\'a', 'b')"
),
),
array(
"SET('''a','b')",
array(
'type' => 'set',
'print_type' => "set('''a', 'b')",
'binary' => false,
'unsigned' => false,
'zerofill' => false,
'spec_in_brackets' => "'''a','b'",
'enum_set_values' => array("'a", 'b'),
'attribute' => ' ',
'can_contain_collation' => true,
'displayed_type' => "set('''a', 'b')"
),
),
array(
"ENUM('a&b', 'b''c\\'d', 'e\\\\f')",
array(
'type' => 'enum',
'print_type' => "enum('a&b', 'b''c\\'d', 'e\\\\f')",
'binary' => false,
'unsigned' => false,
'zerofill' => false,
'spec_in_brackets' => "'a&b', 'b''c\\'d', 'e\\\\f'",
'enum_set_values' => array('a&b', 'b\'c\'d', 'e\\f'),
'attribute' => ' ',
'can_contain_collation' => true,
'displayed_type' => "enum('a&amp;b', 'b''c\\'d', 'e\\\\f')"
),
),
array(
"INT UNSIGNED zerofill",
array(
'type' => 'int',
'print_type' => 'int',
'binary' => false,
'unsigned' => true,
'zerofill' => true,
'spec_in_brackets' => '',
'enum_set_values' => array(),
'attribute' => 'UNSIGNED ZEROFILL',
'can_contain_collation' => false,
'displayed_type' => "int"
),
),
array(
"VARCHAR(255)",
array(
'type' => 'varchar',
'print_type' => 'varchar(255)',
'binary' => false,
'unsigned' => false,
'zerofill' => false,
'spec_in_brackets' => '255',
'enum_set_values' => array(),
'attribute' => ' ',
'can_contain_collation' => true,
'displayed_type' => "varchar(255)"
),
),
array(
"VARBINARY(255)",
array(
'type' => 'varbinary',
'print_type' => 'varbinary(255)',
'binary' => false,
'unsigned' => false,
'zerofill' => false,
'spec_in_brackets' => '255',
'enum_set_values' => array(),
'attribute' => ' ',
'can_contain_collation' => false,
'displayed_type' => "varbinary(255)"
),
),
);
}
}

View File

@ -0,0 +1,55 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
** Test for PMA\libraries\Util::extractValueFromFormattedSize from common.lib
*
* @package PhpMyAdmin-test
* @group common.lib-tests
*/
/*
* Include to test.
*/
/**
** Test for PMA\libraries\Util::extractValueFromFormattedSize from common.lib
*
* @package PhpMyAdmin-test
* @group common.lib-tests
*/
class PMA_ExtractValueFromFormattedSize_Test extends PHPUnit_Framework_TestCase
{
/**
* Test for extractValueFromFormattedSize
*
* @param int|string $size Size
* @param int $expected Expected value
*
* @return void
*
* @dataProvider provider
*/
function testExtractValueFromFormattedSize($size, $expected)
{
$this->assertEquals(
$expected,
PMA\libraries\Util::extractValueFromFormattedSize($size)
);
}
/**
* Data provider for testExtractValueFromFormattedSize
*
* @return array
*/
public function provider()
{
return array(
array(100, -1),
array("10GB", 10737418240),
array("15MB", 15728640),
array("256K", 262144)
);
}
}

View File

@ -0,0 +1,53 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* Test for supporting foreign key
*
* @package PhpMyAdmin-test
* @group common.lib-tests
*/
/*
* Include to test.
*/
/**
* Test for supporting foreign key
*
* @package PhpMyAdmin-test
* @group common.lib-tests
*/
class PMA_IsForeignKeySupportedTest extends PHPUnit_Framework_TestCase
{
/**
* data provider for foreign key supported test
*
* @return array
*/
public function foreignkeySupportedDataProvider()
{
return array(
array('MyISAM', false),
array('innodb', true),
array('pBxT', true)
);
}
/**
* foreign key supported test
*
* @param string $a Engine
* @param bool $e Expected Value
*
* @return void
*
* @dataProvider foreignkeySupportedDataProvider
*/
public function testForeignkeySupported($a, $e)
{
$this->assertEquals(
$e, PMA\libraries\Util::isForeignKeySupported($a)
);
}
}

View File

@ -0,0 +1,169 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* Test for format number and byte
*
* @package PhpMyAdmin-test
* @group common.lib-tests
*/
/*
* Include to test.
*/
/**
* Test for format number and byte
*
* @package PhpMyAdmin-test
* @group common.lib-tests
*/
class PMA_FormatNumberByteDown_Test extends PHPUnit_Framework_TestCase
{
/**
* temporary variable for globals array
*/
protected $tmpGlobals;
/**
* temporary variable for session array
*/
protected $tmpSession;
/**
* storing globals and session
*
* @return void
*/
public function setUp()
{
$this->tmpGlobals = $GLOBALS;
$this->tmpSession = $_SESSION;
}
/**
* recovering globals and session
*
* @return void
*/
public function tearDown()
{
$GLOBALS = $this->tmpGlobals;
$_SESSION = $this->tmpSession;
}
/**
* format number data provider
*
* @return array
*/
public function formatNumberDataProvider()
{
return array(
array(10, 2, 2, '10 '),
array(100, 2, 0, '100 '),
array(100, 2, 2, '100 '),
array(-1000.454, 4, 2, '-1,000.45 '),
array(0.00003, 3, 2, '30 &micro;'),
array(0.003, 3, 3, '3 m'),
array(-0.003, 6, 0, '-3,000 &micro;'),
array(100.98, 0, 2, '100.98'),
array(21010101, 0, 2, '21,010,101.00'),
array(20000, 2, 2, '20 k'),
array(20011, 2, 2, '20.01 k'),
);
}
/**
* Core test for formatNumber
*
*
* @param float $a Value to format
* @param int $b Sensitiveness
* @param int $c Number of decimals to retain
* @param array $d Expected value
*
* @return void
*/
private function assertFormatNumber($a, $b, $c, $d)
{
$this->assertEquals(
$d,
(string) PMA\libraries\Util::formatNumber(
$a, $b, $c, false
)
);
}
/**
* format number test, globals are defined
*
* @param float $a Value to format
* @param int $b Sensitiveness
* @param int $c Number of decimals to retain
* @param array $d Expected value
*
* @return void
*
* @dataProvider formatNumberDataProvider
*/
public function testFormatNumber($a, $b, $c, $d)
{
$this->assertFormatNumber($a, $b, $c, $d);
// Test with various precisions
$old_precision = ini_get('precision');
ini_set('precision', 20);
$this->assertFormatNumber($a, $b, $c, $d);
ini_set('precision', 14);
$this->assertFormatNumber($a, $b, $c, $d);
ini_set('precision', 10);
$this->assertFormatNumber($a, $b, $c, $d);
ini_set('precision', 5);
$this->assertFormatNumber($a, $b, $c, $d);
ini_set('precision', -1);
$this->assertFormatNumber($a, $b, $c, $d);
ini_set('precision', $old_precision);
}
/**
* format byte down data provider
*
* @return array
*/
public function formatByteDownDataProvider()
{
return array(
array(10, 2, 2, array('10', __('B'))),
array(100, 2, 0, array('0', __('KiB'))),
array(100, 3, 0, array('100', __('B'))),
array(100, 2, 2, array('0.10', __('KiB'))),
array(1034, 3, 2, array('1.01', __('KiB'))),
array(100233, 3, 3, array('97.884', __('KiB'))),
array(2206451, 1, 2, array('2.10', __('MiB'))),
array(21474836480, 4, 0, array('20', __('GiB'))),
array(doubleval(52) + doubleval(2048), 3, 1, array('2.1', 'KiB')),
);
}
/**
* format byte test, globals are defined
*
* @param float $a Value to format
* @param int $b Sensitiveness
* @param int $c Number of decimals to retain
* @param array $e Expected value
*
* @return void
*
* @dataProvider formatByteDownDataProvider
*/
public function testFormatByteDown($a, $b, $c, $e)
{
$result = PMA\libraries\Util::formatByteDown($a, $b, $c);
$result[0] = trim($result[0]);
$this->assertEquals($e, $result);
}
}

View File

@ -0,0 +1,55 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
** Test for PMA\libraries\Util::formatSql from Util.php
*
* @package PhpMyAdmin-test
* @group common.lib-tests
*/
/*
* Include to test.
*/
/**
** Test for PMA\libraries\Util::formatSql from Util.php
*
* @package PhpMyAdmin-test
* @group common.lib-tests
*/
class PMA_FormatSql_Test extends PHPUnit_Framework_TestCase
{
/**
* Test for formatSql
*
* @return void
*/
function testFormatSQL()
{
$this->assertEquals(
'<code class="sql"><pre>' . "\n"
. 'SELECT 1 &lt; 2' . "\n"
. '</pre></code>',
PMA\libraries\Util::formatSql('SELECT 1 < 2')
);
}
/**
* Test for formatSql
*
* @return void
*/
function testFormatSQLTruncate()
{
$GLOBALS['cfg']['MaxCharactersInDisplayedSQL'] = 6;
$this->assertEquals(
'<code class="sql"><pre>' . "\n"
. 'SELECT[...]' . "\n"
. '</pre></code>',
PMA\libraries\Util::formatSql('SELECT 1 < 2', true)
);
}
}

View File

@ -0,0 +1,57 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
** Test for PMA\libraries\Util::generateHiddenMaxFileSize from Util.php
*
* @package PhpMyAdmin-test
* @group common.lib-tests
*/
/*
* Include to test.
*/
/**
** Test for PMA\libraries\Util::generateHiddenMaxFileSize from Util.php
*
* @package PhpMyAdmin-test
* @group common.lib-tests
*/
class PMA_GenerateHiddenMaxFileSize_Test extends PHPUnit_Framework_TestCase
{
/**
* Data provider for test
*
* @return array
*/
public function dataProvider()
{
return array(
array(10),
array("100"),
array(1024),
array("1024Mb"),
array(2147483648),
array("some_string")
);
}
/**
* Test for generateHiddenMaxFileSize
*
* @param int $size Size
*
* @return void
*
* @dataProvider dataProvider
*/
function testGenerateHiddenMaxFileSize($size)
{
$this->assertEquals(
PMA\libraries\Util::generateHiddenMaxFileSize($size),
'<input type="hidden" name="MAX_FILE_SIZE" value="' . $size . '" />'
);
}
}

View File

@ -0,0 +1,94 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
** Test for PMA\libraries\Util::getCheckbox from Util.php
*
* @package PhpMyAdmin-test
* @group common.lib-tests
*/
/*
* Include to test.
*/
/**
** Test for PMA\libraries\Util::getCheckbox from Util.php
*
* @package PhpMyAdmin-test
* @group common.lib-tests
*/
class PMA_GetCheckboxTest extends PHPUnit_Framework_TestCase
{
/**
* Test for getCheckbox
*
* @return void
*/
function testGetCheckbox()
{
$name = "test_display_html_checkbox";
$label = "text_label_for_checkbox";
$this->assertEquals(
PMA\libraries\Util::getCheckbox($name, $label, false, false, $name),
'<input type="checkbox" name="' . $name . '" id="' . $name
. '" /><label for="' . $name . '">' . $label
. '</label>'
);
}
/**
* Test for getCheckbox
*
* @return void
*/
function testGetCheckboxChecked()
{
$name = "test_display_html_checkbox";
$label = "text_label_for_checkbox";
$this->assertEquals(
PMA\libraries\Util::getCheckbox($name, $label, true, false, $name),
'<input type="checkbox" name="' . $name . '" id="' . $name
. '" checked="checked" /><label for="' . $name . '">' . $label
. '</label>'
);
}
/**
* Test for getCheckbox
*
* @return void
*/
function testGetCheckboxOnclick()
{
$name = "test_display_html_checkbox";
$label = "text_label_for_checkbox";
$this->assertEquals(
PMA\libraries\Util::getCheckbox($name, $label, false, true, $name),
'<input type="checkbox" name="' . $name . '" id="' . $name
. '" class="autosubmit" /><label for="' . $name . '">' . $label
. '</label>'
);
}
/**
* Test for getCheckbox
*
* @return void
*/
function testGetCheckboxCheckedOnclick()
{
$name = "test_display_html_checkbox";
$label = "text_label_for_checkbox";
$this->assertEquals(
PMA\libraries\Util::getCheckbox($name, $label, true, true, $name),
'<input type="checkbox" name="' . $name . '" id="' . $name
. '" checked="checked" class="autosubmit" /><label for="' . $name
. '">' . $label . '</label>'
);
}
}

View File

@ -0,0 +1,118 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* Test for PMA_getDbLink_test from Util.php
*
* @package PhpMyAdmin-test
* @group common.lib-tests
*/
/*
* Include to test.
*/
require_once 'libraries/url_generating.lib.php';
/**
* Test for PMA_getDbLink_test from Util.php
*
* @package PhpMyAdmin-test
* @group common.lib-tests
*/
class PMA_GetDbLink_Test extends PHPUnit_Framework_TestCase
{
/**
* Set up
*
* @return void
*/
function setUp()
{
global $cfg;
include 'libraries/config.default.php';
$GLOBALS['server'] = 99;
}
/**
* Test for getDbLink
*
* @return void
*
* @group medium
*/
function testGetDbLinkEmpty()
{
$GLOBALS['db'] = null;
$this->assertEmpty(PMA\libraries\Util::getDbLink());
}
/**
* Test for getDbLink
*
* @return void
*
* @group medium
*/
function testGetDbLinkNull()
{
global $cfg;
$GLOBALS['db'] = 'test_db';
$database = $GLOBALS['db'];
$this->assertEquals(
'<a href="'
. PMA\libraries\Util::getScriptNameForOption(
$GLOBALS['cfg']['DefaultTabDatabase'], 'database'
)
. '?db=' . $database
. '&amp;server=99&amp;lang=en&amp;token=token" '
. 'title="Jump to database &quot;'
. htmlspecialchars($database) . '&quot;.">'
. htmlspecialchars($database) . '</a>',
PMA\libraries\Util::getDbLink()
);
}
/**
* Test for getDbLink
*
* @return void
*/
function testGetDbLink()
{
global $cfg;
$database = 'test_database';
$this->assertEquals(
'<a href="' . PMA\libraries\Util::getScriptNameForOption(
$GLOBALS['cfg']['DefaultTabDatabase'], 'database'
)
. '?db=' . $database
. '&amp;server=99&amp;lang=en&amp;token=token" title="Jump to database &quot;'
. htmlspecialchars($database) . '&quot;.">'
. htmlspecialchars($database) . '</a>',
PMA\libraries\Util::getDbLink($database)
);
}
/**
* Test for getDbLink
*
* @return void
*/
function testGetDbLinkWithSpecialChars()
{
global $cfg;
$database = 'test&data\'base';
$this->assertEquals(
'<a href="'
. PMA\libraries\Util::getScriptNameForOption(
$GLOBALS['cfg']['DefaultTabDatabase'], 'database'
)
. '?db='
. htmlspecialchars(urlencode($database))
. '&amp;server=99&amp;lang=en&amp;token=token" title="Jump to database &quot;'
. htmlspecialchars($database) . '&quot;.">'
. htmlspecialchars($database) . '</a>',
PMA\libraries\Util::getDbLink($database)
);
}
}

View File

@ -0,0 +1,82 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
** Test for PMA\libraries\Util::getDivForSliderEffect from Util.php
*
* @package PhpMyAdmin-test
* @group common.lib-tests
*/
/*
* Include to test.
*/
/**
** Test for PMA\libraries\Util::getDivForSliderEffect from Util.php
*
* @package PhpMyAdmin-test
* @group common.lib-tests
*/
class PMA_GetDivForSliderEffectTest extends PHPUnit_Framework_TestCase
{
/**
* Test for getDivForSliderEffect
*
* @return void
*/
function testGetDivForSliderEffectTest()
{
global $cfg;
$cfg['InitialSlidersState'] = 'undefined';
$id = "test_id";
$message = "test_message";
$this->assertEquals(
PMA\libraries\Util::getDivForSliderEffect($id, $message),
'<div id="' . $id . '" class="pma_auto_slider" title="'
. htmlspecialchars($message) . '">'
);
}
/**
* Test for getDivForSliderEffect
*
* @return void
*/
function testGetDivForSliderEffectTestClosed()
{
global $cfg;
$cfg['InitialSlidersState'] = 'closed';
$id = "test_id";
$message = "test_message";
$this->assertEquals(
PMA\libraries\Util::getDivForSliderEffect($id, $message),
'<div id="' . $id . '" style="display: none; overflow:auto;" '
. 'class="pma_auto_slider" title="' . htmlspecialchars($message) . '">'
);
}
/**
* Test for getDivForSliderEffect
*
* @return void
*/
function testGetDivForSliderEffectTestDisabled()
{
global $cfg;
$cfg['InitialSlidersState'] = 'disabled';
$id = "test_id";
$message = "test_message";
$this->assertEquals(
PMA\libraries\Util::getDivForSliderEffect($id, $message),
'<div id="' . $id . '">'
);
}
}

View File

@ -0,0 +1,107 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
** Test for PMA\libraries\Util::getDropdown from Util.php
*
* @package PhpMyAdmin-test
* @group common.lib-tests
*/
/*
* Include to test.
*/
/**
** Test for PMA\libraries\Util::getDropdown from Util.php
*
* @package PhpMyAdmin-test
* @group common.lib-tests
*/
class PMA_GetDropdownTest extends PHPUnit_Framework_TestCase
{
/**
* Test for getDropdown
*
* @return void
*/
function testGetDropdownEmpty()
{
$name = "test_dropdown_name";
$choices = array();
$active_choice = null;
$id = "test_&lt;dropdown&gt;_name";
$result = '<select name="' . htmlspecialchars($name) . '" id="'
. htmlspecialchars($id) . '"></select>';
$this->assertEquals(
$result,
PMA\libraries\Util::getDropdown(
$name, $choices, $active_choice, $id
)
);
}
/**
* Test for getDropdown
*
* @return void
*/
function testGetDropdown()
{
$name = "&test_dropdown_name";
$choices = array("value_1" => "label_1", "value&_2\"" => "label_2");
$active_choice = null;
$id = "test_&lt;dropdown&gt;_name";
$result = '<select name="' . htmlspecialchars($name) . '" id="'
. htmlspecialchars($id) . '">';
foreach ($choices as $one_choice_value => $one_choice_label) {
$result .= '<option value="' . htmlspecialchars($one_choice_value) . '"';
if ($one_choice_value == $active_choice) {
$result .= ' selected="selected"';
}
$result .= '>' . htmlspecialchars($one_choice_label) . '</option>';
}
$result .= '</select>';
$this->assertEquals(
$result,
PMA\libraries\Util::getDropdown(
$name, $choices, $active_choice, $id
)
);
}
/**
* Test for getDropdown
*
* @return void
*/
function testGetDropdownWithActive()
{
$name = "&test_dropdown_name";
$choices = array("value_1" => "label_1", "value&_2\"" => "label_2");
$active_choice = "value&_2\"";
$id = "test_&lt;dropdown&gt;_name";
$result = '<select name="' . htmlspecialchars($name) . '" id="'
. htmlspecialchars($id) . '">';
foreach ($choices as $one_choice_value => $one_choice_label) {
$result .= '<option value="' . htmlspecialchars($one_choice_value) . '"';
if ($one_choice_value == $active_choice) {
$result .= ' selected="selected"';
}
$result .= '>' . htmlspecialchars($one_choice_label) . '</option>';
}
$result .= '</select>';
$this->assertEquals(
$result,
PMA\libraries\Util::getDropdown(
$name, $choices, $active_choice, $id
)
);
}
}

View File

@ -0,0 +1,61 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
** Test for PMA\libraries\Util::getFormattedMaximumUploadSize from Util.php
*
* @package PhpMyAdmin-test
* @group common.lib-tests
*/
/*
* Include to test.
*/
/**
** Test for PMA\libraries\Util::getFormattedMaximumUploadSize from Util.php
*
* @package PhpMyAdmin-test
* @group common.lib-tests
*/
class PMA_GetFormattedMaximumUploadSize_Test extends PHPUnit_Framework_TestCase
{
/**
* Data provider for test
*
* @return array
*/
public function dataProvider()
{
return array(
array(10, __('B'), "10"),
array(100, __('B'), "100"),
array(1024, __('B'), "1,024"),
array(102400, __('KiB'), "100"),
array(10240000, __('MiB'), "10"),
array(2147483648, __('MiB'), "2,048"),
array(21474836480, __('GiB'), "20")
);
}
/**
* Test for PMA\libraries\Util::getFormattedMaximumUploadSize
*
* @param int $size Size
* @param string $unit Unit
* @param string $res Result
*
* @return void
*
* @dataProvider dataProvider
*/
function testMaximumUploadSize($size, $unit, $res)
{
$this->assertEquals(
"(" . __('Max: ') . $res . $unit . ")",
PMA\libraries\Util::getFormattedMaximumUploadSize($size)
);
}
}

View File

@ -0,0 +1,104 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
** Test for PMA\libraries\Util::getIcon() from Util.php
*
* @package PhpMyAdmin-test
* @group common.lib-tests
*/
/*
* Include to test.
*/
use PMA\libraries\Theme;
/**
** Test for PMA\libraries\Util::getIcon() from Util.php
*
* @package PhpMyAdmin-test
* @group common.lib-tests
*/
class PMA_GetIcon_Test extends PHPUnit_Framework_TestCase
{
/**
* Set up
*
* @return void
*/
function setup()
{
$_SESSION['PMA_Theme'] = Theme::load('./themes/pmahomme');
}
/**
* Test for getIcon
*
* @return void
*/
function testGetIconWithoutActionLinksMode()
{
$GLOBALS['cfg']['ActionLinksMode'] = 'text';
$this->assertEquals(
'<span class="nowrap"></span>',
PMA\libraries\Util::getIcon('b_comment.png')
);
}
/**
* Test for getIcon
*
* @return void
*/
function testGetIconWithActionLinksMode()
{
$GLOBALS['cfg']['ActionLinksMode'] = 'icons';
$this->assertEquals(
'<span class="nowrap"><img src="themes/dot.gif" title="" alt="" class="icon ic_b_comment" /></span>',
PMA\libraries\Util::getIcon('b_comment.png')
);
}
/**
* Test for getIcon
*
* @return void
*/
function testGetIconAlternate()
{
$GLOBALS['cfg']['ActionLinksMode'] = 'icons';
$alternate_text = 'alt_str';
$this->assertEquals(
'<span class="nowrap"><img src="themes/dot.gif" title="'
. $alternate_text . '" alt="' . $alternate_text
. '" class="icon ic_b_comment" /></span>',
PMA\libraries\Util::getIcon('b_comment.png', $alternate_text)
);
}
/**
* Test for getIcon
*
* @return void
*/
function testGetIconWithForceText()
{
$GLOBALS['cfg']['ActionLinksMode'] = 'icons';
$alternate_text = 'alt_str';
// Here we are checking for an icon embedded inside a span (i.e not a menu
// bar icon
$this->assertEquals(
'<span class="nowrap"><img src="themes/dot.gif" title="'
. $alternate_text . '" alt="' . $alternate_text
. '" class="icon ic_b_comment" />&nbsp;' . $alternate_text . '</span>',
PMA\libraries\Util::getIcon('b_comment.png', $alternate_text, true, false)
);
}
}

View File

@ -0,0 +1,275 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
** Test for PMA\libraries\Util::getRadioFields from Util.php
*
* @package PhpMyAdmin-test
* @group common.lib-tests
*/
/*
* Include to test.
*/
/**
** Test for PMA\libraries\Util::getRadioFields from Util.php
*
* @package PhpMyAdmin-test
* @group common.lib-tests
*/
class PMA_GetRadioFieldsTest extends PHPUnit_Framework_TestCase
{
/**
* Test for getRadioFields
*
* @return void
*/
function testGetRadioFieldsEmpty()
{
$name = "test_display_radio";
$choices = array();
$this->assertEquals(
PMA\libraries\Util::getRadioFields($name, $choices),
""
);
}
/**
* Test for getRadioFields
*
* @return void
*/
function testGetRadioFields()
{
$name = "test_display_radio";
$choices = array('value_1'=>'choice_1', 'value_2'=>'choice_2');
$out = "";
foreach ($choices as $choice_value => $choice_label) {
$html_field_id = $name . '_' . $choice_value;
$out .= '<input type="radio" name="' . $name . '" id="' . $html_field_id
. '" value="' . htmlspecialchars($choice_value) . '"';
$out .= ' />' . "\n";
$out .= '<label for="' . $html_field_id . '">' . $choice_label
. '</label>';
$out .= '<br />';
$out .= "\n";
}
$this->assertEquals(
PMA\libraries\Util::getRadioFields($name, $choices),
$out
);
}
/**
* Test for getRadioFields
*
* @return void
*/
function testGetRadioFieldsWithChecked()
{
$name = "test_display_radio";
$choices = array('value_1'=>'choice_1', 'value_2'=>'choice_2');
$checked_choice = "value_2";
$out = "";
foreach ($choices as $choice_value => $choice_label) {
$html_field_id = $name . '_' . $choice_value;
$out .= '<input type="radio" name="' . $name . '" id="' . $html_field_id
. '" value="' . htmlspecialchars($choice_value) . '"';
if ($choice_value == $checked_choice) {
$out .= ' checked="checked"';
}
$out .= ' />' . "\n";
$out .= '<label for="' . $html_field_id . '">' . $choice_label
. '</label>';
$out .= '<br />';
$out .= "\n";
}
$this->assertEquals(
PMA\libraries\Util::getRadioFields(
$name, $choices, $checked_choice
),
$out
);
}
/**
* Test for getRadioFields
*
* @return void
*/
function testGetRadioFieldsWithCheckedWithClass()
{
$name = "test_display_radio";
$choices = array('value_1'=>'choice_1', 'value_2'=>'choice_2');
$checked_choice = "value_2";
$class = "test_class";
$out = "";
foreach ($choices as $choice_value => $choice_label) {
$html_field_id = $name . '_' . $choice_value;
$out .= '<div class="' . $class . '">';
$out .= '<input type="radio" name="' . $name . '" id="' . $html_field_id
. '" value="' . htmlspecialchars($choice_value) . '"';
if ($choice_value == $checked_choice) {
$out .= ' checked="checked"';
}
$out .= ' />' . "\n";
$out .= '<label for="' . $html_field_id . '">' . $choice_label
. '</label>';
$out .= '<br />';
$out .= '</div>';
$out .= "\n";
}
$this->assertEquals(
PMA\libraries\Util::getRadioFields(
$name, $choices, $checked_choice, true, false, $class
),
$out
);
}
/**
* Test for getRadioFields
*
* @return void
*/
function testGetRadioFieldsWithoutBR()
{
$name = "test_display_radio";
$choices = array('value_1'=>'choice_1', 'value&_&lt;2&gt;'=>'choice_2');
$checked_choice = "choice_2";
$out = "";
foreach ($choices as $choice_value => $choice_label) {
$html_field_id = $name . '_' . $choice_value;
$out .= '<input type="radio" name="' . $name . '" id="' . $html_field_id
. '" value="' . htmlspecialchars($choice_value) . '"';
if ($choice_value == $checked_choice) {
$out .= ' checked="checked"';
}
$out .= ' />' . "\n";
$out .= '<label for="' . $html_field_id . '">' . $choice_label
. '</label>';
$out .= "\n";
}
$this->assertEquals(
PMA\libraries\Util::getRadioFields(
$name, $choices, $checked_choice, false
),
$out
);
}
/**
* Test for getRadioFields
*
* @return void
*/
function testGetRadioFieldsEscapeLabelEscapeLabel()
{
$name = "test_display_radio";
$choices = array('value_1'=>'choice_1', 'value_&2'=>'choice&_&lt;2&gt;');
$checked_choice = "value_2";
$out = "";
foreach ($choices as $choice_value => $choice_label) {
$html_field_id = $name . '_' . $choice_value;
$out .= '<input type="radio" name="' . $name . '" id="' . $html_field_id
. '" value="' . htmlspecialchars($choice_value) . '"';
if ($choice_value == $checked_choice) {
$out .= ' checked="checked"';
}
$out .= ' />' . "\n";
$out .= '<label for="' . $html_field_id . '">'
. htmlspecialchars($choice_label) . '</label>';
$out .= '<br />';
$out .= "\n";
}
$this->assertEquals(
PMA\libraries\Util::getRadioFields(
$name, $choices, $checked_choice, true, true
),
$out
);
}
/**
* Test for getRadioFields
*
* @return void
*/
function testGetRadioFieldsEscapeLabelNotEscapeLabel()
{
$name = "test_display_radio";
$choices = array('value_1'=>'choice_1', 'value_&2'=>'choice&_&lt;2&gt;');
$checked_choice = "value_2";
$out = "";
foreach ($choices as $choice_value => $choice_label) {
$html_field_id = $name . '_' . $choice_value;
$out .= '<input type="radio" name="' . $name . '" id="' . $html_field_id
. '" value="' . htmlspecialchars($choice_value) . '"';
if ($choice_value == $checked_choice) {
$out .= ' checked="checked"';
}
$out .= ' />' . "\n";
$out .= '<label for="' . $html_field_id . '">' . $choice_label
. '</label>';
$out .= '<br />';
$out .= "\n";
}
$this->assertEquals(
PMA\libraries\Util::getRadioFields(
$name, $choices, $checked_choice, true, false
),
$out
);
}
/**
* Test for getRadioFields
*
* @return void
*/
function testGetRadioFieldsEscapeLabelEscapeLabelWithClass()
{
$name = "test_display_radio";
$choices = array('value_1'=>'choice_1', 'value_&2'=>'choice&_&lt;2&gt;');
$checked_choice = "value_2";
$class = "test_class";
$out = "";
foreach ($choices as $choice_value => $choice_label) {
$html_field_id = $name . '_' . $choice_value;
$out .= '<div class="' . $class . '">';
$out .= '<input type="radio" name="' . $name . '" id="' . $html_field_id
. '" value="' . htmlspecialchars($choice_value) . '"';
if ($choice_value == $checked_choice) {
$out .= ' checked="checked"';
}
$out .= ' />' . "\n";
$out .= '<label for="' . $html_field_id . '">'
. htmlspecialchars($choice_label) . '</label>';
$out .= '<br />';
$out .= '</div>';
$out .= "\n";
}
$this->assertEquals(
PMA\libraries\Util::getRadioFields(
$name, $choices, $checked_choice, true, true, $class
),
$out
);
}
}

View File

@ -0,0 +1,60 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
** Test for PMA\libraries\Util::getTitleForTarget from common.lib
*
* @package PhpMyAdmin-test
* @group common.lib-tests
*/
/*
* Include to test.
*/
/**
** Test for PMA\libraries\Util::getTitleForTarget from common.lib
*
* @package PhpMyAdmin-test
* @group common.lib-tests
*/
class PMA_GetTitleForTarget_Test extends PHPUnit_Framework_TestCase
{
/**
* Data provider for testGetTitleForTarget
*
* @return array
*/
function dataProvider()
{
return array(
array('tbl_structure.php', __('Structure')),
array('tbl_sql.php', __('SQL'),),
array('tbl_select.php', __('Search'),),
array('tbl_change.php', __('Insert')),
array('sql.php', __('Browse')),
array('db_structure.php', __('Structure')),
array('db_sql.php', __('SQL')),
array('db_search.php', __('Search')),
array('db_operations.php', __('Operations')),
);
}
/**
* Test for
*
* @param string $target Target
* @param array $result Expected value
*
* @return void
*
* @dataProvider dataProvider
*/
function testGetTitleForTarget($target, $result)
{
$this->assertEquals(
$result, PMA\libraries\Util::getTitleForTarget($target)
);
}
}

View File

@ -0,0 +1,126 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* Test for generating localised date or timespan expression
*
* @package PhpMyAdmin-test
* @group common.lib-tests
*/
/*
* Include to test.
*/
/**
* Test for generating localised date or timespan expression
*
* @package PhpMyAdmin-test
* @group common.lib-tests
*/
class PMA_LocalisedDateTimespan_Test extends PHPUnit_Framework_TestCase
{
/**
* temporary variable for globals array
*/
protected $tmpGlobals;
/**
* temporary variable for session array
*/
protected $tmpSession;
/**
* temporary variable for timezone info
*/
protected $tmpTimezone;
/**
* storing globals and session
*
* @return void
*/
public function setUp()
{
$this->tmpGlobals = $GLOBALS;
$this->tmpSession = $_SESSION;
$this->tmpTimezone = date_default_timezone_get();
date_default_timezone_set('Europe/London');
}
/**
* recovering globals and session
*
* @return void
*/
public function tearDown()
{
$GLOBALS = $this->tmpGlobals;
$_SESSION = $this->tmpSession;
date_default_timezone_set($this->tmpTimezone);
}
/**
* data provider for localised date test
*
* @return array
*/
public function localisedDateDataProvider()
{
return array(
array(1227455558, '', 'Nov 23, 2008 at 03:52 PM'),
array(1227455558, '%Y-%m-%d %H:%M:%S %a', '2008-11-23 15:52:38 Sun')
);
}
/**
* localised date test, globals are defined
*
* @param string $a Current timestamp
* @param string $b Format
* @param string $e Expected output
*
* @return void
*
* @dataProvider localisedDateDataProvider
*/
public function testLocalisedDate($a, $b, $e)
{
$this->assertEquals(
$e, PMA\libraries\Util::localisedDate($a, $b)
);
}
/**
* data provider for localised timestamp test
*
* @return array
*/
public function timespanFormatDataProvider()
{
return array(
array(1258, '0 days, 0 hours, 20 minutes and 58 seconds'),
array(821958, '9 days, 12 hours, 19 minutes and 18 seconds')
);
}
/**
* localised timestamp test, globals are defined
*
* @param int $a Timespan in seconds
* @param string $e Expected output
*
* @return void
*
* @dataProvider timespanFormatDataProvider
*/
public function testTimespanFormat($a, $e)
{
$GLOBALS['timespanfmt'] = '%s days, %s hours, %s minutes and %s seconds';
$this->assertEquals(
$e, PMA\libraries\Util::timespanFormat($a)
);
}
}

View File

@ -0,0 +1,133 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* Tests for PMA\libraries\Util::pow() function from Util.php
*
* @package PhpMyAdmin-test
* @group common.lib-tests
*/
/*
* Include to test.
*/
/**
* Tests for PMA\libraries\Util::pow() function from Util.php
*
* @package PhpMyAdmin-test
* @group common.lib-tests
*/
class PMA_Pow_Test extends PHPUnit_Framework_TestCase
{
/**
* Test forpow
*
* @return void
*/
public function testIntOverflow()
{
$this->assertEquals(
'1267650600228229401496703205376',
PMA\libraries\Util::pow(2, 100)
);
}
/**
* Test forpow
*
* @return void
*/
public function testBcpow()
{
if (function_exists('bcpow')) {
$this->assertEquals(
'1267650600228229401496703205376',
PMA\libraries\Util::pow(2, 100, 'bcpow')
);
} else {
$this->markTestSkipped('function bcpow() does not exist');
}
}
/**
* Test forpow
*
* @return void
*/
public function testGmppow()
{
if (function_exists('gmp_pow')) {
$this->assertEquals(
'1267650600228229401496703205376',
PMA\libraries\Util::pow(2, 100, 'gmp_pow')
);
} else {
$this->markTestSkipped('function gmp_pow() does not exist');
}
}
/**
* Test forpow
*
* @return void
*/
public function testNegativeExp()
{
$this->assertEquals(
0.25,
PMA\libraries\Util::pow(2, -2)
);
}
/**
* Test forpow
*
* @return void
*/
public function testNegativeExpPow()
{
if (function_exists('pow')) {
$this->assertEquals(
0.25,
PMA\libraries\Util::pow(2, -2, 'pow')
);
} else {
$this->markTestSkipped('function pow() does not exist');
}
}
/**
* Test forpow
*
* @return void
*/
public function testNegativeExpBcpow()
{
if (function_exists('bcpow')) {
$this->assertEquals(
false,
PMA\libraries\Util::pow(2, -2, 'bcpow')
);
} else {
$this->markTestSkipped('function bcpow() does not exist');
}
}
/**
* Test forpow
*
* @return void
*/
public function testNegativeExpGmppow()
{
if (function_exists('gmp_pow')) {
$this->assertEquals(
false,
PMA\libraries\Util::pow(2, -2, 'gmp_pow')
);
} else {
$this->markTestSkipped('function gmp_pow() does not exist');
}
}
}

View File

@ -0,0 +1,58 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* Test PMA\libraries\Util::printableBitValue function
*
* @package PhpMyAdmin-test
* @group common.lib-tests
*/
/*
* Include to test.
*/
/**
* Test PMA\libraries\Util::printableBitValue function
*
* @package PhpMyAdmin-test
* @group common.lib-tests
*/
class PMA_PrintableBitValueTest extends PHPUnit_Framework_TestCase
{
/**
* data provider for printable bit value test
*
* @return array
*/
public function printableBitValueDataProvider()
{
return array(
array(
'20131009',
64,
'0000000000000000000000000000000000000001001100110010110011000001'
),
array('5', 32, '00000000000000000000000000000101')
);
}
/**
* test for generating string contains printable bit value of selected data
*
* @param integer $a Value
* @param int $b Length
* @param string $e Expected output
*
* @return void
*
* @dataProvider printableBitValueDataProvider
*/
public function testPrintableBitValue($a, $b, $e)
{
$this->assertEquals(
$e, PMA\libraries\Util::printableBitValue($a, $b)
);
}
}

View File

@ -0,0 +1,186 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* Test for quoting, slashing/backslashing
*
* @package PhpMyAdmin-test
* @group common.lib-tests
*/
/*
* Include to test.
*/
/**
* Test for quoting, slashing/backslashing
*
* @package PhpMyAdmin-test
* @group common.lib-tests
*/
class PMA_QuotingSlashing_Test extends PHPUnit_Framework_TestCase
{
/**
* data provider for PMA\libraries\Util::unQuote test
*
* @return array
*/
public function unQuoteProvider()
{
return array(
array('"test\'"', "test'"),
array("'test''", "test'"),
array("`test'`", "test'"),
array("'test'test", "'test'test")
);
}
/**
* PMA\libraries\Util::unQuote test
*
* @param string $param String
* @param string $expected Expected output
*
* @return void
*
* @dataProvider unQuoteProvider
*/
public function testUnQuote($param, $expected)
{
$this->assertEquals(
$expected, PMA\libraries\Util::unQuote($param)
);
}
/**
* data provider for PMA\libraries\Util::unQuote test with chosen quote
*
* @return array
*/
public function unQuoteSelectedProvider()
{
return array(
array('"test\'"', "test'"),
array("'test''", "'test''"),
array("`test'`", "`test'`"),
array("'test'test", "'test'test")
);
}
/**
* PMA\libraries\Util::unQuote test with chosen quote
*
* @param string $param String
* @param string $expected Expected output
*
* @return void
*
* @dataProvider unQuoteSelectedProvider
*/
public function testUnQuoteSelectedChar($param, $expected)
{
$this->assertEquals(
$expected, PMA\libraries\Util::unQuote($param, '"')
);
}
/**
* data provider for backquote test
*
* @return array
*/
public function backquoteDataProvider()
{
return array(
array('0', '`0`'),
array('test', '`test`'),
array('te`st', '`te``st`'),
array(
array('test', 'te`st', '', '*'),
array('`test`', '`te``st`', '', '*')
)
);
}
/**
* backquote test with different param $do_it (true, false)
*
* @param string $a String
* @param string $b Expected output
*
* @return void
*
* @dataProvider backquoteDataProvider
*/
public function testBackquote($a, $b)
{
// Test bypass quoting (used by dump functions)
$this->assertEquals($a, PMA\libraries\Util::backquote($a, false));
// Test backquote
$this->assertEquals($b, PMA\libraries\Util::backquote($a));
}
/**
* data provider for backquoteCompat test
*
* @return array
*/
public function backquoteCompatDataProvider()
{
return array(
array('0', '"0"'),
array('test', '"test"'),
array('te`st', '"te`st"'),
array(
array('test', 'te`st', '', '*'),
array('"test"', '"te`st"', '', '*')
)
);
}
/**
* backquoteCompat test with different param $compatibility (NONE, MSSQL)
*
* @param string $a String
* @param string $b Expected output
*
* @return void
*
* @dataProvider backquoteCompatDataProvider
*/
public function testbackquoteCompat($a, $b)
{
// Test bypass quoting (used by dump functions)
$this->assertEquals($a, PMA\libraries\Util::backquoteCompat($a, 'NONE', false));
// Run tests in MSSQL compatibility mode
// Test bypass quoting (used by dump functions)
$this->assertEquals($a, PMA\libraries\Util::backquoteCompat($a, 'MSSQL', false));
// Test backquote
$this->assertEquals($b, PMA\libraries\Util::backquoteCompat($a, 'MSSQL'));
}
/**
* backquoteCompat test with forbidden words
*
* @return void
*/
public function testBackquoteForbidenWords()
{
foreach (SqlParser\Context::$KEYWORDS as $keyword => $type) {
if ($type & SqlParser\Token::FLAG_KEYWORD_RESERVED) {
$this->assertEquals(
"`" . $keyword . "`",
PMA\libraries\Util::backquote($keyword, false)
);
} else {
$this->assertEquals(
$keyword,
PMA\libraries\Util::backquote($keyword, false)
);
}
}
}
}

View File

@ -0,0 +1,51 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
** Test for PMA\libraries\Util::showDocu from Util.php
*
* @package PhpMyAdmin-test
* @group common.lib-tests
*/
/*
* Include to test.
*/
use PMA\libraries\Theme;
/**
** Test for PMA\libraries\Util::showDocu from Util.php
*
* @package PhpMyAdmin-test
* @group common.lib-tests
*/
class PMA_ShowDocu_Test extends PHPUnit_Framework_TestCase
{
/**
* Set up
*
* @return void
*/
function setup()
{
$_SESSION['PMA_Theme'] = Theme::load('./themes/pmahomme');
$GLOBALS['server'] = '99';
$GLOBALS['cfg']['ServerDefault'] = 1;
}
/**
* Test for showDocu
*
* @return void
*/
function testShowDocu()
{
$this->assertEquals(
'<a href="./url.php?url=https%3A%2F%2Fdocs.phpmyadmin.net%2Fen%2Flatest%2Fpage.html%23anchor" target="documentation"><img src="themes/dot.gif" title="Documentation" alt="Documentation" class="icon ic_b_help" /></a>',
PMA\libraries\Util::showDocu('page', 'anchor')
);
}
}

View File

@ -0,0 +1,80 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
** Test for PMA\libraries\Util::getMessage from common.lib
*
* @package PhpMyAdmin-test
* @group common.lib-tests
*/
const PMA_IS_WINDOWS = false;
/*
* Include to test.
*/
require_once 'libraries/js_escape.lib.php';
/**
** Test for PMA\libraries\Util::getMessage from common.lib
*
* @package PhpMyAdmin-test
* @group common.lib-tests
*/
class PMA_ShowMessage_Test extends PHPUnit_Framework_TestCase
{
/**
* Set up
*
* @return void
*/
function setUp()
{
global $cfg;
if (! defined('VERSION_CHECK_DEFAULT')) {
define('VERSION_CHECK_DEFAULT', 1);
}
include 'libraries/config.default.php';
}
/**
* Test for getMessage
*
* @return void
*/
function testShowMessageNotAjax()
{
global $cfg;
$GLOBALS['is_ajax_request'] = true;
$cfg['Server']['DisableIS'] = false;
$GLOBALS['table'] = 'tbl';
$GLOBALS['db'] = 'db';
$GLOBALS['sql_query'] = "SELECT * FROM tblPatient ";
$this->expectOutputString(
"<div class=\"result_query\" align=\"\">
<div class=\"notice\">msg</div><code class=\"sql\"><span class=\"syntax\"><span class=\"inner_sql\"><a href=\"./url.php?url=http%3A%2F%2Fdev.mysql.com%2Fdoc%2Frefman%2F5.0%2Fen%2Fselect.html&amp;server=server&amp;lang=en&amp;token=647a62ad301bf9025e3b13bc7caa02cb\" target=\"mysql_doc\"><span class=\"syntax_alpha syntax_alpha_reservedWord\">SELECT</span></a> <span class=\"syntax_punct\">*</span> <br /><span class=\"syntax_alpha syntax_alpha_reservedWord\">FROM</span> <span class=\"syntax_alpha syntax_alpha_identifier\">tblPatient</span></span></span></code><div class=\"tools\"><form action=\"sql.php\" method=\"post\"><input type=\"hidden\" name=\"db\" value=\"db\" /><input type=\"hidden\" name=\"table\" value=\"tbl\" /><input type=\"hidden\" name=\"server\" value=\"server\" /><input type=\"hidden\" name=\"lang\" value=\"en\" /><input type=\"hidden\" name=\"token\" value=\"647a62ad301bf9025e3b13bc7caa02cb\" /><input type=\"hidden\" name=\"sql_query\" value=\"SELECT * FROM tblPatient \" /></form><script type=\"text/javascript\">
//<![CDATA[
$('.tools form').last().after('[<a href=\"#\" title=\"Inline edit of this query\" class=\"inline_edit_sql\">Inline</a>]');
//]]>
</script> [
<a href=\"tbl_sql.php?db=db&amp;table=tbl&amp;sql_query=SELECT+%2A+FROM+tblPatient+&amp;show_query=1&amp;server=server&amp;lang=en&amp;token=647a62ad301bf9025e3b13bc7caa02cb#querybox\" >Edit</a>
] [
<a href=\"import.php?db=db&amp;table=tbl&amp;sql_query=EXPLAIN+SELECT+%2A+FROM+tblPatient+&amp;server=server&amp;lang=en&amp;token=647a62ad301bf9025e3b13bc7caa02cb\" >Explain SQL</a>
] [
<a href=\"import.php?db=db&amp;table=tbl&amp;sql_query=SELECT+%2A+FROM+tblPatient+&amp;show_query=1&amp;show_as_php=1&amp;server=server&amp;lang=en&amp;token=647a62ad301bf9025e3b13bc7caa02cb\" >Create PHP code</a>
] [
<a href=\"import.php?db=db&amp;table=tbl&amp;sql_query=SELECT+%2A+FROM+tblPatient+&amp;show_query=1&amp;server=server&amp;lang=en&amp;token=647a62ad301bf9025e3b13bc7caa02cb\" >Refresh</a>
]</div></div>"
);
echo PMA\libraries\Util::getMessage("msg");
//$this->assertEquals("", PMA\libraries\Util::getMessage("msg"));
$this->assertTrue(true);
}
}

View File

@ -0,0 +1,56 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
** Test for PMA\libraries\Util::showPHPDocu from Util.php
*
* @package PhpMyAdmin-test
* @group common.lib-tests
*/
/*
* Include to test.
*/
use PMA\libraries\Theme;
/**
** Test for PMA\libraries\Util::showPHPDocu from Util.php
*
* @package PhpMyAdmin-test
* @group common.lib-tests
*/
class PMA_ShowPHPDocu_Test extends PHPUnit_Framework_TestCase
{
/**
* Set up
*
* @return void
*/
function setup()
{
$_SESSION['PMA_Theme'] = Theme::load('./themes/pmahomme');
$GLOBALS['server'] = 99;
$GLOBALS['cfg']['ServerDefault'] = 0;
}
/**
* Test for showPHPDocu
*
* @return void
*/
function testShowPHPDocu()
{
$target = "docu";
$lang = _pgettext('PHP documentation language', 'en');
$expected = '<a href="./url.php?url=https%3A%2F%2Fphp.net%2Fmanual%2F' . $lang
. '%2F' . $target . '" target="documentation">'
. '<img src="themes/dot.gif" title="' . __('Documentation') . '" alt="'
. __('Documentation') . '" class="icon ic_b_help" /></a>';
$this->assertEquals(
$expected, PMA\libraries\Util::showPHPDocu($target)
);
}
}

View File

@ -0,0 +1,171 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* Test for several string operations
*
* @package PhpMyAdmin-test
* @group common.lib-tests
*/
/*
* Include to test.
*/
/**
* Test for several string operations
*
* @package PhpMyAdmin-test
* @group common.lib-tests
*/
class PMA_StringOperations_Test extends PHPUnit_Framework_TestCase
{
/**
* temporary variable for globals array
*/
protected $tmpGlobals;
/**
* temporary variable for session array
*/
protected $tmpSession;
/**
* storing globals and session
*
* @return void
*/
public function setUp()
{
global $GLOBALS, $_SESSION;
$this->tmpGlobals = $GLOBALS;
$this->tmpSession = $_SESSION;
}
/**
* data provider for PMA\libraries\Util::flipstring test
*
* @return array
*/
public function flipStringDataProvider()
{
return array(
array('test', "t<br />\ne<br />\ns<br />\nt"),
array(
'te&nbsp;;st',
"t<br />\ne<br />\n&nbsp;<br />\n;<br />\ns<br />\nt"
)
);
}
/**
* test of changing string from horizontal to vertical orientation
*
* @param string $a String
* @param string $e Expected output
*
* @return void
*
* @dataProvider flipStringDataProvider
*/
public function testFlipString($a, $e)
{
$this->assertEquals($e, PMA\libraries\Util::flipstring($a));
}
/**
* data provider for PMA\libraries\Util::userDir test
*
* @return array
*/
public function userDirDataProvider()
{
return array(
array('/var/pma_tmp/%u/', "/var/pma_tmp/root/"),
array('/home/%u/pma', "/home/root/pma/")
);
}
/**
* test of generating user dir, globals are defined
*
* @param string $a String
* @param string $e Expected output
*
* @return void
*
* @dataProvider userDirDataProvider
*/
public function testUserDirString($a, $e)
{
$GLOBALS['cfg']['Server']['user'] = 'root';
$this->assertEquals($e, PMA\libraries\Util::userDir($a));
}
/**
* data provider for replace binary content test
*
* @return array
*/
public function replaceBinaryContentsDataProvider()
{
return array(
array("\x000", '\00'),
array("\x08\x0a\x0d\x1atest", '\b\n\r\Ztest'),
array("\ntest", '\ntest')
);
}
/**
* replace binary contents test
*
* @param string $a String
* @param string $e Expected output
*
* @return void
*
* @dataProvider replaceBinaryContentsDataProvider
*/
public function testReplaceBinaryContents($a, $e)
{
$this->assertEquals(
$e, PMA\libraries\Util::replaceBinaryContents($a)
);
}
/**
* data provider for duplicate first newline test
*
* @return array
*/
public function duplicateFirstNewlineDataProvider()
{
return array(
array('test', 'test'),
array("\r\ntest", "\n\r\ntest"),
array("\ntest", "\ntest"),
array("\n\r\ntest", "\n\r\ntest")
);
}
/**
* duplicate first newline test
*
* @param string $a String
* @param string $e Expected output
*
* @return void
*
* @dataProvider duplicateFirstNewlineDataProvider
*/
public function testDuplicateFirstNewline($a, $e)
{
$this->assertEquals(
$e, PMA\libraries\Util::duplicateFirstNewline($a)
);
}
}

View File

@ -0,0 +1,35 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
** Test for PMA\libraries\Util::unsupportedDatatypes from common.lib
*
* @package PhpMyAdmin-test
* @group common.lib-tests
*/
/*
* Include to test.
*/
/**
** Test for PMA\libraries\Util::unsupportedDatatypes from common.lib
*
* @package PhpMyAdmin-test
* @group common.lib-tests
*/
class PMA_UnsupportedDatatypes_Test extends PHPUnit_Framework_TestCase
{
/**
* Test for unsupportedDatatypes
*
* @return void
*/
function testNotSupportedDataTypes()
{
$no_support_types = array();
$this->assertEquals(
$no_support_types, PMA\libraries\Util::unsupportedDatatypes()
);
}
}

View File

@ -0,0 +1,87 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* Test PMA\libraries\Util::whichCrlf function
*
* @package PhpMyAdmin-test
* @group common.lib-tests
*/
/*
* Include to test.
*/
/**
* Test PMA\libraries\Util::whichCrlf function
*
* @package PhpMyAdmin-test
* @group common.lib-tests
*/
class PMA_WhichCrlf_Test extends PHPUnit_Framework_TestCase
{
/**
* Test for whichCrlf
*
* @return void
*
* @using runkit pecl extension
* if not define PMA_USR_OS, then define it as Win
* if installed runkit, then constant will not change
*/
public function testWhichCrlf()
{
if (PMA_HAS_RUNKIT && defined('PMA_USR_OS')) {
$pma_usr_os = PMA_USR_OS;
}
if (defined('PMA_USR_OS') && !PMA_HAS_RUNKIT) {
if (PMA_USR_OS == 'Win') {
$this->assertEquals(
"\r\n", PMA\libraries\Util::whichCrlf()
);
} else {
$this->assertEquals(
"\n", PMA\libraries\Util::whichCrlf()
);
}
$this->markTestIncomplete('Cannot redefine constant');
} else {
if (PMA_HAS_RUNKIT) {
if (!defined('PMA_USR_OS')) {
define('PMA_USR_OS', 'Linux');
} else {
runkit_constant_redefine('PMA_USR_OS', 'Linux');
}
$this->assertEquals(
"\n", PMA\libraries\Util::whichCrlf()
);
}
if (PMA_HAS_RUNKIT) {
runkit_constant_redefine('PMA_USR_OS', 'Win');
} else {
define('PMA_USR_OS', 'Win');
}
$this->assertEquals(
"\r\n", PMA\libraries\Util::whichCrlf()
);
}
if (PMA_HAS_RUNKIT) {
if (isset($pma_usr_os)) {
runkit_constant_redefine('PMA_USR_OS', 'Win');
} else {
runkit_constant_remove('PMA_USR_OS');
}
}
}
}