From a09db703a134328fdffba09466a3dd95254e5108 Mon Sep 17 00:00:00 2001 From: Sebastian Mendel Date: Tue, 4 Sep 2007 15:19:33 +0000 Subject: [PATCH] testsuite for PMA_generate_common_url --- test/AllTests.php | 6 +- test/PMA_generateCommonUrl_test.php | 158 ++++++++++++++++++++++++++++ 2 files changed, 163 insertions(+), 1 deletion(-) create mode 100644 test/PMA_generateCommonUrl_test.php diff --git a/test/AllTests.php b/test/AllTests.php index 72b0eba2c..a49f98e29 100644 --- a/test/AllTests.php +++ b/test/AllTests.php @@ -30,6 +30,8 @@ require_once './test/PMA_escapeJsString_test.php'; require_once './test/PMA_isValid_test.php'; require_once './test/PMA_transformation_getOptions_test.php'; require_once './test/PMA_STR_sub_test.php'; +require_once './test/PMA_generateCommonUrl_test.php'; +//require_once './test/PMA_arrayWalkRecursive_test.php'; class AllTests { @@ -55,6 +57,8 @@ class AllTests $suite->addTestSuite('PMA_isValid_test'); $suite->addTestSuite('PMA_transformation_getOptions_test'); $suite->addTestSuite('PMA_STR_sub_test'); + $suite->addTestSuite('PMA_generate_common_url_test'); + //$suite->addTestSuite('PMA_arrayWalkRecursive_test'); return $suite; } } @@ -64,4 +68,4 @@ if (PMA_MAIN_METHOD == 'AllTests::main') { AllTests::main(); echo ''; } -?> \ No newline at end of file +?> diff --git a/test/PMA_generateCommonUrl_test.php b/test/PMA_generateCommonUrl_test.php new file mode 100644 index 000000000..aa6d6bde2 --- /dev/null +++ b/test/PMA_generateCommonUrl_test.php @@ -0,0 +1,158 @@ +assertEquals($expected, PMA_generate_common_url('db', 'table')); + } + + public function testOldStyleDbOnly() + { + $GLOBALS['server'] = 'x'; + $GLOBALS['lang'] = 'x'; + $GLOBALS['convcharset'] = 'x'; + $GLOBALS['collation_connection'] = 'x'; + $_SESSION[' PMA_token '] = 'x'; + $GLOBALS['cfg']['ServerDefault'] = 'y'; + + $separator = PMA_get_arg_separator(); + $expected = 'server=x' . htmlentities($separator) + . 'lang=x' . htmlentities($separator) + . 'convcharset=x' . htmlentities($separator) + . 'collation_connection=x' . htmlentities($separator) + . 'token=x' + ; + + $expected = 'db=db' + . htmlentities($separator) . $expected; + + $this->assertEquals($expected, PMA_generate_common_url('db')); + } + + public function testNewStyle() + { + $GLOBALS['server'] = 'x'; + $GLOBALS['lang'] = 'x'; + $GLOBALS['convcharset'] = 'x'; + $GLOBALS['collation_connection'] = 'x'; + $_SESSION[' PMA_token '] = 'x'; + $GLOBALS['cfg']['ServerDefault'] = 'y'; + + $separator = PMA_get_arg_separator(); + $expected = 'server=x' . htmlentities($separator) + . 'lang=x' . htmlentities($separator) + . 'convcharset=x' . htmlentities($separator) + . 'collation_connection=x' . htmlentities($separator) + . 'token=x' + ; + + $expected = '?db=db' + . htmlentities($separator) . 'table=table' + . htmlentities($separator) . $expected; + $params = array('db' => 'db', 'table' => 'table'); + $this->assertEquals($expected, PMA_generate_common_url($params)); + } + + public function testOldStyleWithAlternateSeparator() + { + $GLOBALS['server'] = 'x'; + $GLOBALS['lang'] = 'x'; + $GLOBALS['convcharset'] = 'x'; + $GLOBALS['collation_connection'] = 'x'; + $_SESSION[' PMA_token '] = 'x'; + $GLOBALS['cfg']['ServerDefault'] = 'y'; + + $separator = PMA_get_arg_separator(); + $expected = 'server=x' . htmlentities($separator) + . 'lang=x' . htmlentities($separator) + . 'convcharset=x' . htmlentities($separator) + . 'collation_connection=x' . htmlentities($separator) + . 'token=x' + ; + + $expected = 'db=db' + . htmlentities($separator) . 'table=table' + . htmlentities($separator) . $expected; + $this->assertEquals($expected, PMA_generate_common_url('db', 'table', '&')); + } + + public function testOldStyleWithAlternateSeparatorDbOnly() + { + $GLOBALS['server'] = 'x'; + $GLOBALS['lang'] = 'x'; + $GLOBALS['convcharset'] = 'x'; + $GLOBALS['collation_connection'] = 'x'; + $_SESSION[' PMA_token '] = 'x'; + $GLOBALS['cfg']['ServerDefault'] = 'y'; + + $separator = PMA_get_arg_separator(); + $expected = 'server=x' . htmlentities($separator) + . 'lang=x' . htmlentities($separator) + . 'convcharset=x' . htmlentities($separator) + . 'collation_connection=x' . htmlentities($separator) + . 'token=x' + ; + + $expected = 'db=db' + . htmlentities($separator) . $expected; + $this->assertEquals($expected, PMA_generate_common_url('db', '', '&')); + } + + public function testDefault() + { + $GLOBALS['server'] = 'x'; + $GLOBALS['lang'] = 'x'; + $GLOBALS['convcharset'] = 'x'; + $GLOBALS['collation_connection'] = 'x'; + $_SESSION[' PMA_token '] = 'x'; + $GLOBALS['cfg']['ServerDefault'] = 'y'; + + $separator = PMA_get_arg_separator(); + $expected = '?server=x' . htmlentities($separator) + . 'lang=x' . htmlentities($separator) + . 'convcharset=x' . htmlentities($separator) + . 'collation_connection=x' . htmlentities($separator) + . 'token=x' + ; + $this->assertEquals($expected, PMA_generate_common_url()); + } +} +?>