diff --git a/test/AllTests.php b/test/AllTests.php index 7c58b8fc4..b5a568cec 100644 --- a/test/AllTests.php +++ b/test/AllTests.php @@ -24,6 +24,7 @@ require_once './test/PMA_get_real_size_test.php'; require_once './test/PMA_sanitize_test.php'; require_once './test/PMA_pow_test.php'; require_once './test/Environment_test.php'; +require_once './test/escape_js_string.php'; class AllTests { @@ -45,6 +46,7 @@ class AllTests $suite->addTestSuite('PMA_get_real_size_test'); $suite->addTestSuite('PMA_sanitize_test'); $suite->addTestSuite('PMA_pow_test'); + $suite->addTestSuite('PMA_escapeJsString_test'); return $suite; } } diff --git a/test/core.lib.php b/test/core.lib.php deleted file mode 100644 index 9d7bc8c88..000000000 --- a/test/core.lib.php +++ /dev/null @@ -1,66 +0,0 @@ - - * @package phpMyAdmin-test - * @version $Id: common.lib.php 9832 2007-01-09 09:50:49Z nijel $ - */ - -/** - * Go to root directory. - */ -chdir('..'); - - -/** - * Report failed test. - * - * @param string function to test - * @param string test description - * @param string failure description - */ -function PMA_test_fail($function, $test, $message) { - $function = htmlspecialchars($function); - $test = htmlspecialchars($test); - $message = htmlspecialchars($message); - echo <<$function ($test) -
Failed: $message
-EOT; -} - -/** - * Report ok test. - * - * @param string function to test - * @param string test description - */ -function PMA_test_okay($function, $test) { - $function = htmlspecialchars($function); - $test = htmlspecialchars($test); - echo <<$function ($test) -
OK
-EOT; -} - -/** - * Function for testing strings. - * - * @uses PMA_test_okay() - * @uses PMA_test_fail() - * @param string function to test - * @param string test description - * @param string actual result - * @param string expected result - */ -function PMA_test_string($function, $test, $received, $expected) { - if ($received != $expected) { - PMA_test_fail($function, $test, "Strings >$received< and >$expected< do not match"); - } else { - PMA_test_okay($function, $test); - } -} -?> diff --git a/test/escape_js_string.php b/test/escape_js_string.php index 9b6012ccf..092784363 100644 --- a/test/escape_js_string.php +++ b/test/escape_js_string.php @@ -11,28 +11,48 @@ /** * Tests core. */ -include('./core.lib.php'); +require_once 'PHPUnit/Framework.php'; + /** * Include to test. */ -include('./libraries/js_escape.lib.php'); +require_once './libraries/js_escape.lib.php'; /** * Test java script escaping. * - * @uses PMA_escapeJsString() - * @uses PMA_test_string() - * @param string string to escape - * @param string expected result */ -function PMA_test_escape($test, $expected) { - PMA_test_string('PMA_escapeJsString', $test, PMA_escapeJsString($test), $expected); -} +class PMA_escapeJsString_test extends PHPUnit_Framework_TestCase +{ + public function testEscape_1() + { + $this->assertEquals('\\\';', PMA_escapeJsString('\';')); + } -PMA_test_escape('\';', '\\\';'); -PMA_test_escape("\r\n'", '\r\n\\\'[HTML]', '[HTML]'); -PMA_test_escape('"\'\\\'"', '"\\\'\\\\\\\'"'); -PMA_test_escape("\\''''''''''''\\", "\\\\\'\'\'\'\'\'\'\'\'\'\'\'\\\\"); + public function testEscape_2() + { + $this->assertEquals('\r\n\\\'")); + } + + public function testEscape_3() + { + $this->assertEquals('\\\';[XSS]', PMA_escapeJsString('\';[XSS]')); + } + + public function testEscape_4() + { + $this->assertEquals('[HTML]', PMA_escapeJsString('[HTML]')); + } + + public function testEscape_5() + { + $this->assertEquals('"\\\'\\\\\\\'"', PMA_escapeJsString('"\'\\\'"')); + } + + public function testEscape_6() + { + $this->assertEquals("\\\\\'\'\'\'\'\'\'\'\'\'\'\'\\\\", PMA_escapeJsString("\\''''''''''''\\")); + } + +} ?>