diff --git a/.gitignore b/.gitignore index dda2e0ecd9..6cc231a221 100644 --- a/.gitignore +++ b/.gitignore @@ -20,6 +20,7 @@ phpmyadmin.wpj .buildpath .cache .idea +.netbeans *.sw[op] # Locales /locale/ @@ -31,3 +32,8 @@ phpmyadmin.wpj /apidoc/ # Demo server revision-info.php +# PHPUnit +phpunit.xml +/test/bootstrap.php +# Jenkins +/build/ \ No newline at end of file diff --git a/build.xml b/build.xml new file mode 100644 index 0000000000..a6f09da0ed --- /dev/null +++ b/build.xml @@ -0,0 +1,87 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/libraries/common.lib.php b/libraries/common.lib.php index e64c75161a..e4c7cbda33 100644 --- a/libraries/common.lib.php +++ b/libraries/common.lib.php @@ -2846,7 +2846,9 @@ function PMA_ajaxResponse($message, $success = true, $extra_data = array()) header("Content-Type: application/json"); echo json_encode($response); - exit; + + if(!defined('TESTSUITE')) + exit; } /** diff --git a/libraries/core.lib.php b/libraries/core.lib.php index 371aec2505..fe533e35f3 100644 --- a/libraries/core.lib.php +++ b/libraries/core.lib.php @@ -224,8 +224,10 @@ function PMA_fatalError($error_message, $message_args = null) } require('./libraries/error.inc.php'); - - exit; + + if (!defined('TESTSUITE')) { + exit; + } } /** diff --git a/phpunit.xml.dist b/phpunit.xml.dist new file mode 100644 index 0000000000..41782b7189 --- /dev/null +++ b/phpunit.xml.dist @@ -0,0 +1,53 @@ + + + + + + + + + + + + + + + + + + + + test/classes + + + test/Environment_test.php + test/libraries/core + test/libraries/common + test/libraries + + + + + + + + + + + + + diff --git a/po/da.po b/po/da.po index 9c35456bb4..e76637484f 100644 --- a/po/da.po +++ b/po/da.po @@ -10460,7 +10460,7 @@ msgid "" "cookie validity%s must be set to a value less or equal to it." msgstr "" "Hvis du bruger cookie autentifikation og %sLogin cookie sletning%s ikke er " -"0, så skal %Login cookie gyldighed% være en værdi mindre end eller lig med " +"0, så skal %sLogin cookie gyldighed%s være en værdi mindre end eller lig med " "den." #: setup/lib/index.lib.php:266 diff --git a/test/.htaccess b/test/.htaccess new file mode 100644 index 0000000000..d4984c298b --- /dev/null +++ b/test/.htaccess @@ -0,0 +1,6 @@ +# This folder does NOT need to be accessible over HTTP +# In most cases the tests included here will be run from a command line interface. + +# (the following directive denies access by default) +# For more information see: http://httpd.apache.org/docs/current/mod/mod_authz_host.html#allow +Order allow,deny diff --git a/test/Environment_test.php b/test/Environment_test.php index f61956f36d..c72a1656e0 100644 --- a/test/Environment_test.php +++ b/test/Environment_test.php @@ -9,7 +9,7 @@ /** * */ -require_once 'PHPUnit/Framework.php'; +require_once 'config.sample.inc.php'; /** * @package phpMyAdmin-test @@ -24,12 +24,28 @@ class Environment_test extends PHPUnit_Framework_TestCase public function testMySQL() { - $this->markTestIncomplete(); + try{ + $pdo = new PDO("mysql:host=".TESTSUITE_SERVER.";dbname=".TESTSUITE_DATABASE, TESTSUITE_USER, TESTSUITE_PASSWORD); + $this->assertNull($pdo->errorCode(),"Error when trying to connect to database"); + + //$pdo->beginTransaction(); + $test = $pdo->exec("SHOW TABLES;"); + //$pdo->commit(); + $this->assertEquals(0, $pdo->errorCode(), 'Error trying to show tables for database'); + } + catch (Exception $e){ + $this->fail("Error: ".$e->getMessage()); + } + + // Check id MySQL server is 5 version + preg_match("/^(\d+)?\.(\d+)?\.(\*|\d+)/", $pdo->getAttribute(constant("PDO::ATTR_SERVER_VERSION")), $version_parts); + $this->assertEquals(5, $version_parts[1]); } - public function testSession() - { - $this->markTestIncomplete(); - } + //TODO: Think about this test +// public function testSession() +// { +// $this->markTestIncomplete(); +// } } ?> diff --git a/test/FailTest.php b/test/FailTest.php deleted file mode 100644 index f430bb470b..0000000000 --- a/test/FailTest.php +++ /dev/null @@ -1,24 +0,0 @@ -assertEquals(0, 1); - } -} -?> diff --git a/test/PMA_escapeJsString_test.php b/test/PMA_escapeJsString_test.php deleted file mode 100644 index 4efd6337ef..0000000000 --- a/test/PMA_escapeJsString_test.php +++ /dev/null @@ -1,57 +0,0 @@ -assertEquals('\\\';', PMA_escapeJsString('\';')); - } - - 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("\\''''''''''''\\")); - } - -} -?> diff --git a/test/PMA_isValid_test.php b/test/PMA_isValid_test.php deleted file mode 100644 index ffd41a2615..0000000000 --- a/test/PMA_isValid_test.php +++ /dev/null @@ -1,114 +0,0 @@ -assertFalse(isset($var)); - } - public function testNotSet() - { - $this->assertFalse(PMA_isValid($var)); - } - public function testEmptyString() - { - $var = ''; - $this->assertFalse(PMA_isValid($var)); - } - public function testNotEmptyString() - { - $var = '0'; - $this->assertTrue(PMA_isValid($var)); - } - public function testZero() - { - $var = 0; - $this->assertTrue(PMA_isValid($var)); - } - public function testNullFail() - { - $var = null; - $this->assertFalse(PMA_isValid($var)); - } - public function testNotSetArray() - { - $this->assertFalse(PMA_isValid($array['x'])); - } - public function testScalarString() - { - $var = 'string'; - $this->assertTrue(PMA_isValid($var, 'scalar')); - } - public function testScalarInt() - { - $var = 1; - $this->assertTrue(PMA_isValid($var, 'scalar')); - } - public function testScalarFloat() - { - $var = 1.1; - $this->assertTrue(PMA_isValid($var, 'scalar')); - } - public function testScalarBool() - { - $var = true; - $this->assertTrue(PMA_isValid($var, 'scalar')); - } - public function testNotScalarArray() - { - $var = array('test'); - $this->assertFalse(PMA_isValid($var, 'scalar')); - } - public function testNotScalarNull() - { - $var = null; - $this->assertFalse(PMA_isValid($var, 'scalar')); - } - public function testNumericInt() - { - $var = 1; - $this->assertTrue(PMA_isValid($var, 'numeric')); - } - public function testNumericFloat() - { - $var = 1.1; - $this->assertTrue(PMA_isValid($var, 'numeric')); - } - public function testNumericZero() - { - $var = 0; - $this->assertTrue(PMA_isValid($var, 'numeric')); - } - public function testNumericString() - { - $var = '+0.1'; - $this->assertTrue(PMA_isValid($var, 'numeric')); - } - public function testValueInArray() - { - $var = 'a'; - $this->assertTrue(PMA_isValid($var, array('a', 'b', ))); - } - public function testValueNotInArray() - { - $var = 'c'; - $this->assertFalse(PMA_isValid($var, array('a', 'b', ))); - } -} -?> diff --git a/test/PMA_showHint_test.php b/test/PMA_showHint_test.php index 2ff37fee99..83707591dd 100644 --- a/test/PMA_showHint_test.php +++ b/test/PMA_showHint_test.php @@ -1,26 +1,17 @@ doLogin(); - $this->assertRegExp("/phpMyAdmin .*-dev/", $this->getTitle()); - } -} -?> diff --git a/test/PmaSeleniumTestCase.php b/test/PmaSeleniumTestCase.php deleted file mode 100644 index ac70594d45..0000000000 --- a/test/PmaSeleniumTestCase.php +++ /dev/null @@ -1,100 +0,0 @@ - 'Firefox on Windows XP', - 'browser' => '*firefox', - 'host' => 'my.windowsxp.box', - 'port' => 4444, - 'timeout' => 30000, - ), - - array( - 'name' => 'Internet Explorer on Windows XP', - 'browser' => '*iexplore', - 'host' => 'my.windowsxp.box', - 'port' => 4444, - 'timeout' => 30000, - ), - - ); - - public function setUp() - { - global $cfg; - $this->cfg =& $cfg; - //PHPUnit_Extensions_SeleniumTestCase::$browsers = $this->cfg['Test']['broswers']; - - // Check if the test configuration is available - if ( empty($cfg['Test']['pma_host']) - || empty($cfg['Test']['pma_url']) - //|| empty($cfg['Test']['browsers']) - ) { - $this->fail("Missing Selenium configuration in config.inc.php"); // TODO add doc ref? - } - - $this->setBrowserUrl($cfg['Test']['pma_host'] . $cfg['Test']['pma_url']); - - $this->start(); - } - - public function tearDown() - { - $this->stop(); - } - - /** - * perform a login - */ - public function doLogin() - { - $this->open($this->cfg['Test']['pma_url']); - // Somehow selenium does not like the language selection on the cookie login page, forced English in the config for now. - //$this->select("lang", "label=English"); - - $this->waitForPageToLoad("30000"); - $this->type("input_username", $this->cfg['Test']['testuser']['username']); - $this->type("input_password", $this->cfg['Test']['testuser']['password']); - $this->click("input_go"); - $this->waitForPageToLoad("30001"); - } - - /* - * Just a dummy to show some example statements - * - public function mockTest() - { - // Slow down the testing speed, ideal for debugging - //$this->setSpeed(4000); -} - */ -} - -?> diff --git a/test/README b/test/README new file mode 100644 index 0000000000..a7e287ad42 --- /dev/null +++ b/test/README @@ -0,0 +1,11 @@ +PhpMyAdmin test suite +===================== + +This directory is protected from web visitors by a .htaccess file. + +For more information on allowing http access to this directory see: +http://httpd.apache.org/docs/current/mod/mod_authz_host.html#allow + +Please visit the wiki for more information on unit testing: +https://wiki.phpmyadmin.net/pma/UnitTesting + diff --git a/test/bootstrap-dist.php b/test/bootstrap-dist.php new file mode 100644 index 0000000000..fac9b2720d --- /dev/null +++ b/test/bootstrap-dist.php @@ -0,0 +1,14 @@ + diff --git a/test/classes/PMA_Config_test.php b/test/classes/PMA_Config_test.php new file mode 100644 index 0000000000..3340957810 --- /dev/null +++ b/test/classes/PMA_Config_test.php @@ -0,0 +1,613 @@ +object = new PMA_Config; + } + + /** + * Tears down the fixture, for example, closes a network connection. + * This method is called after a test is executed. + */ + protected function tearDown() + { + } + + public function testCheckSystem() + { + $this->object->checkSystem(); + + $this->assertNotNull($this->object->get('PMA_VERSION')); + $this->assertNotEmpty($this->object->get('PMA_THEME_VERSION')); + $this->assertNotEmpty($this->object->get('PMA_THEME_GENERATION')); + } + + public function testCheckOutputCompression() + { + + $this->object->set('OBGzip', 'auto'); + + $this->object->set('PMA_USR_BROWSER_AGENT', 'IE'); + $this->object->set('PMA_USR_BROWSER_VER', 6); + $this->object->checkOutputCompression(); + $this->assertFalse($this->object->get("OBGzip")); + + $this->object->set('OBGzip', 'auto'); + $this->object->set('PMA_USR_BROWSER_AGENT', 'MOZILLA'); + $this->object->set('PMA_USR_BROWSER_VER', 5); + $this->object->checkOutputCompression(); + $this->assertEquals('auto',$this->object->get("OBGzip")); + + ini_set('zlib.output_compression', 'Off'); + $this->object->checkOutputCompression(); + $this->assertFalse($this->object->get("OBGzip")); + + ini_set('zlib.output_compression', 'On'); + } + + public function testCheckClient() + { + $_SERVER['HTTP_USER_AGENT'] = 'Opera/9.80 (X11; Linux x86_64; U; pl) Presto/2.7.62 Version/11.00'; + $this->object->checkClient(); + $this->assertEquals("Linux", $this->object->get('PMA_USR_OS'), "User OS expected to be Linux"); + $this->assertEquals("OPERA", $this->object->get('PMA_USR_BROWSER_AGENT'), "Browser expected to be Opera"); + $this->assertEquals("9.80", $this->object->get('PMA_USR_BROWSER_VER'), "Browser ver expected to be 9.80"); + + $_SERVER['HTTP_USER_AGENT'] = 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en-US) AppleWebKit/528.16 OmniWeb/622.8.0.112941'; + $this->object->checkClient(); + $this->assertEquals("Mac", $this->object->get('PMA_USR_OS'), "User OS expected to be Mac"); + $this->assertEquals("OMNIWEB", $this->object->get('PMA_USR_BROWSER_AGENT'), "Browser expected to be OmniWeb"); + + $_SERVER['HTTP_USER_AGENT'] = 'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1)'; + $this->object->checkClient(); + $this->assertEquals("Win", $this->object->get('PMA_USR_OS'), "User OS expected to be Windows"); + $this->assertEquals("IE", $this->object->get('PMA_USR_BROWSER_AGENT'), "Browser expected to be IE"); + + $_SERVER['HTTP_USER_AGENT'] = 'Mozilla/5.0 (Unknown; U; Unix BSD/SYSV system; C -) AppleWebKit/527+ (KHTML, like Gecko, Safari/419.3) Arora/0.10.2'; + $this->object->checkClient(); + $this->assertEquals("Unix", $this->object->get('PMA_USR_OS'), "User OS expected to be Unix"); + + $_SERVER['HTTP_USER_AGENT'] = 'Mozilla/4.0 (compatible; OS/2 Webexplorer)'; + $this->object->checkClient(); + $this->assertEquals("OS/2", $this->object->get('PMA_USR_OS'), "User OS expected to be OS/2"); + + $_SERVER['HTTP_USER_AGENT'] = 'Mozilla/5.0 (Windows; U; Win95; en-US; rv:1.9b) Gecko/20031208'; + $this->object->checkClient(); + $this->assertEquals("GECKO", $this->object->get('PMA_USR_BROWSER_AGENT'), "Browser expected to be Gecko"); + + $_SERVER['HTTP_USER_AGENT'] = 'Mozilla/5.0 (compatible; Konqueror/4.5; NetBSD 5.0.2; X11; amd64; en_US) KHTML/4.5.4 (like Gecko)'; + $this->object->checkClient(); + $this->assertEquals("KONQUEROR", $this->object->get('PMA_USR_BROWSER_AGENT'), "Browser expected to be Konqueror"); + + $_SERVER['HTTP_USER_AGENT'] = 'Mozilla/5.0 (X11; Linux x86_64; rv:5.0) Gecko/20100101 Firefox/5.0'; + $this->object->checkClient(); + $this->assertEquals("MOZILLA", $this->object->get('PMA_USR_BROWSER_AGENT'), "Browser expected to be Mozilla"); + $this->assertEquals("Linux", $this->object->get('PMA_USR_OS'), "User OS expected to be Linux"); + + } + + public function testCheckGd2() + { + $prevIsGb2Val = $this->object->get('PMA_IS_GD2'); + + $this->object->set('GD2Available','yes'); + $this->object->checkGd2(); + $this->assertEquals(1, $this->object->get('PMA_IS_GD2')); + + $this->object->set('GD2Available','no'); + $this->object->checkGd2(); + $this->assertEquals(0, $this->object->get('PMA_IS_GD2')); + + $this->object->set('GD2Available',$prevIsGb2Val); + + if (!@function_exists('imagecreatetruecolor')) + { + $this->object->checkGd2(); + $this->assertEquals(0, $this->object->get('PMA_IS_GD2'), 'Function imagecreatetruecolor does not exist, PMA_IS_GD2 should be 0'); + } + + if (@function_exists('gd_info')) { + $this->object->checkGd2(); + $gd_nfo = gd_info(); + if (strstr($gd_nfo["GD Version"], '2.')) { + $this->assertEquals(1, $this->object->get('PMA_IS_GD2'), 'GD Version >= 2, PMA_IS_GD2 should be 1'); + } else { + $this->assertEquals(0, $this->object->get('PMA_IS_GD2'), 'GD Version < 2, PMA_IS_GD2 should be 0'); + } + } + + /* Get GD version string from phpinfo output */ + ob_start(); + phpinfo(INFO_MODULES); /* Only modules */ + $a = strip_tags(ob_get_contents()); + ob_end_clean(); + + if (preg_match('@GD Version[[:space:]]*\(.*\)@', $a, $v)) { + if (strstr($v, '2.')) { + $this->assertEquals(1, $this->object->get('PMA_IS_GD2'), 'PMA_IS_GD2 should be 1'); + } else { + $this->assertEquals(0, $this->object->get('PMA_IS_GD2'), 'PMA_IS_GD2 should be 0'); + } + } + } + + public function testCheckWebServer() + { + $_SERVER['SERVER_SOFTWARE'] = "Microsoft-IIS 7.0"; + $this->object->checkWebServer(); + $this->assertEquals(1, $this->object->get('PMA_IS_IIS')); + + $_SERVER['SERVER_SOFTWARE'] = "Apache/2.2.17"; + $this->object->checkWebServer(); + $this->assertEquals(0, $this->object->get('PMA_IS_IIS')); + + unset($_SERVER['SERVER_SOFTWARE']); + } + + public function testCheckWebServerOs() + { + $this->object->checkWebServerOs(); + + if (defined('PHP_OS')) + { + switch (PHP_OS) + { + case stristr(PHP_OS,'win'): + $this->assertEquals(1, $this->object->get('PMA_IS_WINDOWS'), 'PHP_OS equals: ' . PHP_OS . ' PMA_IS_WINDOWS should be 1'); + break; + case stristr(PHP_OS, 'OS/2'): + $this->assertEquals(1, $this->object->get('PMA_IS_WINDOWS'), 'PHP_OS is OS/2 PMA_IS_WINDOWS should be 1 (No file permissions like Windows)'); + break; + case stristr(PHP_OS, 'Linux'): + $this->assertEquals(0, $this->object->get('PMA_IS_WINDOWS')); + break; + } + } + else + { + $this->assertEquals(0, $this->object->get('PMA_IS_WINDOWS'), 'PMA_IS_WINDOWS Default to Unix or Equiv'); + + define('PHP_OS','Windows'); + $this->assertEquals(1, $this->object->get('PMA_IS_WINDOWS'), 'PMA_IS_WINDOWS must be 1'); + } + } + + public function testCheckPhpVersion() + { + $this->object->checkPhpVersion(); + + $php_int_ver = 0; + $php_str_ver = phpversion(); + + $match = array(); + preg_match('@([0-9]{1,2}).([0-9]{1,2}).([0-9]{1,2})@', phpversion(), $match); + if (isset($match) && ! empty($match[1])) { + if (! isset($match[2])) { + $match[2] = 0; + } + if (! isset($match[3])) { + $match[3] = 0; + } + $php_int_ver = (int) sprintf('%d%02d%02d', $match[1], $match[2], $match[3]); + } else { + $php_int_ver = 0; + } + + $this->assertEquals($php_str_ver, $this->object->get('PMA_PHP_STR_VERSION')); + $this->assertEquals($php_int_ver, $this->object->get('PMA_PHP_INT_VERSION')); + } + + public function testLoadDefaults() + { + $prevDefaultSource = $this->object->default_source; + + $this->object->default_source = 'unexisted.file.php'; + $this->assertFalse($this->object->loadDefaults()); + + $this->object->default_source = $prevDefaultSource; + + include $this->object->default_source; + + $loadedConf = $cfg; + unset($cfg); + + $this->assertTrue($this->object->loadDefaults()); + + $this->assertEquals($this->object->default_source_mtime, filemtime($prevDefaultSource)); + $this->assertEquals($loadedConf['Servers'][1], $this->object->default_server); + + unset($loadedConf['Servers']); + + $this->assertEquals($loadedConf, $this->object->default); + + $expectedSettings = PMA_array_merge_recursive($this->object->settings, $loadedConf); + + $this->assertEquals($expectedSettings, $this->object->settings,'Settings loaded wrong'); + + $this->assertFalse($this->object->error_config_default_file); + } + + public function testCheckConfigSource() + { + $this->object->setSource('unexisted.config.php'); + $this->assertFalse($this->object->checkConfigSource()); + $this->assertEquals(0, $this->object->source_mtime); + +// if(! is_readable($this->object->getSource())) +// $this->markTestSkipped('Configuration file is read only'); + + $this->object->setSource('libraries/config.default.php'); + + $this->assertNotEmpty($this->object->getSource()); + $this->assertTrue($this->object->checkConfigSource()); + } + + /** + * @covers PMA_Config::get + * @covers PMA_Config::set + * @return void + */ + public function testGetAndSet() + { + $this->assertNull($this->object->get("unresisting_setting")); + + $this->object->set('test_setting', 'test_value'); + + $this->assertEquals('test_value', $this->object->get('test_setting')); + } + + /** + * @covers PMA_Config::getSource + * @covers PMA_Config::setSource + */ + public function testGetSetSource() + { + echo $this->object->getSource(); + + $this->assertEmpty($this->object->getSource(), "Source is null by default"); + + $this->object->setSource("config.sample.inc.php"); + + $this->assertEquals("config.sample.inc.php", $this->object->getSource(), "Cant set new source"); + } + + public function testCheckPmaAbsoluteUriEmpty() + { + $this->object->set('PmaAbsoluteUri',''); + $this->assertFalse($this->object->checkPmaAbsoluteUri(), 'PmaAbsoluteUri is not set and should be error'); + $this->assertTrue($this->object->error_pma_uri, 'PmaAbsoluteUri is not set and should be error'); + } + + /** + * @depends testCheckPmaAbsoluteUriEmpty + */ + public function testCheckPmaAbsoluteUriNormal() + { + $this->object->set('PmaAbsoluteUri','http://localhost/phpmyadmin/'); + $this->object->checkPmaAbsoluteUri(); + $this->assertEquals("http://localhost/phpmyadmin/", $this->object->get('PmaAbsoluteUri')); + + $this->object->set('PmaAbsoluteUri','http://localhost/phpmyadmin'); + $this->object->checkPmaAbsoluteUri(); + $this->assertEquals("http://localhost/phpmyadmin/", $this->object->get('PmaAbsoluteUri'), 'Expected trailing slash at the end of the phpMyAdmin uri'); + + } + + /** + * @depends testCheckPmaAbsoluteUriNormal + */ + public function testCheckPmaAbsoluteUriScheme() + { + $_SERVER['HTTP_HOST'] = 'localhost'; + $_SERVER['HTTP_SCHEME'] = 'http'; + $_SERVER['HTTPS'] = 'off'; + $GLOBALS['PMA_PHP_SELF'] = 'index.php'; + + $this->object->set('PmaAbsoluteUri',''); + + $this->object->checkPmaAbsoluteUri(); + $this->assertEquals("http://localhost/", $this->object->get('PmaAbsoluteUri')); + } + + /** + * @depends testCheckPmaAbsoluteUriScheme + */ + public function testCheckPmaAbsoluteUriUser() + { + $this->object->set('PmaAbsoluteUri','http://user:pwd@localhost/phpmyadmin/index.php'); + + $this->object->checkPmaAbsoluteUri(); + $this->assertEquals("http://user:pwd@localhost/phpmyadmin/index.php/", $this->object->get('PmaAbsoluteUri')); + + $this->object->set('PmaAbsoluteUri','https://user:pwd@localhost/phpmyadmin/index.php'); + + $this->object->checkPmaAbsoluteUri(); + $this->assertEquals("https://user:pwd@localhost/phpmyadmin/index.php/", $this->object->get('PmaAbsoluteUri')); + } + + public function testCheckCollationConnection() + { + $_REQUEST['collation_connection'] = 'utf-8'; + $this->object->checkCollationConnection(); + + $this->assertEquals($_REQUEST['collation_connection'], $this->object->get('collation_connection')); + } + + public function testIsHttps() + { + $this->object->set('PmaAbsoluteUri', 'http://some_host.com/phpMyAdmin'); + $this->assertFalse($this->object->isHttps()); + + $this->object->set('PmaAbsoluteUri', 'https://some_host.com/phpMyAdmin'); + $this->assertFalse($this->object->isHttps()); + } + + public function testDetectHttps() + { + unset($_SERVER['REQUEST_URI']); + unset($_SERVER['HTTP_SCHEME']); + unset($_SERVER['HTTPS']); + + $this->assertFalse($this->object->detectHttps()); + + $_SERVER['REQUEST_URI'] = '/url:\this_is_not_url'; + $this->assertFalse($this->object->detectHttps()); + + $_SERVER['REQUEST_URI'] = 'file://localhost/phpmyadmin/index.php'; + $this->assertFalse($this->object->detectHttps()); + + $_ENV['REQUEST_URI'] = 'http://localhost/phpmyadmin/index.php'; + $this->assertFalse($this->object->detectHttps()); + + $_SERVER['REQUEST_URI'] = 'https://localhost/phpmyadmin/index.php'; + $this->assertTrue($this->object->detectHttps()); + + $_SERVER['REQUEST_URI'] = 'localhost/phpmyadmin/index.php'; + $_SERVER['HTTP_SCHEME'] = 'https'; + $_SERVER['HTTPS'] = 'on'; + $this->assertTrue($this->object->detectHttps()); + } + + /** + * @depends testDetectHttps + */ + public function testCheckCookiePath() + { + $this->object->checkCookiePath(); + echo $this->object->get('cookie_path'); + $this->assertEquals('',$this->object->get('cookie_path')); + } + + /** + * @depends testCheckSystem + * @depends testCheckWebServer + * @depends testLoadDefaults + * @depends testLoad + */ + public function testEnableBc() + { + $this->object->enableBc(); + + $defines = array( + 'PMA_VERSION', + 'PMA_THEME_VERSION', + 'PMA_THEME_GENERATION', + 'PMA_PHP_STR_VERSION', + 'PMA_PHP_INT_VERSION', + 'PMA_IS_WINDOWS', + 'PMA_IS_IIS', + 'PMA_IS_GD2', + 'PMA_USR_OS', + 'PMA_USR_BROWSER_VER', + 'PMA_USR_BROWSER_AGENT' + ); + + foreach ($defines as $define) + { + $this->assertTrue(defined($define)); + $this->assertEquals(constant($define), $this->object->get($define)); + } + } + + /** + * @todo Implement testSave(). + */ + public function testSave() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } + + /** + * @todo Implement testGetFontsizeForm(). + */ + public function testGetFontsizeForm() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } + + /** + * @todo Implement testRemoveCookie(). + */ + public function testRemoveCookie() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } + /** + * @todo Implement testCheckFontsize(). + */ + public function testCheckFontsize() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } + + /** + * @todo Implement testCheckUpload(). + */ + public function testCheckUpload() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } + + /** + * @todo Implement testCheckUploadSize(). + */ + public function testCheckUploadSize() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } + + /** + * @todo Implement testCheckIsHttps(). + */ + public function testCheckIsHttps() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } + + /** + * @todo Implement testGetCookiePath(). + */ + public function testGetCookiePath() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } + + /** + * @todo finish implementing test + dependencies + */ + public function testLoad() + { + $this->assertFalse($this->object->load()); + + $this->assertTrue($this->object->load('./libraries/config.default.php')); + } + + /** + * @todo Implement testLoadUserPreferences(). + */ + public function testLoadUserPreferences() + { + $this->assertNull($this->object->loadUserPreferences()); + +// echo $GLOBALS['cfg']['ServerDefault']; + } + + /** + * @todo Implement testSetUserValue(). + */ + public function testSetUserValue() + { + $this->object->setUserValue(null, 'lang', $GLOBALS['lang'], 'en'); + $this->object->setUserValue("TEST_COOKIE_USER_VAL",'','cfg_val_1'); + + // Remove the following lines when you implement this test. +// $this->markTestIncomplete( +// 'This test has not been implemented yet.' +// ); + } + + /** + * @todo Implement testGetUserValue(). + */ + public function testGetUserValue() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } + + /** + * @todo Implement testGetThemeUniqueValue(). + */ + public function testGetThemeUniqueValue() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } + + /** + * @todo Implement testCheckPermissions(). + */ + public function testCheckPermissions() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } + + + /** + * @todo Implement testSetCookie(). + */ + public function testSetCookie() + { + $this->assertFalse($this->object->setCookie('TEST_DEF_COOKIE', 'test_def_123', 'test_def_123')); + + $this->assertTrue($this->object->setCookie('TEST_CONFIG_COOKIE', 'test_val_123', null, 3600)); + + $this->assertTrue($this->object->setCookie('TEST_CONFIG_COOKIE', '', 'default_val')); + + $_COOKIE['TEST_MANUAL_COOKIE'] = 'some_test_val'; + $this->assertTrue($this->object->setCookie('TEST_MANUAL_COOKIE', 'other', 'other')); + + } +} +?> diff --git a/test/PMA_Message_test.php b/test/classes/PMA_Message_test.php similarity index 81% rename from test/PMA_Message_test.php rename to test/classes/PMA_Message_test.php index ed7694e3d9..405bb759f9 100644 --- a/test/PMA_Message_test.php +++ b/test/classes/PMA_Message_test.php @@ -3,24 +3,16 @@ /** * Test for PMA_Message class * - */ - -/** - * Tests core. - */ -require_once 'PHPUnit/Framework.php'; -require_once 'PHPUnit/Extensions/OutputTestCase.php'; - -/** - * Include to test. - */ -require_once './libraries/Message.class.php'; - -/** - * Test class PMA_Message. - * * @package phpMyAdmin-test */ + +/* + * Include to test. + */ +require_once 'libraries/sanitizing.lib.php'; +require_once 'libraries/core.lib.php'; +require_once 'libraries/Message.class.php'; + class PMA_Message_test extends PHPUnit_Extensions_OutputTestCase { /** @@ -99,17 +91,6 @@ class PMA_Message_test extends PHPUnit_Extensions_OutputTestCase $this->assertEquals($this->object, PMA_Message::rawError('test<&>')); } - /** - * test rawWarning method - */ - public function testRawWarning() - { - $this->object = new PMA_Message('', PMA_Message::WARNING); - $this->object->setMessage('test<&>'); - - $this->assertEquals($this->object, PMA_Message::rawWarning('test<&>')); - } - /** * test rawNotice method */ @@ -207,15 +188,6 @@ class PMA_Message_test extends PHPUnit_Extensions_OutputTestCase $this->assertEquals(array('*', PMA_Message::notice('test'), '', PMA_Message::notice('test')), $this->object->getAddedMessages()); } - /** - * testing add messages method - */ - public function testAddMessages() - { - $this->object->addMessages(array('test', PMA_Message::rawWarning('test')), '&'); - $this->assertEquals(array('&', PMA_Message::rawNotice('test'), '&', PMA_Message::rawWarning('test')), $this->object->getAddedMessages()); - } - /** * testing add message method */ @@ -225,8 +197,20 @@ class PMA_Message_test extends PHPUnit_Extensions_OutputTestCase $this->assertEquals(array(PMA_Message::rawNotice('test')), $this->object->getAddedMessages()); $this->object->addMessage('test'); $this->assertEquals(array(PMA_Message::rawNotice('test'), ' ', PMA_Message::rawNotice('test')), $this->object->getAddedMessages()); - $this->object->addMessage(PMA_Message::rawWarning('test'), '&'); - $this->assertEquals(array(PMA_Message::rawNotice('test'), ' ', PMA_Message::rawNotice('test'), '&', PMA_Message::rawWarning('test')), $this->object->getAddedMessages()); + } + + /** + * testing add messages method + */ + public function testAddMessages() + { + $messages = array(); + $messages[] = "Test1"; + $messages[] = new PMA_Message("PMA_Test2", PMA_Message::ERROR); + $messages[] = "Test3"; + $this->object->addMessages($messages, ''); + + $this->assertEquals(array(PMA_Message::rawNotice('Test1'), PMA_Message::error("PMA_Test2"), PMA_Message::rawNotice('Test3')), $this->object->getAddedMessages()); } /** @@ -384,5 +368,65 @@ class PMA_Message_test extends PHPUnit_Extensions_OutputTestCase $this->assertTrue($this->object->isDisplayed(true)); $this->assertTrue($this->object->isDisplayed(false)); } + + public function providerAffectedRows(){ + return array(array(1, '
1 row affected.
')); + return array(array(2, '
2 rows affected.
')); + return array(array(50000000000000, '
50000000000000 rows affected.
')); + } + + /** + * affected_rows test + * + * @dataProvider providerAffectedRows + */ + public function testAffectedRows($rows, $output) + { + $this->object = new PMA_Message(); + $msg = $this->object->affected_rows($rows); + echo $this->object->addMessage($msg); + $this->expectOutputString($output); + $this->object->display(); + } + + public function providerInsertedRows(){ + return array(array(1, '
1 row inserted.
')); + return array(array(2, '
2 rows inserted.
')); + return array(array(50000000000000, '
50000000000000 rows inserted.
')); + } + + /** + * inserted_rows test + * + * @dataProvider providerInsertedRows + */ + public function testInsertedRows($rows, $output) + { + $this->object = new PMA_Message(); + $msg = $this->object->inserted_rows($rows); + echo $this->object->addMessage($msg); + $this->expectOutputString($output); + $this->object->display(); + } + + public function providerDeletedRows(){ + return array(array(1, '
1 row deleted.
')); + return array(array(2, '
2 rows deleted.
')); + return array(array(50000000000000, '
50000000000000 rows deleted.
')); + } + + /** + * deleted_rows test + * + * @dataProvider providerDeletedRows + */ + public function testDeletedRows($rows, $output) + { + $this->object = new PMA_Message(); + $msg = $this->object->deleted_rows($rows); + echo $this->object->addMessage($msg); + $this->expectOutputString($output); + $this->object->display(); + } } ?> diff --git a/test/classes/PMA_Theme_test.php b/test/classes/PMA_Theme_test.php new file mode 100644 index 0000000000..d8ca69914a --- /dev/null +++ b/test/classes/PMA_Theme_test.php @@ -0,0 +1,206 @@ +object = new PMA_Theme; + } + + /** + * Tears down the fixture, for example, closes a network connection. + * This method is called after a test is executed. + */ + protected function tearDown() + { + } + + public function testCheckImgPathNotExisted() + { + $this->object->setPath('path/to/nowhere'); + $this->assertFalse($this->object->loadInfo()); + } + + public function testCheckImgPathIncorrect() + { + $this->object->setPath('./test/classes/_data/incorrect_theme'); + $this->assertFalse($this->object->loadInfo(), 'Theme name is not properly set'); + } + + public function testCheckImgPathFull() + { + $this->object->setPath('./test/classes/_data/gen_version_info'); + $this->assertTrue($this->object->loadInfo()); + $this->assertEquals('Test Theme', $this->object->getName()); + $this->assertEquals('2.0.3', $this->object->getVersion()); + } + + public function testLoadInfo() + { + $this->object->setPath('./themes/original'); + $this->assertTrue($this->object->loadInfo()); + + $this->assertEquals(filemtime($this->object->getPath().'/info.inc.php'), $this->object->mtime_info); + + $this->object->setPath('./themes/original'); + $this->object->mtime_info = filemtime($this->object->getPath().'/info.inc.php'); + $this->assertTrue($this->object->loadInfo()); + $this->assertEquals('Original', $this->object->getName()); + } + + public function testLoad() + { + $newTheme = PMA_Theme::load('./themes/original'); + $this->assertNotNull($newTheme); + } + + public function testLoadNotExisted() + { + $this->assertFalse(PMA_Theme::load('/path/to/nowhere')); + } + + /** + * @expectedException PHPUnit_Framework_Error + */ + public function testCheckImgPathBad() + { + $prevConfPath = $GLOBALS['cfg']['ThemePath']; + $GLOBALS['cfg']['ThemePath'] = 'nowhere'; + $this->object->setPath('path/to/nowhere'); + + $this->object->checkImgPath(); + } + + public function testCheckImgPath() + { + $this->object->setPath('./themes/original'); + $this->assertTrue($this->object->checkImgPath()); + } + + public function testCheckImgPathGlobals() + { + $this->object->setPath('/this/is/wrong/path'); + $GLOBALS['cfg']['ThemePath'] = 'themes'; + $this->assertTrue($this->object->checkImgPath()); + } + + /** + * @expectedException PHPUnit_Framework_Error + */ + public function testCheckImgPathGlobalsWrongPath() + { + $prevThemePath = $GLOBALS['cfg']['ThemePath']; + $GLOBALS['cfg']['ThemePath'] = 'no_themes'; + + $this->object->setPath('/this/is/wrong/path'); + $this->object->checkImgPath(); + + $GLOBALS['cfg']['ThemePath'] = $prevThemePath; + } + + /** + * @covers PMA_Theme::setPath + * @covers PMA_Theme::getPath + */ + public function testGetSetPath() + { + $this->assertEmpty($this->object->getPath()); + $this->object->setPath('./themes/original'); + + $this->assertEquals('./themes/original', $this->object->getPath()); + } + + public function testGetLayoutFile() + { + $this->assertContains('layout.inc.php', $this->object->getLayoutFile()); + } + + /** + * @depends testLoadInfo + */ + public function testGetSetCheckVersion() + { + $this->assertEquals('0.0.0.0', $this->object->getVersion(), 'Version 0.0.0.0 by default'); + + $this->object->setVersion("1.2.3.4"); + $this->assertEquals('1.2.3.4', $this->object->getVersion()); + + $this->assertFalse($this->object->checkVersion("0.0.1.1")); + $this->assertTrue($this->object->checkVersion("2.0.1.1")); + } + + /** + * @covers PMA_Theme::getName + * @covers PMA_Theme::setName + */ + public function testGetSetName() + { + $this->assertEmpty($this->object->getName(), 'Name is empty by default'); + $this->object->setName('New Theme Name'); + + $this->assertEquals('New Theme Name', $this->object->getName()); + } + + /** + * @covers PMA_Theme::getId + * @covers PMA_Theme::setId + */ + public function testGetSetId() + { + $this->assertEmpty($this->object->getId(), 'ID is empty by default'); + $this->object->setId('NewID'); + + $this->assertEquals('NewID', $this->object->getId()); + } + + /** + * @covers PMA_Theme::getImgPath + * @covers PMA_Theme::setImgPath + */ + public function testGetSetImgPath() + { + $this->assertEmpty($this->object->getImgPath(), 'ImgPath is empty by default'); + $this->object->setImgPath('/new/path'); + + $this->assertEquals('/new/path', $this->object->getImgPath()); + } + + public function testLoadCssWrongType() + { + $type = 'middle'; + $this->assertFalse($this->object->loadCss($type)); + } + + public function testLoadCssNotExisted() + { + $type = 'print'; + $this->assertFalse($this->object->loadCss($type)); + } + + /** + * @todo Implement testPrintPreview(). + */ + public function testPrintPreview() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } +} +?> diff --git a/test/classes/_data/gen_version_info/info.inc.php b/test/classes/_data/gen_version_info/info.inc.php new file mode 100644 index 0000000000..d4e2e90911 --- /dev/null +++ b/test/classes/_data/gen_version_info/info.inc.php @@ -0,0 +1,7 @@ +assertParser('SELECT * from `aaa;', array ( 'raw' => 'SELECT * from `aaa`;', 0 => diff --git a/test/PMA_STR_sub_test.php b/test/libraries/PMA_STR_sub_test.php similarity index 86% rename from test/PMA_STR_sub_test.php rename to test/libraries/PMA_STR_sub_test.php index 640c777115..e10ff39c30 100644 --- a/test/PMA_STR_sub_test.php +++ b/test/libraries/PMA_STR_sub_test.php @@ -6,11 +6,6 @@ * @package phpMyAdmin-test */ -/** - * - */ -require_once 'PHPUnit/Framework.php'; - $match = array(); preg_match('@^([0-9]{1,2})(?:.([0-9]{1,2})(?:.([0-9]{1,2}))?)?@', phpversion(), $match); @@ -33,11 +28,8 @@ if (isset($match) && ! empty($match[1])) { define('PMA_PHP_INT_VERSION', 0); } -require_once './libraries/string.lib.php'; +require_once 'libraries/string.lib.php'; -/** - * @package phpMyAdmin-test - */ class PMA_STR_sub_test extends PHPUnit_Framework_TestCase { public function testMultiByte() diff --git a/test/PMA_blowfish_test.php b/test/libraries/PMA_blowfish_test.php similarity index 87% rename from test/PMA_blowfish_test.php rename to test/libraries/PMA_blowfish_test.php index 234339abcd..d860bd05cf 100644 --- a/test/PMA_blowfish_test.php +++ b/test/libraries/PMA_blowfish_test.php @@ -6,21 +6,11 @@ * @package phpMyAdmin-test */ -/** - * Tests core. - */ -require_once 'PHPUnit/Framework.php'; - -/** +/* * Include to test. */ -require_once './libraries/blowfish.php'; +require_once 'libraries/blowfish.php'; -/** - * Test java script escaping. - * - * @package phpMyAdmin-test - */ class PMA_blowfish_test extends PHPUnit_Framework_TestCase { public function testEncryptDecryptNumbers() @@ -39,6 +29,7 @@ class PMA_blowfish_test extends PHPUnit_Framework_TestCase PMA_blowfish_decrypt(PMA_blowfish_encrypt($string, $secret), $secret)); } + /* Due to differences in the initialization factor, these tests are not portable between systems. public function testEncrypt() { $secret = '$%ÄüfuDFRR'; @@ -54,6 +45,7 @@ class PMA_blowfish_test extends PHPUnit_Framework_TestCase $decrypted = '12345678'; $this->assertEquals($decrypted, PMA_blowfish_decrypt($encrypted, $secret)); } + */ } ?> diff --git a/test/libraries/PMA_escapeJsString_test.php b/test/libraries/PMA_escapeJsString_test.php new file mode 100644 index 0000000000..93afaef775 --- /dev/null +++ b/test/libraries/PMA_escapeJsString_test.php @@ -0,0 +1,36 @@ +assertEquals($target, PMA_escapeJsString($source)); + } + + public function escapeDataProvider() { + return array( + array('\\\';', '\';'), + array('\r\n\\\'"), + array('\\\';[XSS]', '\';[XSS]'), + array('[HTML]', '[HTML]'), + array('\"\\\'\\\\\\\'\"', '"\'\\\'"'), + array("\\\\\'\'\'\'\'\'\'\'\'\'\'\'\\\\", "\\''''''''''''\\") + ); + } +} +?> diff --git a/test/PMA_generateCommonUrl_test.php b/test/libraries/PMA_generateCommonUrl_test.php similarity index 96% rename from test/PMA_generateCommonUrl_test.php rename to test/libraries/PMA_generateCommonUrl_test.php index 22e948b6b6..cc2aacfccb 100644 --- a/test/PMA_generateCommonUrl_test.php +++ b/test/libraries/PMA_generateCommonUrl_test.php @@ -6,16 +6,12 @@ * @package phpMyAdmin-test */ -/** - * +/* + * Include to test. */ -require_once 'PHPUnit/Framework.php'; -require_once './libraries/core.lib.php'; -require_once './libraries/url_generating.lib.php'; +require_once 'libraries/core.lib.php'; +require_once 'libraries/url_generating.lib.php'; -/** - * @package phpMyAdmin-test - */ class PMA_generate_common_url_test extends PHPUnit_Framework_TestCase { public function setUp() diff --git a/test/PMA_sanitize_test.php b/test/libraries/PMA_sanitize_test.php similarity index 87% rename from test/PMA_sanitize_test.php rename to test/libraries/PMA_sanitize_test.php index 1400c7edee..0e7704c634 100644 --- a/test/PMA_sanitize_test.php +++ b/test/libraries/PMA_sanitize_test.php @@ -6,15 +6,12 @@ * @package phpMyAdmin-test */ -/** - * +/* + * Include to test */ -require_once 'PHPUnit/Framework.php'; -require_once './libraries/sanitizing.lib.php'; +require_once 'libraries/sanitizing.lib.php'; +require_once 'libraries/core.lib.php'; -/** - * @package phpMyAdmin-test - */ class PMA_sanitize_test extends PHPUnit_Framework_TestCase { public function testXssInHref() @@ -23,11 +20,13 @@ class PMA_sanitize_test extends PHPUnit_Framework_TestCase PMA_sanitize('[a@javascript:alert(\'XSS\');@target]link[/a]')); } +/* public function testLink() { $this->assertEquals('link', PMA_sanitize('[a@http://www.phpmyadmin.net/@target]link[/a]')); } +*/ public function testHtmlTags() { diff --git a/test/PMA_transformation_getOptions_test.php b/test/libraries/PMA_transformation_getOptions_test.php similarity index 88% rename from test/PMA_transformation_getOptions_test.php rename to test/libraries/PMA_transformation_getOptions_test.php index 126a6204c5..99d0a10031 100644 --- a/test/PMA_transformation_getOptions_test.php +++ b/test/libraries/PMA_transformation_getOptions_test.php @@ -6,15 +6,11 @@ * @package phpMyAdmin-test */ -/** - * +/* + * Include to test. */ -require_once 'PHPUnit/Framework.php'; -require_once './libraries/transformations.lib.php'; +require_once 'libraries/transformations.lib.php'; -/** - * @package phpMyAdmin-test - */ class PMA_transformation_getOptions_test extends PHPUnit_Framework_TestCase { public function testDefault() diff --git a/test/libraries/common/PMA_ajaxResponse_test.php b/test/libraries/common/PMA_ajaxResponse_test.php new file mode 100644 index 0000000000..7f8d69d77f --- /dev/null +++ b/test/libraries/common/PMA_ajaxResponse_test.php @@ -0,0 +1,72 @@ +expectOutputString('{"success":true,"message":"' . $message . '"}'); + PMA_ajaxResponse($message); + } + + function testAjaxResponseTextWithExtra() + { + $message = 'text'; + $exra = array('str_val' => 'te\x/t"1', 'int_val' => 10); + + $this->expectOutputString('{"success":true,"message":"' . $message . '","str_val":"te\\\\x\/t\"1","int_val":10}'); + PMA_ajaxResponse($message, true, $exra); + } + + function testAjaxResponseTextError() + { + $message = 'error_text'; + + $this->expectOutputString('{"success":false,"error":"' . $message . '"}'); + PMA_ajaxResponse($message, false); + } + + function testAjaxResponseMessage() + { + $message = new PMA_Message("Message Text", 1); + + $this->expectOutputString('{"success":true,"message":"
Message Text<\/div>"}'); + PMA_ajaxResponse($message); + } + + function testAjaxResponseMessageWithExtra() + { + + $message = new PMA_Message("Message Text", 1); + $exra = array('str_val' => 'te\x/t"1', 'int_val' => 10); + + $this->expectOutputString('{"success":true,"message":"
Message Text<\/div>","str_val":"te\\\\x\/t\"1","int_val":10}'); + PMA_ajaxResponse($message, true, $exra); + } + + function testAjaxResponseMessageError() + { + + $message = new PMA_Message("Error Message Text", 1); + + // TODO: class for output div should be "error" + $this->expectOutputString('{"success":false,"error":"
Error Message Text<\/div>"}'); + PMA_ajaxResponse($message, false); + } + +} \ No newline at end of file diff --git a/test/libraries/common/PMA_browseUploadFile_test.php b/test/libraries/common/PMA_browseUploadFile_test.php new file mode 100644 index 0000000000..45b8407d26 --- /dev/null +++ b/test/libraries/common/PMA_browseUploadFile_test.php @@ -0,0 +1,48 @@ +expectOutputString('' + . '' + . '' + . '' + . "(" . __('Max: '). $res . $unit .")" . "\n" + . '' . "\n"); + + PMA_browseUploadFile($size); + } +} \ No newline at end of file diff --git a/test/libraries/common/PMA_buildActionTitles_test.php b/test/libraries/common/PMA_buildActionTitles_test.php new file mode 100644 index 0000000000..130a972f99 --- /dev/null +++ b/test/libraries/common/PMA_buildActionTitles_test.php @@ -0,0 +1,42 @@ +assertEquals($titles, PMA_buildActionTitles()); + + } +} \ No newline at end of file diff --git a/test/PMA_cache_test.php b/test/libraries/common/PMA_cache_test.php similarity index 83% rename from test/PMA_cache_test.php rename to test/libraries/common/PMA_cache_test.php index 34aa5f98d4..2284078c4a 100644 --- a/test/PMA_cache_test.php +++ b/test/libraries/common/PMA_cache_test.php @@ -5,22 +5,14 @@ * * @package phpMyAdmin-test * @version $Id: PMA_cache_test.php + * @group common.lib-tests */ -/** - * Tests core. - */ -require_once 'PHPUnit/Framework.php'; - -/** +/* * Include to test. */ -require_once './libraries/common.lib.php'; +require_once 'libraries/common.lib.php'; -/** - * Test cache. - * - */ class PMA_cache_test extends PHPUnit_Framework_TestCase { @@ -99,5 +91,18 @@ class PMA_cache_test extends PHPUnit_Framework_TestCase PMA_cacheUnset('test_data_2', true); $this->assertArrayNotHasKey('test_data_2', $_SESSION['cache']['server_server']); } + + /** + * Test clearing user cache + */ + public function testClearUserCache() + { + $GLOBALS['server'] = 'server'; + PMA_cacheSet('is_superuser', 'yes', true); + $this->assertEquals('yes', $_SESSION['cache']['server_server']['is_superuser']); + + PMA_clearUserCache(); + $this->assertArrayNotHasKey('is_superuser', $_SESSION['cache']['server_server']); + } } ?> diff --git a/test/libraries/common/PMA_checkParameters_test.php b/test/libraries/common/PMA_checkParameters_test.php new file mode 100644 index 0000000000..f72b880ecd --- /dev/null +++ b/test/libraries/common/PMA_checkParameters_test.php @@ -0,0 +1,46 @@ +getPath(); + + $this->expectOutputRegex("/Missing parameter: field/" ); + + PMA_checkParameters(array('db', 'table', 'field'), false); + } + + function testCheckParameter() + { + $GLOBALS['PMA_PHP_SELF'] = PMA_getenv('PHP_SELF'); + $GLOBALS['pmaThemePath'] = $_SESSION['PMA_Theme']->getPath(); + $GLOBALS['table'] = "tblTable"; + $GLOBALS['field'] = "test_field"; + $GLOBALS['sql_query'] = "SELECT * FROM tblTable;"; + + $this->expectOutputString(""); + PMA_checkParameters(array('db', 'table', 'field', 'sql_query'), false); + } +} \ No newline at end of file diff --git a/test/libraries/common/PMA_contains_nonprintable_ascii_test.php b/test/libraries/common/PMA_contains_nonprintable_ascii_test.php new file mode 100644 index 0000000000..8f4059ee5f --- /dev/null +++ b/test/libraries/common/PMA_contains_nonprintable_ascii_test.php @@ -0,0 +1,37 @@ +assertEquals($res,PMA_contains_nonprintable_ascii($str)); + } + +} + +// PMA_contains_nonprintable_ascii \ No newline at end of file diff --git a/test/libraries/common/PMA_convert_bit_default_value_test.php b/test/libraries/common/PMA_convert_bit_default_value_test.php new file mode 100644 index 0000000000..d54ab2d3ce --- /dev/null +++ b/test/libraries/common/PMA_convert_bit_default_value_test.php @@ -0,0 +1,33 @@ +assertEquals($val, PMA_convert_bit_default_value($bit)); + + } +} diff --git a/test/libraries/common/PMA_displayMaximumUploadSize_test.php b/test/libraries/common/PMA_displayMaximumUploadSize_test.php new file mode 100644 index 0000000000..ad93ddb4f3 --- /dev/null +++ b/test/libraries/common/PMA_displayMaximumUploadSize_test.php @@ -0,0 +1,41 @@ +assertEquals("(" . __('Max: '). $res . $unit .")", PMA_displayMaximumUploadSize($size)); + + } +} \ No newline at end of file diff --git a/test/libraries/common/PMA_display_html_checkbox_test.php b/test/libraries/common/PMA_display_html_checkbox_test.php new file mode 100644 index 0000000000..c779d7212f --- /dev/null +++ b/test/libraries/common/PMA_display_html_checkbox_test.php @@ -0,0 +1,55 @@ +expectOutputString(''); + PMA_display_html_checkbox($name,$label,false,false); + } + + function testDisplayHtmlCheckboxChecked() + { + $name = "test_display_html_checkbox"; + $label = "text_label_for_checkbox"; + + $this->expectOutputString(''); + PMA_display_html_checkbox($name,$label,true,false); + } + + function testDisplayHtmlCheckboxOnclick() + { + $name = "test_display_html_checkbox"; + $label = "text_label_for_checkbox"; + + $this->expectOutputString(''); + PMA_display_html_checkbox($name,$label,false,true); + } + + function testDisplayHtmlCheckboxCheckedOnclick() + { + $name = "test_display_html_checkbox"; + $label = "text_label_for_checkbox"; + + $this->expectOutputString(''); + PMA_display_html_checkbox($name,$label,true,true); + } +} + +//PMA_display_html_checkbox \ No newline at end of file diff --git a/test/libraries/common/PMA_display_html_radio_test.php b/test/libraries/common/PMA_display_html_radio_test.php new file mode 100644 index 0000000000..c5f2d4b898 --- /dev/null +++ b/test/libraries/common/PMA_display_html_radio_test.php @@ -0,0 +1,188 @@ +expectOutputString(""); + PMA_display_html_radio($name,$choices); + } + + function testDisplayHtmlRadio() + { + $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 .= '' . $choice_label . ''; + $out .= '
'; + $out .= "\n"; + } + + $this->expectOutputString($out); + PMA_display_html_radio($name,$choices); + } + + function testDisplayHtmlRadioWithChecked() + { + $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 .= '' . $choice_label . ''; + $out .= '
'; + $out .= "\n"; + } + + $this->expectOutputString($out); + PMA_display_html_radio($name,$choices,$checked_choice); + } + + function testDisplayHtmlRadioWithCheckedWithClass() + { + $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 .= '
'; + $out .= '' . $choice_label . ''; + $out .= '
'; + $out .= '
'; + $out .= "\n"; + } + + $this->expectOutputString($out); + PMA_display_html_radio($name,$choices,$checked_choice,true,false,$class); + } + + function testDisplayHtmlRadioWithoutBR() + { + $name = "test_display_radio"; + $choices = array('value_1'=>'choice_1', 'value&_<2>'=>'choice_2'); + $checked_choice = "choice_2"; + + $out = ""; + foreach ($choices as $choice_value => $choice_label) { + $html_field_id = $name . '_' . $choice_value; + $out .= '' . $choice_label . ''; + $out .= "\n"; + } + + $this->expectOutputString($out); + PMA_display_html_radio($name,$choices,$checked_choice,false); + } + + function testDisplayHtmlRadioEscapeLabelEscapeLabel() + { + $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 .= '' . htmlspecialchars($choice_label) . ''; + $out .= '
'; + $out .= "\n"; + } + + $this->expectOutputString($out); + PMA_display_html_radio($name,$choices,$checked_choice,true,true); + } + + function testDisplayHtmlRadioEscapeLabelNotEscapeLabel() + { + $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 .= '' . $choice_label . ''; + $out .= '
'; + $out .= "\n"; + } + + $this->expectOutputString($out); + PMA_display_html_radio($name,$choices,$checked_choice,true,false); + } + + function testDisplayHtmlRadioEscapeLabelEscapeLabelWithClass() + { + $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 .= '
'; + $out .= '' . htmlspecialchars($choice_label) . ''; + $out .= '
'; + $out .= '
'; + $out .= "\n"; + } + + $this->expectOutputString($out); + PMA_display_html_radio($name,$choices,$checked_choice,true,true,$class); + } +} \ No newline at end of file diff --git a/test/PMA_escapeMySqlWildcards_test.php b/test/libraries/common/PMA_escapeMySqlWildcards_test.php similarity index 87% rename from test/PMA_escapeMySqlWildcards_test.php rename to test/libraries/common/PMA_escapeMySqlWildcards_test.php index ccdf15b972..c77a841fe7 100644 --- a/test/PMA_escapeMySqlWildcards_test.php +++ b/test/libraries/common/PMA_escapeMySqlWildcards_test.php @@ -4,22 +4,15 @@ * Test for MySQL Wildcards escaping/unescaping * * @package phpMyAdmin-test + * @version $Id: PMA_escapeMySqlWildcards_test.php + * @group common.lib-tests */ -/** - * Tests core. - */ -require_once 'PHPUnit/Framework.php'; - -/** +/* * Include to test. */ -require_once './libraries/common.lib.php'; +require_once 'libraries/common.lib.php'; -/** - * Test MySQL escaping. - * - */ class PMA_escapeMySqlWildcards_test extends PHPUnit_Framework_TestCase { diff --git a/test/libraries/common/PMA_extractValueFromFormattedSize_test.php b/test/libraries/common/PMA_extractValueFromFormattedSize_test.php new file mode 100644 index 0000000000..038a36e427 --- /dev/null +++ b/test/libraries/common/PMA_extractValueFromFormattedSize_test.php @@ -0,0 +1,37 @@ +assertEquals(-1,PMA_extractValueFromFormattedSize(100)); + } + + function testExtractValueFromFormattedSizeGB(){ + + $this->assertEquals(10737418240,PMA_extractValueFromFormattedSize("10GB")); + } + + function testExtractValueFromFormattedSizeMB(){ + + $this->assertEquals(15728640,PMA_extractValueFromFormattedSize("15MB")); + } + + function testExtractValueFromFormattedSizeK(){ + + $this->assertEquals(262144,PMA_extractValueFromFormattedSize("256K")); + } +} diff --git a/test/PMA_foreignKeySupported_test.php b/test/libraries/common/PMA_foreignKeySupported_test.php similarity index 82% rename from test/PMA_foreignKeySupported_test.php rename to test/libraries/common/PMA_foreignKeySupported_test.php index f00afca2c4..e0ebd2e8d5 100644 --- a/test/PMA_foreignKeySupported_test.php +++ b/test/libraries/common/PMA_foreignKeySupported_test.php @@ -4,28 +4,20 @@ * Test for supporting foreign key * * @package phpMyAdmin-test + * @version $Id: PMA_foreignKeySupported_test.php + * @group common.lib-tests */ -/** - * Tests core. - */ -require_once 'PHPUnit/Framework.php'; - -/** +/* * Include to test. */ -require_once './libraries/common.lib.php'; +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), @@ -38,7 +30,6 @@ class PMA_foreignKeySupported_test extends PHPUnit_Framework_TestCase * 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/libraries/common/PMA_formatNumberByteDown_test.php similarity index 62% rename from test/PMA_formatNumberByteDown_test.php rename to test/libraries/common/PMA_formatNumberByteDown_test.php index 1bc3d063e5..f0265c6233 100644 --- a/test/PMA_formatNumberByteDown_test.php +++ b/test/libraries/common/PMA_formatNumberByteDown_test.php @@ -5,35 +5,24 @@ * * @package phpMyAdmin-test * @version $Id: PMA_formatNumberByteDown_test.php + * @group common.lib-tests */ -/** - * Tests core. - */ -require_once 'PHPUnit/Framework.php'; - -/** +/* * Include to test. */ -require_once './libraries/common.lib.php'; +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; /** @@ -62,14 +51,14 @@ class PMA_formatNumberByteDown_test extends PHPUnit_Framework_TestCase public function formatNumberDataProvider() { return array( - array(10, 2, 2, '10,00 '), + array(10, 2, 2, '10 '), 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') + array(100, 2, 2, '100 '), + array(-1000.454, 4, 2, '-1,000.45 '), + array(0.00003, 3, 2, '30 µ'), + array(0.003, 3, 3, '3 m'), + array(-0.003, 6, 0, '-3,000 µ'), + array(100.98, 0, 2, '100.98') ); } @@ -77,24 +66,22 @@ class PMA_formatNumberByteDown_test extends PHPUnit_Framework_TestCase * format number test, globals are defined * @dataProvider formatNumberDataProvider */ - - public function testFormatNumber($a, $b, $c, $e) { - $this->assertEquals($e, (string)PMA_formatNumber($a, $b, $c, false)); + public function testFormatNumber($a, $b, $c, $d) { + $this->assertEquals($d, (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')) + 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'))) ); } @@ -102,7 +89,6 @@ class PMA_formatNumberByteDown_test extends PHPUnit_Framework_TestCase * format byte test, globals are defined * @dataProvider formatByteDownDataProvider */ - public function testFormatByteDown($a, $b, $c, $e) { $result = PMA_formatByteDown($a, $b, $c); $result[0] = trim($result[0]); diff --git a/test/libraries/common/PMA_formatSql_test.php b/test/libraries/common/PMA_formatSql_test.php new file mode 100644 index 0000000000..df0ddc4f4b --- /dev/null +++ b/test/libraries/common/PMA_formatSql_test.php @@ -0,0 +1,744 @@ +tmpCfg = $cfg; + } + + /** + * recovering globals and session + */ + public function tearDown() { + global $cfg; + $cfg = $this->tmpCfg; + } + + function testFormatSQLNotArray(){ + global $cfg; + $cfg['SQP']['fmtType'] = 'html'; + $sql = "SELECT * FROM tTable;"; + $this->assertEquals("
\n$sql\n
",PMA_formatSql($sql)); + } + + function testFormatSQLfmTypeHtml_1(){ + global $cfg; + $cfg['SQP']['fmtType'] = 'html'; + $cfg['MySQLManualType'] = 'viewable'; + + $sql = array ( + 'raw' => 'SELECT 1;', + 0 => + array ( + 'type' => 'alpha_reservedWord', + 'data' => 'SELECT', + 'pos' => 6, + 'forbidden' => true, + ), + 1 => + array ( + 'type' => 'digit_integer', + 'data' => '1', + 'pos' => 8, + ), + 2 => + array ( + 'type' => 'punct_queryend', + 'data' => ';', + 'pos' => 0, + ), + 'len' => 3, + ); + $unparsed = "SELECT 1;"; + $expected = 'SELECT 1 ;

'; + + $this->assertEquals($expected,PMA_formatSql($sql, $unparsed)); + } + + function testFormatSQLfmTypeHtml_2(){ + global $cfg; + $cfg['SQP']['fmtType'] = 'html'; + $cfg['MySQLManualType'] = 'viewable'; + + $unparsed = "SELECT * from `tTable`;"; + $sql = array ( + 'raw' => $unparsed, + 0 => + array ( + 'type' => 'alpha_reservedWord', + 'data' => 'SELECT', + 'pos' => 6, + 'forbidden' => true, + ), + 1 => + array ( + 'type' => 'punct', + 'data' => '*', + 'pos' => 0, + ), + 2 => + array ( + 'type' => 'alpha_reservedWord', + 'data' => 'from', + 'pos' => 13, + 'forbidden' => true, + ), + 3 => + array ( + 'type' => 'quote_backtick', + 'data' => '`tTable`', + 'pos' => 0, + ), + 4 => + array ( + 'type' => 'punct_queryend', + 'data' => ';', + 'pos' => 0, + ), + 'len' => 5, + ); + $expected = 'SELECT *
FROM `tTable` ;

'; + + $this->assertEquals($expected,PMA_formatSql($sql, $unparsed)); + } + + function testFormatSQLfmTypeHtml_3(){ + global $cfg; + $cfg['SQP']['fmtType'] = 'html'; + $cfg['MySQLManualType'] = 'viewable'; + + $unparsed = 'SELECT * FROM `tTable_A` A INNER JOIN `tTable_B` B ON B.ID = A.ID;'; + $sql = array ( + 'raw' => $unparsed, + 0 => + array ( + 'type' => 'alpha_reservedWord', + 'data' => 'SELECT', + 'pos' => 6, + 'forbidden' => true, + ), + 1 => + array ( + 'type' => 'punct', + 'data' => '*', + 'pos' => 0, + ), + 2 => + array ( + 'type' => 'alpha_reservedWord', + 'data' => 'FROM', + 'pos' => 13, + 'forbidden' => true, + ), + 3 => + array ( + 'type' => 'quote_backtick', + 'data' => '`tTable_A`', + 'pos' => 0, + ), + 4 => + array ( + 'type' => 'alpha_identifier', + 'data' => 'A', + 'pos' => 26, + 'forbidden' => false, + ), + 5 => + array ( + 'type' => 'alpha_reservedWord', + 'data' => 'INNER', + 'pos' => 32, + 'forbidden' => true, + ), + 6 => + array ( + 'type' => 'alpha_reservedWord', + 'data' => 'JOIN', + 'pos' => 37, + 'forbidden' => true, + ), + 7 => + array ( + 'type' => 'quote_backtick', + 'data' => '`tTable_B`', + 'pos' => 0, + ), + 8 => + array ( + 'type' => 'alpha_identifier', + 'data' => 'B', + 'pos' => 50, + 'forbidden' => false, + ), + 9 => + array ( + 'type' => 'alpha_reservedWord', + 'data' => 'ON', + 'pos' => 53, + 'forbidden' => true, + ), + 10 => + array ( + 'type' => 'alpha_identifier', + 'data' => 'B', + 'pos' => 55, + 'forbidden' => false, + ), + 11 => + array ( + 'type' => 'punct_qualifier', + 'data' => '.', + 'pos' => 0, + ), + 12 => + array ( + 'type' => 'alpha_identifier', + 'data' => 'ID', + 'pos' => 58, + 'forbidden' => false, + ), + 13 => + array ( + 'type' => 'punct', + 'data' => '=', + 'pos' => 0, + ), + 14 => + array ( + 'type' => 'alpha_identifier', + 'data' => 'A', + 'pos' => 62, + 'forbidden' => false, + ), + 15 => + array ( + 'type' => 'punct_qualifier', + 'data' => '.', + 'pos' => 0, + ), + 16 => + array ( + 'type' => 'alpha_identifier', + 'data' => 'ID', + 'pos' => 65, + 'forbidden' => false, + ), + 17 => + array ( + 'type' => 'punct_queryend', + 'data' => ';', + 'pos' => 0, + ), + 'len' => 18, + ); + + $expected = 'SELECT *
FROM `tTable_A` A
INNER JOIN `tTable_B` B ON B.ID = A.ID;

'; + + $this->assertEquals($expected,PMA_formatSql($sql, $unparsed)); + } + + function testFormatSQLfmTypeText_1(){ + global $cfg; + $cfg['SQP']['fmtType'] = 'text'; + $cfg['MySQLManualType'] = 'viewable'; + + $sql = array ( + 'raw' => 'SELECT 1;', + 0 => + array ( + 'type' => 'alpha_reservedWord', + 'data' => 'SELECT', + 'pos' => 6, + 'forbidden' => true, + ), + 1 => + array ( + 'type' => 'digit_integer', + 'data' => '1', + 'pos' => 8, + ), + 2 => + array ( + 'type' => 'punct_queryend', + 'data' => ';', + 'pos' => 0, + ), + 'len' => 3, + ); + $unparsed = "SELECT 1;"; + $expected = 'SELECT 1 ;

'; + + $this->assertEquals($expected,PMA_formatSql($sql, $unparsed)); + } + + function testFormatSQLfmTypeText_2(){ + global $cfg; + $cfg['SQP']['fmtType'] = 'text'; + $cfg['MySQLManualType'] = 'viewable'; + + $unparsed = "SELECT * from `tTable`;"; + $sql = array ( + 'raw' => $unparsed, + 0 => + array ( + 'type' => 'alpha_reservedWord', + 'data' => 'SELECT', + 'pos' => 6, + 'forbidden' => true, + ), + 1 => + array ( + 'type' => 'punct', + 'data' => '*', + 'pos' => 0, + ), + 2 => + array ( + 'type' => 'alpha_reservedWord', + 'data' => 'from', + 'pos' => 13, + 'forbidden' => true, + ), + 3 => + array ( + 'type' => 'quote_backtick', + 'data' => '`tTable`', + 'pos' => 0, + ), + 4 => + array ( + 'type' => 'punct_queryend', + 'data' => ';', + 'pos' => 0, + ), + 'len' => 5, + ); + $expected = 'SELECT *
FROM `tTable` ;

'; + + $this->assertEquals($expected,PMA_formatSql($sql, $unparsed)); + } + + function testFormatSQLfmTypeText_3(){ + global $cfg; + $cfg['SQP']['fmtType'] = 'text'; + $cfg['MySQLManualType'] = 'viewable'; + + $unparsed = 'SELECT * FROM `tTable_A` A INNER JOIN `tTable_B` B ON B.ID = A.ID;'; + $sql = array ( + 'raw' => $unparsed, + 0 => + array ( + 'type' => 'alpha_reservedWord', + 'data' => 'SELECT', + 'pos' => 6, + 'forbidden' => true, + ), + 1 => + array ( + 'type' => 'punct', + 'data' => '*', + 'pos' => 0, + ), + 2 => + array ( + 'type' => 'alpha_reservedWord', + 'data' => 'FROM', + 'pos' => 13, + 'forbidden' => true, + ), + 3 => + array ( + 'type' => 'quote_backtick', + 'data' => '`tTable_A`', + 'pos' => 0, + ), + 4 => + array ( + 'type' => 'alpha_identifier', + 'data' => 'A', + 'pos' => 26, + 'forbidden' => false, + ), + 5 => + array ( + 'type' => 'alpha_reservedWord', + 'data' => 'INNER', + 'pos' => 32, + 'forbidden' => true, + ), + 6 => + array ( + 'type' => 'alpha_reservedWord', + 'data' => 'JOIN', + 'pos' => 37, + 'forbidden' => true, + ), + 7 => + array ( + 'type' => 'quote_backtick', + 'data' => '`tTable_B`', + 'pos' => 0, + ), + 8 => + array ( + 'type' => 'alpha_identifier', + 'data' => 'B', + 'pos' => 50, + 'forbidden' => false, + ), + 9 => + array ( + 'type' => 'alpha_reservedWord', + 'data' => 'ON', + 'pos' => 53, + 'forbidden' => true, + ), + 10 => + array ( + 'type' => 'alpha_identifier', + 'data' => 'B', + 'pos' => 55, + 'forbidden' => false, + ), + 11 => + array ( + 'type' => 'punct_qualifier', + 'data' => '.', + 'pos' => 0, + ), + 12 => + array ( + 'type' => 'alpha_identifier', + 'data' => 'ID', + 'pos' => 58, + 'forbidden' => false, + ), + 13 => + array ( + 'type' => 'punct', + 'data' => '=', + 'pos' => 0, + ), + 14 => + array ( + 'type' => 'alpha_identifier', + 'data' => 'A', + 'pos' => 62, + 'forbidden' => false, + ), + 15 => + array ( + 'type' => 'punct_qualifier', + 'data' => '.', + 'pos' => 0, + ), + 16 => + array ( + 'type' => 'alpha_identifier', + 'data' => 'ID', + 'pos' => 65, + 'forbidden' => false, + ), + 17 => + array ( + 'type' => 'punct_queryend', + 'data' => ';', + 'pos' => 0, + ), + 'len' => 18, + ); + $expected = 'SELECT *
FROM `tTable_A` A
INNER JOIN `tTable_B` B ON B.ID = A.ID;

'; + + $this->assertEquals($expected,PMA_formatSql($sql, $unparsed)); + } + + function testFormatSQLfmTypeNone_1(){ + global $cfg; + $cfg['SQP']['fmtType'] = 'none'; + $cfg['MySQLManualType'] = 'viewable'; + + $sql = array ( + 'raw' => 'SELECT 1;', + 0 => + array ( + 'type' => 'alpha_reservedWord', + 'data' => 'SELECT', + 'pos' => 6, + 'forbidden' => true, + ), + 1 => + array ( + 'type' => 'digit_integer', + 'data' => '1', + 'pos' => 8, + ), + 2 => + array ( + 'type' => 'punct_queryend', + 'data' => ';', + 'pos' => 0, + ), + 'len' => 3, + ); + $unparsed = "SELECT 1;"; + + $expected = "
\nSELECT 1;\n
"; + $this->assertEquals($expected,PMA_formatSql($sql, $unparsed)); + + $expected = "SELECT 1;"; + $this->assertEquals($expected,PMA_formatSql($sql)); + } + + function testFormatSQLfmTypeNone_2(){ + global $cfg; + $cfg['SQP']['fmtType'] = 'none'; + $cfg['MySQLManualType'] = 'viewable'; + + $unparsed = "SELECT * from `tTable`;"; + $sql = array ( + 'raw' => $unparsed, + 0 => + array ( + 'type' => 'alpha_reservedWord', + 'data' => 'SELECT', + 'pos' => 6, + 'forbidden' => true, + ), + 1 => + array ( + 'type' => 'punct', + 'data' => '*', + 'pos' => 0, + ), + 2 => + array ( + 'type' => 'alpha_reservedWord', + 'data' => 'from', + 'pos' => 13, + 'forbidden' => true, + ), + 3 => + array ( + 'type' => 'quote_backtick', + 'data' => '`tTable`', + 'pos' => 0, + ), + 4 => + array ( + 'type' => 'punct_queryend', + 'data' => ';', + 'pos' => 0, + ), + 'len' => 5, + ); + + $expected = "
\nSELECT * from `tTable`;\n
"; + $this->assertEquals($expected,PMA_formatSql($sql, $unparsed)); + + $expected = "SELECT * from `tTable`;"; + $this->assertEquals($expected,PMA_formatSql($sql)); + } + + function testFormatSQLfmTypeNone_3(){ + global $cfg; + $cfg['SQP']['fmtType'] = 'none'; + $cfg['MySQLManualType'] = 'viewable'; + + $unparsed = 'SELECT * FROM `tTable_A` A INNER JOIN `tTable_B` B ON B.ID = A.ID;'; + $sql = array ( + 'raw' => $unparsed, + 0 => + array ( + 'type' => 'alpha_reservedWord', + 'data' => 'SELECT', + 'pos' => 6, + 'forbidden' => true, + ), + 1 => + array ( + 'type' => 'punct', + 'data' => '*', + 'pos' => 0, + ), + 2 => + array ( + 'type' => 'alpha_reservedWord', + 'data' => 'FROM', + 'pos' => 13, + 'forbidden' => true, + ), + 3 => + array ( + 'type' => 'quote_backtick', + 'data' => '`tTable_A`', + 'pos' => 0, + ), + 4 => + array ( + 'type' => 'alpha_identifier', + 'data' => 'A', + 'pos' => 26, + 'forbidden' => false, + ), + 5 => + array ( + 'type' => 'alpha_reservedWord', + 'data' => 'INNER', + 'pos' => 32, + 'forbidden' => true, + ), + 6 => + array ( + 'type' => 'alpha_reservedWord', + 'data' => 'JOIN', + 'pos' => 37, + 'forbidden' => true, + ), + 7 => + array ( + 'type' => 'quote_backtick', + 'data' => '`tTable_B`', + 'pos' => 0, + ), + 8 => + array ( + 'type' => 'alpha_identifier', + 'data' => 'B', + 'pos' => 50, + 'forbidden' => false, + ), + 9 => + array ( + 'type' => 'alpha_reservedWord', + 'data' => 'ON', + 'pos' => 53, + 'forbidden' => true, + ), + 10 => + array ( + 'type' => 'alpha_identifier', + 'data' => 'B', + 'pos' => 55, + 'forbidden' => false, + ), + 11 => + array ( + 'type' => 'punct_qualifier', + 'data' => '.', + 'pos' => 0, + ), + 12 => + array ( + 'type' => 'alpha_identifier', + 'data' => 'ID', + 'pos' => 58, + 'forbidden' => false, + ), + 13 => + array ( + 'type' => 'punct', + 'data' => '=', + 'pos' => 0, + ), + 14 => + array ( + 'type' => 'alpha_identifier', + 'data' => 'A', + 'pos' => 62, + 'forbidden' => false, + ), + 15 => + array ( + 'type' => 'punct_qualifier', + 'data' => '.', + 'pos' => 0, + ), + 16 => + array ( + 'type' => 'alpha_identifier', + 'data' => 'ID', + 'pos' => 65, + 'forbidden' => false, + ), + 17 => + array ( + 'type' => 'punct_queryend', + 'data' => ';', + 'pos' => 0, + ), + 'len' => 18, + ); + + $expected = "
\nSELECT * FROM `tTable_A` A INNER JOIN `tTable_B` B ON B.ID = A.ID;\n
"; + $this->assertEquals($expected,PMA_formatSql($sql, $unparsed)); + + $expected = 'SELECT * FROM `tTable_A` A INNER JOIN `tTable_B` B ON B.ID = A.ID;'; + $this->assertEquals($expected,PMA_formatSql($sql)); + } + + function testFormatSQLWithoutType(){ + global $cfg; + $cfg['SQP']['fmtType'] = ''; + $cfg['MySQLManualType'] = 'viewable'; + $sql = array ( + 'raw' => 'SELECT 1;', + 0 => + array ( + 'type' => 'alpha_reservedWord', + 'data' => 'SELECT', + 'pos' => 6, + 'forbidden' => true, + ), + 1 => + array ( + 'type' => 'digit_integer', + 'data' => '1', + 'pos' => 8, + ), + 2 => + array ( + 'type' => 'punct_queryend', + 'data' => ';', + 'pos' => 0, + ), + 'len' => 3, + ); + $this->assertEmpty(PMA_formatSql($sql)); + } + + function testFormatSQLError(){ + global $SQP_errorString; + $SQP_errorString = true; + $sql = array("raw" => "& \" < >"); + $this->assertEquals("& " < >",PMA_formatSql($sql)); + $SQP_errorString = false; + } +} diff --git a/test/libraries/common/PMA_generateHiddenMaxFileSize_test.php b/test/libraries/common/PMA_generateHiddenMaxFileSize_test.php new file mode 100644 index 0000000000..3cd6810a47 --- /dev/null +++ b/test/libraries/common/PMA_generateHiddenMaxFileSize_test.php @@ -0,0 +1,40 @@ +assertEquals(PMA_generateHiddenMaxFileSize($size), + ''); + } +} diff --git a/test/libraries/common/PMA_generate_html_dropdown_test.php b/test/libraries/common/PMA_generate_html_dropdown_test.php new file mode 100644 index 0000000000..8e27c2088b --- /dev/null +++ b/test/libraries/common/PMA_generate_html_dropdown_test.php @@ -0,0 +1,69 @@ +'; + + $this->assertEquals($result, PMA_generate_html_dropdown($name,$choices,$active_choice,$id)); + } + + function testGenerateHtmlDropdown() + { + $name = "&test_dropdown_name"; + $choices = array("value_1" => "label_1", "value&_2\"" => "label_2"); + $active_choice = null; + $id = "test_<dropdown>_name"; + + $result = ''; + + $this->assertEquals($result, PMA_generate_html_dropdown($name,$choices,$active_choice,$id)); + } + + function testGenerateHtmlDropdownWithActive() + { + $name = "&test_dropdown_name"; + $choices = array("value_1" => "label_1", "value&_2\"" => "label_2"); + $active_choice = "value&_2\""; + $id = "test_<dropdown>_name"; + + $result = ''; + + $this->assertEquals($result, PMA_generate_html_dropdown($name,$choices,$active_choice,$id)); + } +} \ No newline at end of file diff --git a/test/libraries/common/PMA_generate_slider_effect_test.php b/test/libraries/common/PMA_generate_slider_effect_test.php new file mode 100644 index 0000000000..62458be8da --- /dev/null +++ b/test/libraries/common/PMA_generate_slider_effect_test.php @@ -0,0 +1,53 @@ +expectOutputString('
' . "\n" . ' '); + PMA_generate_slider_effect($id,$message); + } + + function testGenerateSliderEffectTestClosed() + { + global $cfg; + $cfg['InitialSlidersState'] = 'closed'; + + $id = "test_id"; + $message = "test_message"; + + $this->expectOutputString('