From ccbc80228a7b2349529914aeb3169d2ba3136b65 Mon Sep 17 00:00:00 2001 From: Marc Delisle Date: Sun, 30 Nov 2008 11:49:44 +0000 Subject: [PATCH] new unit tests, thanks to Michal Biniek --- ChangeLog | 2 +- test/AllTests.php | 32 ++-- test/PMA_cache_test.php | 104 +++++++++++++ test/PMA_escapeMySqlWildcards_test.php | 74 +++------- test/PMA_foreignKeySupported_test.php | 48 ++++++ test/PMA_formatNumberByteDown_test.php | 121 ++++++++++++++++ test/PMA_localisedDateTimespan_test.php | 106 ++++++++++++++ test/PMA_printableBitValue_test.php | 48 ++++++ test/PMA_quoting_slashing_test.php | 112 ++++++++++++++ test/PMA_showHint_test.php | 185 ++++++++++++++++++++++++ test/PMA_stringOperations_test.php | 135 +++++++++++++++++ 11 files changed, 906 insertions(+), 61 deletions(-) create mode 100644 test/PMA_cache_test.php create mode 100644 test/PMA_foreignKeySupported_test.php create mode 100644 test/PMA_formatNumberByteDown_test.php create mode 100644 test/PMA_localisedDateTimespan_test.php create mode 100644 test/PMA_printableBitValue_test.php create mode 100644 test/PMA_quoting_slashing_test.php create mode 100644 test/PMA_showHint_test.php create mode 100644 test/PMA_stringOperations_test.php diff --git a/ChangeLog b/ChangeLog index 4e2dc5964..231be08ca 100644 --- a/ChangeLog +++ b/ChangeLog @@ -18,7 +18,7 @@ $HeadURL: https://phpmyadmin.svn.sourceforge.net/svnroot/phpmyadmin/trunk/phpMyA - bug #2355925 [display] properly update tooltips in navigation frame - bug #2355923 [core] do not use ctype if it is not available - bug #2356433 [display] HeaderFlipType "fake" problems, - thanks to Michal Binied + thanks to Michal Biniek 3.1.0.0 (2008-11-28) + [auth] Support for Swekey hardware authentication, diff --git a/test/AllTests.php b/test/AllTests.php index f2a8eccbc..ec2251a14 100644 --- a/test/AllTests.php +++ b/test/AllTests.php @@ -15,9 +15,7 @@ if (! defined('PMA_MAIN_METHOD')) { chdir('..'); } -/** - * required to not die() in some libraries - */ +// required to not die() in some libraries define('PHPMYADMIN', true); /** @@ -38,11 +36,15 @@ require_once './test/PMA_STR_sub_test.php'; require_once './test/PMA_generateCommonUrl_test.php'; require_once './test/PMA_blowfish_test.php'; require_once './test/PMA_escapeMySqlWildcards_test.php'; +require_once './test/PMA_showHint_test.php'; +require_once './test/PMA_formatNumberByteDown_test.php'; +require_once './test/PMA_localisedDateTimespan_test.php'; +require_once './test/PMA_cache_test.php'; +require_once './test/PMA_quoting_slashing_test.php'; +require_once './test/PMA_stringOperations_test.php'; +require_once './test/PMA_printableBitValue_test.php'; +require_once './test/PMA_foreignKeySupported_test.php'; -/** - * Class to run all tests. - * @package phpMyAdmin-test - */ class AllTests { public static function main() @@ -68,15 +70,25 @@ class AllTests $suite->addTestSuite('PMA_transformation_getOptions_test'); $suite->addTestSuite('PMA_STR_sub_test'); $suite->addTestSuite('PMA_generate_common_url_test'); - //$suite->addTestSuite('PMA_arrayWalkRecursive_test'); $suite->addTestSuite('PMA_blowfish_test'); + $suite->addTestSuite('PMA_escapeMySqlWildcards_test'); + $suite->addTestSuite('PMA_showHint_test'); + $suite->addTestSuite('PMA_formatNumberByteDown_test'); + $suite->addTestSuite('PMA_localisedDateTimespan_test'); + $suite->addTestSuite('PMA_cache_test'); + $suite->addTestSuite('PMA_quoting_slashing_test'); + $suite->addTestSuite('PMA_stringOperations_test'); + $suite->addTestSuite('PMA_printableBitValue_test'); + $suite->addTestSuite('PMA_foreignKeySupported_test'); return $suite; } } - +// Please clarify the reason of this section; it has for effect +// of running the tests a second time. +/* if (PMA_MAIN_METHOD == 'AllTests::main') { echo '
';
     AllTests::main();
     echo '
'; -} +}*/ ?> diff --git a/test/PMA_cache_test.php b/test/PMA_cache_test.php new file mode 100644 index 000000000..86f065cb2 --- /dev/null +++ b/test/PMA_cache_test.php @@ -0,0 +1,104 @@ + + * @package phpMyAdmin-test + * @version $Id: PMA_cache_test.php + */ + +/** + * Tests core. + */ +require_once 'PHPUnit/Framework.php'; + +/** + * Include to test. + */ +require_once './libraries/common.lib.php'; + +/** + * Test cache. + * + */ +class PMA_cache_test extends PHPUnit_Framework_TestCase +{ + + /** + * temporary variable for globals array + */ + + protected $tmpGlobals; + + /** + * temporary variable for session array + */ + + protected $tmpSession; + + /** + * storing globals and session + */ + public function setUp() { + + $this->tmpGlobals = $GLOBALS; + $this->tmpSession = $_SESSION; + + } + + /** + * cacheExists test + */ + + public function testCacheExists() { + $GLOBALS['server'] = 'server'; + $_SESSION['cache']['server_server'] = array('test_data'=>1, 'test_data_2'=>2); + + $this->assertTrue(PMA_cacheExists('test_data', true)); + $this->assertTrue(PMA_cacheExists('test_data_2', 'server')); + $this->assertFalse(PMA_cacheExists('fake_data_2', true)); + } + + /** + * cacheGet test + */ + + public function testCacheGet() { + $GLOBALS['server'] = 'server'; + $_SESSION['cache']['server_server'] = array('test_data'=>1, 'test_data_2'=>2); + + $this->assertNotNull(PMA_cacheGet('test_data', true)); + $this->assertNotNull(PMA_cacheGet('test_data_2', 'server')); + $this->assertNull(PMA_cacheGet('fake_data_2', true)); + } + + /** + * cacheSet test + */ + + public function testCacheSet() { + $GLOBALS['server'] = 'server'; + $_SESSION['cache']['server_server'] = array('test_data'=>1, 'test_data_2'=>2); + + PMA_cacheSet('test_data', 5, true); + $this->assertEquals(5, $_SESSION['cache']['server_server']['test_data']); + PMA_cacheSet('test_data_3', 3, true); + $this->assertEquals(3, $_SESSION['cache']['server_server']['test_data_3']); + } + + /** + * cacheUnset test + */ + + public function testCacheUnSet() { + $GLOBALS['server'] = 'server'; + $_SESSION['cache']['server_server'] = array('test_data'=>1, 'test_data_2'=>2); + + PMA_cacheUnset('test_data', true); + $this->assertNull($_SESSION['cache']['server_server']['test_data']); + PMA_cacheUnset('test_data_2', true); + $this->assertNull($_SESSION['cache']['server_server']['test_data_2']); + } +} +?> diff --git a/test/PMA_escapeMySqlWildcards_test.php b/test/PMA_escapeMySqlWildcards_test.php index 229e0161c..54273fcd8 100644 --- a/test/PMA_escapeMySqlWildcards_test.php +++ b/test/PMA_escapeMySqlWildcards_test.php @@ -21,67 +21,41 @@ require_once './libraries/common.lib.php'; /** * Test MySQL escaping. * - * @package phpMyAdmin-test */ class PMA_escapeMySqlWildcards_test extends PHPUnit_Framework_TestCase { - /** - * PMA_escape_mysql_wildcards tests + public function escapeDataProvider() { + return array( + array('\_test', '_test'), + array('\_\\', '_\\'), + array('\\_\%', '_%'), + array('\\\_', '\_'), + array('\\\_\\\%', '\_\%'), + array('\_\\%\_\_\%', '_%__%'), + array('\%\_', '%_'), + array('\\\%\\\_', '\%\_') + ); + } + + /** + * PMA_escape_mysql_wildcards tests + * @dataProvider escapeDataProvider */ - public function testEscape_1() + public function testEscape($a, $b) { - $this->assertEquals('\_test', PMA_escape_mysql_wildcards('_test')); + $this->assertEquals($a, PMA_escape_mysql_wildcards($b)); } - public function testEscape_2() - { - $this->assertEquals('\_\\', PMA_escape_mysql_wildcards('_\\')); - } + /** + * PMA_unescape_mysql_wildcards tests + * @dataProvider escapeDataProvider + */ - public function testEscape_3() + public function testUnEscape($a, $b) { - $this->assertEquals('\\_\%', PMA_escape_mysql_wildcards('_%')); - } - - public function testEscape_4() - { - $this->assertEquals('\\\_', PMA_escape_mysql_wildcards('\_')); - } - - public function testEscape_5() - { - $this->assertEquals('\\\_\\\%', PMA_escape_mysql_wildcards('\_\%')); - } - - /** - * PMA_unescape_mysql_wildcards tests - */ - - public function testUnEscape_1() - { - $this->assertEquals('_test', PMA_unescape_mysql_wildcards('\_test')); - } - - public function testUnEscape_2() - { - $this->assertEquals('_%__%', PMA_unescape_mysql_wildcards('\_\\%\_\_\%')); - } - - public function testUnEscape_3() - { - $this->assertEquals('\_', PMA_unescape_mysql_wildcards('\\\_')); - } - - public function testUnEscape_4() - { - $this->assertEquals('%_', PMA_unescape_mysql_wildcards('%\_')); - } - - public function testUnEscape_5() - { - $this->assertEquals('\%\_', PMA_unescape_mysql_wildcards('\\\%\\\_')); + $this->assertEquals($b, PMA_unescape_mysql_wildcards($a)); } } ?> diff --git a/test/PMA_foreignKeySupported_test.php b/test/PMA_foreignKeySupported_test.php new file mode 100644 index 000000000..5ce8ce276 --- /dev/null +++ b/test/PMA_foreignKeySupported_test.php @@ -0,0 +1,48 @@ + + * @package phpMyAdmin-test + * @version $Id$ + */ + +/** + * Tests core. + */ +require_once 'PHPUnit/Framework.php'; + +/** + * Include to test. + */ +require_once './libraries/common.lib.php'; + +/** + * Test supported foreign key. + * + */ +class PMA_foreignKeySupported_test extends PHPUnit_Framework_TestCase +{ + /** + * data provider for foreign key supported test + */ + + public function foreignkeySupportedDataProvider() { + return array( + array('MyISAM', false), + array('innodb', true), + array('pBxT', true) + ); + } + + /** + * foreign key supported test + * @dataProvider foreignkeySupportedDataProvider + */ + + public function testForeignkeySupported($a, $e) { + $this->assertEquals($e, PMA_foreignkey_supported($a)); + } +} +?> diff --git a/test/PMA_formatNumberByteDown_test.php b/test/PMA_formatNumberByteDown_test.php new file mode 100644 index 000000000..d6cea0a92 --- /dev/null +++ b/test/PMA_formatNumberByteDown_test.php @@ -0,0 +1,121 @@ + + * @package phpMyAdmin-test + * @version $Id: PMA_formatNumberByteDown_test.php + */ + +/** + * Tests core. + */ +require_once 'PHPUnit/Framework.php'; + +/** + * Include to test. + */ +require_once './libraries/common.lib.php'; + +/** + * Test formating number and byte. + * + */ +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 + */ + public function setUp() { + + $this->tmpGlobals = $GLOBALS; + $this->tmpSession = $_SESSION; + + } + + /** + * recovering globals and session + */ + public function tearDown() { + + $GLOBALS = $this->tmpGlobals; + $_SESSION = $this->tmpSession; + + } + + /** + * format number data provider + */ + + public function formatNumberDataProvider() { + return array( + array(10, 2, 2, '10,00 '), + array(100, 2, 0, '100 '), + array(100, 2, 2, '0,10 k'), + array(-1000.454, 4, 2, '-1 000,45 '), + array(0.00003, 3, 2, '0,03 m'), + array(0.003, 3, 3, '0,003 '), + array(-0.003, 6, 0, '-3 m'), + array(100.98, 0, 2, '100,98') + ); + } + + /** + * format number test, globals are defined + * @dataProvider formatNumberDataProvider + */ + + public function testFormatNumber($a, $b, $c, $e) { + $GLOBALS['number_thousands_separator'] = ' '; + $GLOBALS['number_decimal_separator'] = ','; + + $this->assertEquals($e, (string)PMA_formatNumber($a, $b, $c, false)); + } + + /** + * format byte down data provider + */ + + public function formatByteDownDataProvider() { + return array( + array(10, 2, 2, array('10', 'B')), + array(100, 2, 0, array('0', 'KB')), + array(100, 3, 0, array('100', 'B')), + array(100, 2, 2, array('0,10', 'KB')), + array(1034, 3, 2, array('1,01', 'KB')), + array(100233, 3, 3, array('97,884', 'KB')), + array(2206451, 1, 2, array('2,10', 'MB')) + ); + } + + /** + * format byte test, globals are defined + * @dataProvider formatByteDownDataProvider + */ + + public function testFormatByteDown($a, $b, $c, $e) { + $GLOBALS['byteUnits'] = array('B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB'); + $GLOBALS['number_thousands_separator'] = ' '; + $GLOBALS['number_decimal_separator'] = ','; + + + $result = PMA_formatByteDown($a, $b, $c); + $result[0] = trim($result[0]); + $this->assertEquals($e, $result); + } +} +?> diff --git a/test/PMA_localisedDateTimespan_test.php b/test/PMA_localisedDateTimespan_test.php new file mode 100644 index 000000000..4218848b8 --- /dev/null +++ b/test/PMA_localisedDateTimespan_test.php @@ -0,0 +1,106 @@ + + * @package phpMyAdmin-test + * @version $Id: PMA_localisedDateTimespan_test.php + */ + +/** + * Tests core. + */ +require_once 'PHPUnit/Framework.php'; + +/** + * Include to test. + */ +require_once './libraries/common.lib.php'; + +/** + * Test localised date or timespan expression. + * + */ +class PMA_localisedDateTimespan_test extends PHPUnit_Framework_TestCase +{ + + /** + * temporary variable for globals array + */ + + protected $tmpGlobals; + + /** + * temporary variable for session array + */ + + protected $tmpSession; + + /** + * storing globals and session + */ + public function setUp() { + + $this->tmpGlobals = $GLOBALS; + $this->tmpSession = $_SESSION; + + } + + /** + * recovering globals and session + */ + public function tearDown() { + + $GLOBALS = $this->tmpGlobals; + $_SESSION = $this->tmpSession; + + } + + /** + * data provider for localised date test + */ + + public function localisedDateDataProvider() { + return array( + array(1227451958, '', 'Nov 23, 2008 at 03:52 PM'), + array(1227451958, '%Y-%m-%d %H:%M:%S %a', '2008-11-23 15:52:38 Sun') + ); + } + + /** + * localised date test, globals are defined + * @dataProvider localisedDateDataProvider + */ + + public function testLocalisedDate($a, $b, $e) { + $GLOBALS['day_of_week'] = array('Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'); + $GLOBALS['month'] = array('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'); + $GLOBALS['datefmt'] = '%B %d, %Y at %I:%M %p'; + + $this->assertEquals($e, PMA_localisedDate($a, $b)); + } + + /** + * data provider for localised timestamp test + */ + + 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 + * @dataProvider timespanFormatDataProvider + */ + + public function testTimespanFormat($a, $e) { + $GLOBALS['timespanfmt'] = '%s days, %s hours, %s minutes and %s seconds'; + + $this->assertEquals($e, PMA_timespanFormat($a)); + } +} +?> diff --git a/test/PMA_printableBitValue_test.php b/test/PMA_printableBitValue_test.php new file mode 100644 index 000000000..86207789b --- /dev/null +++ b/test/PMA_printableBitValue_test.php @@ -0,0 +1,48 @@ + + * @package phpMyAdmin-test + * @version $Id: PMA_printableBitValue_test.php + */ + +/** + * Tests core. + */ +require_once 'PHPUnit/Framework.php'; + +/** + * Include to test. + */ +require_once './libraries/common.lib.php'; + +/** + * Test printableBitValue function. + * + */ +class PMA_printableBitValue_test extends PHPUnit_Framework_TestCase +{ + + /** + * data provider for printable bit value test + */ + + public function printableBitValueDataProvider() { + return array( + array('testtest', 64, '0111010001100101011100110111010001110100011001010111001101110100'), + array('test', 32, '01110100011001010111001101110100') + ); + } + + /** + * test for generating string contains printable bit value of selected data + * @dataProvider printableBitValueDataProvider + */ + + public function testPrintableBitValue($a, $b, $e) { + $this->assertEquals($e, PMA_printable_bit_value($a, $b)); + } +} +?> diff --git a/test/PMA_quoting_slashing_test.php b/test/PMA_quoting_slashing_test.php new file mode 100644 index 000000000..8d6bc26fa --- /dev/null +++ b/test/PMA_quoting_slashing_test.php @@ -0,0 +1,112 @@ + + * @package phpMyAdmin-test + * @version $Id: PMA_quoting_slashing_test.php + */ + +/** + * Tests core. + */ +require_once 'PHPUnit/Framework.php'; + +/** + * Include to test. + */ +require_once './libraries/common.lib.php'; + +/** + * Test quoting, slashing, backslashing. + * + */ +class PMA_quoting_slashing_test extends PHPUnit_Framework_TestCase +{ + + /** + * sqlAddslashes test + */ + + public function testAddSlashes() { + $string = "\'test''\''\'\r\t\n"; + + $this->assertEquals("\\\\\\\\\'test\'\'\\\\\\\\\'\'\\\\\\\\\'\\r\\t\\n", PMA_sqlAddslashes($string, true, true, true)); + $this->assertEquals("\\\\\\\\''test''''\\\\\\\\''''\\\\\\\\''\\r\\t\\n", PMA_sqlAddslashes($string, true, true, false)); + $this->assertEquals("\\\\\\\\\'test\'\'\\\\\\\\\'\'\\\\\\\\\'\r\t\n", PMA_sqlAddslashes($string, true, false, true)); + $this->assertEquals("\\\\\\\\''test''''\\\\\\\\''''\\\\\\\\''\r\t\n", PMA_sqlAddslashes($string, true, false, false)); + $this->assertEquals("\\\\\'test\'\'\\\\\'\'\\\\\'\\r\\t\\n", PMA_sqlAddslashes($string, false, true, true)); + $this->assertEquals("\\\\''test''''\\\\''''\\\\''\\r\\t\\n", PMA_sqlAddslashes($string, false, true, false)); + $this->assertEquals("\\\\\'test\'\'\\\\\'\'\\\\\'\r\t\n", PMA_sqlAddslashes($string, false, false, true)); + $this->assertEquals("\\\\''test''''\\\\''''\\\\''\r\t\n", PMA_sqlAddslashes($string, false, false, false)); + } + + /** + * data provider for unQuote test + */ + + public function unQuoteProvider() { + return array( + array('"test\'"', "test'"), + array("'test''", "test'"), + array("`test'`", "test'"), + array("'test'test", "'test'test") + ); + } + + /** + * unQuote test + * @dataProvider unQuoteProvider + */ + + public function testUnQuote($param, $expected) { + $this->assertEquals($expected, PMA_unQuote($param)); + } + + /** + * data provider for unQuote test with chosen quote + */ + + public function unQuoteSelectedProvider() { + return array( + array('"test\'"', "test'"), + array("'test''", "'test''"), + array("`test'`", "`test'`"), + array("'test'test", "'test'test") + ); + } + + /** + * unQuote test with chosen quote + * @dataProvider unQuoteSelectedProvider + */ + + public function testUnQuoteSelectedChar($param, $expected) { + $this->assertEquals($expected, PMA_unQuote($param, '"')); + } + + /** + * data provider for backquote test + */ + + 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) + * @dataProvider backquoteDataProvider + */ + + public function testBackquote($a, $b) { + $this->assertEquals($a, PMA_backquote($a, false)); + $this->assertEquals($b, PMA_backquote($a)); + } +} +?> diff --git a/test/PMA_showHint_test.php b/test/PMA_showHint_test.php new file mode 100644 index 000000000..53e885753 --- /dev/null +++ b/test/PMA_showHint_test.php @@ -0,0 +1,185 @@ + + * @package phpMyAdmin-test + * @version $Id: PMA_showHint_test.php + */ + +/** + * Tests core. + */ +require_once 'PHPUnit/Framework.php'; + +/** + * Include to test. + */ +require_once './libraries/common.lib.php'; + +/** + * Test showHint function. + * + */ +class PMA_showHint_test extends PHPUnit_Framework_TestCase +{ + + /** + * temporary variable for globals array + */ + + protected $tmpGlobals; + + /** + * temporary variable for session array + */ + + protected $tmpSession; + + /** + * storing globals and session + */ + public function setUp() { + + $this->tmpGlobals = $GLOBALS; + $this->tmpSession = $_SESSION; + + } + + /** + * recovering globals and session + */ + public function tearDown() { + + $GLOBALS = $this->tmpGlobals; + $_SESSION = $this->tmpSession; + + } + + /** + * PMA_showHint with defined GLOBALS + */ + + public function testShowHintWithGlobals() { + + $key = md5('test'); + $nr = 1234; + $instance = 1; + + $GLOBALS['footnotes'][$key]['nr'] = $nr; + $GLOBALS['footnotes'][$key]['instance'] = $instance; + $this->assertEquals(sprintf('%d', $nr, $instance+1, $nr), PMA_showHint('test')); + + } + + /** + * PMA_showHint with defined GLOBALS formatted as BB + */ + + public function testShowHintWithGlobalsBbFormat() { + + $key = md5('test'); + $nr = 1234; + $instance = 1; + + $GLOBALS['footnotes'][$key]['nr'] = $nr; + $GLOBALS['footnotes'][$key]['instance'] = $instance; + $this->assertEquals(sprintf('[sup]%d[/sup]', $nr), PMA_showHint('test', true)); + + } + + /** + * PMA_showHint with not defined GLOBALS + */ + + public function testShowHintWithoutGlobals() { + + $key = md5('test'); + $nr = 1; + $instance = 1; + + $this->assertEquals(sprintf('%d', $nr, $instance, $nr), PMA_showHint('test', false, 'notice')); + + $expArray = array( + 'note' => 'test', + 'type' => 'notice', + 'nr' => count($GLOBALS['footnotes']), + 'instance' => 1 + ); + + $this->assertEquals($expArray, $GLOBALS['footnotes'][$key]); + + } + + /** + * PMA_showHint with not defined GLOBALS formatted as BB + */ + + public function testShowHintWithoutGlobalsBbFormat() { + + $key = md5('test'); + $nr = 1; + $instance = 1; + + $this->assertEquals(sprintf('[sup]%d[/sup]', $nr), PMA_showHint('test', true, 'notice')); + + $expArray = array( + 'note' => 'test', + 'type' => 'notice', + 'nr' => count($GLOBALS['footnotes']), + 'instance' => 1 + ); + + $this->assertEquals($expArray, $GLOBALS['footnotes'][$key]); + + } + + /** + * PMA_showHint with defined GLOBALS using PMA_Message object + */ + + public function testShowHintPmaMessageWithGlobals() { + + $nr = 1; + $instance = 1; + + $oMock = $this->getMock('PMA_Message', array('setMessage', 'setNumber', 'getHash', 'getLevel')); + $oMock->setMessage('test'); + $oMock->setNumber($nr); + + $GLOBALS['footnotes'][$key]['nr'] = $nr; + $GLOBALS['footnotes'][$key]['instance'] = $instance; + + $this->assertEquals(sprintf('%d', $nr, $instance+1, $nr), PMA_showHint($oMock)); + } + + /** + * PMA_showHint with not defined GLOBALS using PMA_Message object + */ + + public function testShowHintPmaMessageWithoutGlobals() { + + $nr = 1; + $instance = 1; + + $oMock = $this->getMock('PMA_Message', array('setMessage', 'setNumber', 'getHash', 'getLevel', 'getNumber')); + $oMock->setMessage('test'); + $oMock->setNumber($nr); + + $this->assertEquals(sprintf('%d', $nr, $instance, $nr), PMA_showHint($oMock, false)); + + $key = $oMock->getHash(); + + $expArray = array( + 'note' => $oMock, + 'type' => $oMock->getLevel(), + 'nr' => count($GLOBALS['footnotes']), + 'instance' => 1 + ); + + $this->assertEquals($expArray, $GLOBALS['footnotes'][$key]); + } + +} +?> diff --git a/test/PMA_stringOperations_test.php b/test/PMA_stringOperations_test.php new file mode 100644 index 000000000..7ed049c46 --- /dev/null +++ b/test/PMA_stringOperations_test.php @@ -0,0 +1,135 @@ + + * @version $Id: PMA_stringOperations_test.php + */ + +/** + * Tests core. + */ +require_once 'PHPUnit/Framework.php'; + +/** + * Include to test. + */ +require_once './libraries/common.lib.php'; + +/** + * Test string operations. + * @package phpMyAdmin-test + */ +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 + */ + public function setUp() { + + $this->tmpGlobals = $GLOBALS; + $this->tmpSession = $_SESSION; + + } + + /** + * data provider for flipstring test + */ + + public function flipStringDataProvider() { + return array( + array('test', "t
\ne
\ns
\nt"), + array('te ;st', "t
\ne
\n 
\n;
\ns
\nt") + ); + } + + /** + * test of changing string from horizontal to vertical orientation + * @dataProvider flipStringDataProvider + */ + + public function testFlipString($a, $e) { + $this->assertEquals($e, PMA_flipstring($a)); + } + + /** + * data provider for userDir test + */ + + 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 + * @dataProvider userDirDataProvider + */ + + public function testUserDirString($a, $e) { + $GLOBALS['cfg']['Server']['user'] = 'root'; + + $this->assertEquals($e, PMA_userDir($a)); + } + + /** + * data provider for replace binary content test + */ + + public function replaceBinaryContentsDataProvider() { + return array( + array("\x000", '\00'), + array("\x08\x0a\x0d\x1atest", '\b\n\r\Ztest'), + array("\ntest", '\ntest') + ); + } + + /** + * replace binary contents test + * @dataProvider replaceBinaryContentsDataProvider + */ + + public function testReplaceBinaryContents($a, $e) { + $this->assertEquals($e, PMA_replace_binary_contents($a)); + } + + /** + * data provider for duplicate first newline test + */ + + 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 + * @dataProvider duplicateFirstNewlineDataProvider + */ + + public function testDuplicateFirstNewline($a, $e) { + $this->assertEquals($e, PMA_duplicateFirstNewline($a)); + } + +} +?>