From 2206d1830146cfa4b267421190ca2855f4687144 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Mon, 14 May 2012 15:01:58 +0200 Subject: [PATCH 01/27] Coding style improvements to advisor tests, add docs --- test/classes/Advisor_test.php | 94 +++++++++++++++++++++++++++++++---- 1 file changed, 83 insertions(+), 11 deletions(-) diff --git a/test/classes/Advisor_test.php b/test/classes/Advisor_test.php index 9023aefd14..c377a8c0f8 100644 --- a/test/classes/Advisor_test.php +++ b/test/classes/Advisor_test.php @@ -10,6 +10,7 @@ * Include to test. */ require_once 'libraries/Advisor.class.php'; +require_once 'libraries/Theme.class.php'; require_once 'libraries/php-gettext/gettext.inc'; require_once 'libraries/url_generating.lib.php'; require_once 'libraries/core.lib.php'; @@ -24,6 +25,11 @@ class Advisor_test extends PHPUnit_Framework_TestCase } /** + * Tests string escaping + * + * @param string $text Text to escape + * @param string $expected Expected output + * * @dataProvider escapeStrings */ public function testEscape($text, $expected) @@ -49,6 +55,12 @@ class Advisor_test extends PHPUnit_Framework_TestCase } /** + * Test for adding rule + * + * @param array $rule Rule to test + * @param array $expected Expected rendered rulle in fired/errors list + * @param string $error Expected error string (null if none error expected) + * * @depends testParse * @dataProvider rulesProvider */ @@ -71,32 +83,92 @@ class Advisor_test extends PHPUnit_Framework_TestCase { return array( array( - array('justification' => 'foo', 'name' => 'Basic', 'issue' => 'issue', 'recommendation' => 'Recommend'), - array('justification' => 'foo', 'id' => 'Basic', 'name' => 'Basic', 'issue' => 'issue', 'recommendation' => 'Recommend'), + array( + 'justification' => 'foo', + 'name' => 'Basic', + 'issue' => 'issue', + 'recommendation' => 'Recommend' + ), + array( + 'justification' => 'foo', + 'id' => 'Basic', + 'name' => 'Basic', + 'issue' => 'issue', + 'recommendation' => 'Recommend' + ), null, ), array( - array('justification' => 'foo', 'name' => 'Variable', 'issue' => 'issue', 'recommendation' => 'Recommend {status_var}'), - array('justification' => 'foo', 'id' => 'Variable', 'name' => 'Variable', 'issue' => 'issue', 'recommendation' => 'Recommend status_var'), + array( + 'justification' => 'foo', + 'name' => 'Variable', + 'issue' => 'issue', + 'recommendation' => 'Recommend {status_var}' + ), + array( + 'justification' => 'foo', + 'id' => 'Variable', + 'name' => 'Variable', + 'issue' => 'issue', + 'recommendation' => 'Recommend status_var' + ), null, ), array( - array('justification' => '%s foo | value', 'name' => 'Format', 'issue' => 'issue', 'recommendation' => 'Recommend'), - array('justification' => '0 foo', 'id' => 'Format', 'name' => 'Format', 'issue' => 'issue', 'recommendation' => 'Recommend'), + array( + 'justification' => '%s foo | value', + 'name' => 'Format', + 'issue' => 'issue', + 'recommendation' => 'Recommend' + ), + array( + 'justification' => '0 foo', + 'id' => 'Format', + 'name' => 'Format', + 'issue' => 'issue', + 'recommendation' => 'Recommend' + ), null, ), array( - array('justification' => '%s% foo | value', 'name' => 'Percent', 'issue' => 'issue', 'recommendation' => 'Recommend'), - array('justification' => '0% foo', 'id' => 'Percent', 'name' => 'Percent', 'issue' => 'issue', 'recommendation' => 'Recommend'), + array( + 'justification' => '%s% foo | value', + 'name' => 'Percent', + 'issue' => 'issue', + 'recommendation' => 'Recommend' + ), + array( + 'justification' => '0% foo', + 'id' => 'Percent', + 'name' => 'Percent', + 'issue' => 'issue', + 'recommendation' => 'Recommend' + ), null, ), array( - array('justification' => '"\'foo', 'name' => 'Quotes', 'issue' => 'issue', 'recommendation' => 'Recommend"\''), - array('justification' => '"\'foo', 'id' => 'Quotes', 'name' => 'Quotes', 'issue' => 'issue', 'recommendation' => 'Recommend"\''), + array( + 'justification' => '"\'foo', + 'name' => 'Quotes', + 'issue' => 'issue', + 'recommendation' => 'Recommend"\'' + ), + array( + 'justification' => '"\'foo', + 'id' => 'Quotes', + 'name' => 'Quotes', + 'issue' => 'issue', + 'recommendation' => 'Recommend"\'' + ), null, ), array( - array('justification' => 'foo | fsafdsa', 'name' => 'Failure', 'issue' => 'issue', 'recommendation' => 'Recommend'), + array( + 'justification' => 'foo | fsafdsa', + 'name' => 'Failure', + 'issue' => 'issue', + 'recommendation' => 'Recommend' + ), array(), 'Failed formatting string for rule \'Failure\'. PHP threw following error: Use of undefined constant fsafdsa - assumed \'fsafdsa\'', ), From cfc3cef521400b6eb17adc18ff65a69798df324b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Mon, 14 May 2012 15:14:34 +0200 Subject: [PATCH 02/27] Use data provider for testing user agent parsing --- test/classes/PMA_Config_test.php | 124 ++++++++++++++++++++++--------- 1 file changed, 89 insertions(+), 35 deletions(-) diff --git a/test/classes/PMA_Config_test.php b/test/classes/PMA_Config_test.php index 86194e14ca..b005f3cdcf 100644 --- a/test/classes/PMA_Config_test.php +++ b/test/classes/PMA_Config_test.php @@ -78,44 +78,74 @@ class PMA_ConfigTest extends PHPUnit_Framework_TestCase */ } - public function testCheckClient() + /** + * Tests client parsing code. + * + * @param string $agent User agent string + * @param string $os Expected parsed OS (or null if none) + * @param string $browser Expected parsed browser (or null if none) + * @param string $version Expected browser version (or null if none) + * + * @dataProvider userAgentProvider + */ + public function testCheckClient($agent, $os, $browser = null, $version = null) { - $_SERVER['HTTP_USER_AGENT'] = 'Opera/9.80 (X11; Linux x86_64; U; pl) Presto/2.7.62 Version/11.00'; + $_SERVER['HTTP_USER_AGENT'] = $agent; $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"); + $this->assertEquals($os, $this->object->get('PMA_USR_OS')); + if ($os != null) { + $this->assertEquals($browser, $this->object->get('PMA_USR_BROWSER_AGENT')); + } + if ($version != null) { + $this->assertEquals($version, $this->object->get('PMA_USR_BROWSER_VER')); + } + } - $_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 userAgentProvider() + { + return array( + array( + 'Opera/9.80 (X11; Linux x86_64; U; pl) Presto/2.7.62 Version/11.00', + 'Linux', + 'OPERA', + '9.80', + ), + array( + 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en-US) AppleWebKit/528.16 OmniWeb/622.8.0.112941', + 'Mac', + 'OMNIWEB', + '622', + ), + array( + 'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1)', + 'Win', + 'IE', + '8.0', + ), + array( + 'Mozilla/5.0 (Unknown; U; Unix BSD/SYSV system; C -) AppleWebKit/527+ (KHTML, like Gecko, Safari/419.3) Arora/0.10.2', + 'Unix', + 'SAFARI', + '5.0.419', + ), + array( + 'Mozilla/5.0 (Windows; U; Win95; en-US; rv:1.9b) Gecko/20031208', + 'Win', + 'GECKO', + '1.9', + ), + array( + 'Mozilla/5.0 (compatible; Konqueror/4.5; NetBSD 5.0.2; X11; amd64; en_US) KHTML/4.5.4 (like Gecko)', + 'Other', + 'KONQUEROR', + ), + array( + 'Mozilla/5.0 (X11; Linux x86_64; rv:5.0) Gecko/20100101 Firefox/5.0', + 'Linux', + 'MOZILLA', + '5.0', + ), + ); } @@ -271,6 +301,7 @@ class PMA_ConfigTest extends PHPUnit_Framework_TestCase } /** + * * * @covers PMA_Config::get * @covers PMA_Config::set @@ -287,6 +318,8 @@ class PMA_ConfigTest extends PHPUnit_Framework_TestCase } /** + * + * * @covers PMA_Config::getSource * @covers PMA_Config::setSource */ @@ -309,6 +342,7 @@ class PMA_ConfigTest extends PHPUnit_Framework_TestCase } /** + * * * @depends testCheckPmaAbsoluteUriEmpty */ @@ -325,6 +359,7 @@ class PMA_ConfigTest extends PHPUnit_Framework_TestCase } /** + * * * @depends testCheckPmaAbsoluteUriNormal */ @@ -342,6 +377,7 @@ class PMA_ConfigTest extends PHPUnit_Framework_TestCase } /** + * * * @depends testCheckPmaAbsoluteUriScheme */ @@ -402,6 +438,7 @@ class PMA_ConfigTest extends PHPUnit_Framework_TestCase } /** + * * * @depends testDetectHttps */ @@ -413,6 +450,7 @@ class PMA_ConfigTest extends PHPUnit_Framework_TestCase } /** + * * * @depends testCheckSystem * @depends testCheckWebServer @@ -444,6 +482,7 @@ class PMA_ConfigTest extends PHPUnit_Framework_TestCase } /** + * * * @todo Implement testSave(). */ @@ -456,6 +495,7 @@ class PMA_ConfigTest extends PHPUnit_Framework_TestCase } /** + * * * @todo Implement testGetFontsizeForm(). */ @@ -468,6 +508,7 @@ class PMA_ConfigTest extends PHPUnit_Framework_TestCase } /** + * * * @todo Implement testRemoveCookie(). */ @@ -479,6 +520,7 @@ class PMA_ConfigTest extends PHPUnit_Framework_TestCase ); } /** + * * * @todo Implement testCheckFontsize(). */ @@ -491,6 +533,7 @@ class PMA_ConfigTest extends PHPUnit_Framework_TestCase } /** + * * * @todo Implement testCheckUpload(). */ @@ -503,6 +546,7 @@ class PMA_ConfigTest extends PHPUnit_Framework_TestCase } /** + * * * @todo Implement testCheckUploadSize(). */ @@ -515,6 +559,7 @@ class PMA_ConfigTest extends PHPUnit_Framework_TestCase } /** + * * * @todo Implement testCheckIsHttps(). */ @@ -527,6 +572,7 @@ class PMA_ConfigTest extends PHPUnit_Framework_TestCase } /** + * * * @todo Implement testGetCookiePath(). */ @@ -539,6 +585,7 @@ class PMA_ConfigTest extends PHPUnit_Framework_TestCase } /** + * * * @todo finish implementing test + dependencies */ @@ -550,6 +597,7 @@ class PMA_ConfigTest extends PHPUnit_Framework_TestCase } /** + * * * @todo Implement testLoadUserPreferences(). */ @@ -561,6 +609,7 @@ class PMA_ConfigTest extends PHPUnit_Framework_TestCase } /** + * * * @todo Implement testSetUserValue(). */ @@ -572,6 +621,7 @@ class PMA_ConfigTest extends PHPUnit_Framework_TestCase } /** + * * * @todo Implement testGetUserValue(). */ @@ -581,6 +631,7 @@ class PMA_ConfigTest extends PHPUnit_Framework_TestCase } /** + * * * @todo Implement testGetThemeUniqueValue(). */ @@ -593,6 +644,7 @@ class PMA_ConfigTest extends PHPUnit_Framework_TestCase } /** + * * * @todo Implement testCheckPermissions(). */ @@ -606,6 +658,7 @@ class PMA_ConfigTest extends PHPUnit_Framework_TestCase /** + * * * @todo Implement testSetCookie(). */ @@ -623,6 +676,7 @@ class PMA_ConfigTest extends PHPUnit_Framework_TestCase } /** + * * * @dataProvider sslUris */ From 82562d8e7dd786a01a4af3cff0c9731deec0563b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Mon, 14 May 2012 15:16:53 +0200 Subject: [PATCH 03/27] Add some contemporary browsers --- test/classes/PMA_Config_test.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/test/classes/PMA_Config_test.php b/test/classes/PMA_Config_test.php index b005f3cdcf..4118441603 100644 --- a/test/classes/PMA_Config_test.php +++ b/test/classes/PMA_Config_test.php @@ -145,6 +145,21 @@ class PMA_ConfigTest extends PHPUnit_Framework_TestCase 'MOZILLA', '5.0', ), + /** + * @todo Is this version really expected? + */ + array( + 'Mozilla/5.0 (X11; Linux x86_64; rv:12.0) Gecko/20100101 Firefox/12.0', + 'Linux', + 'MOZILLA', + '5.0', + ), + array( + 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/535.4+ (KHTML, like Gecko) Version/5.0 Safari/535.4+ SUSE/12.1 (3.2.1) Epiphany/3.2.1', + 'Linux', + 'SAFARI', + '5.0.535', + ), ); } From 92e763a574b0e67da2bbc71239985ee209a30673 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Mon, 14 May 2012 15:18:36 +0200 Subject: [PATCH 04/27] Remove disabled code --- test/classes/PMA_Config_test.php | 9 --------- 1 file changed, 9 deletions(-) diff --git a/test/classes/PMA_Config_test.php b/test/classes/PMA_Config_test.php index 4118441603..32e45bc597 100644 --- a/test/classes/PMA_Config_test.php +++ b/test/classes/PMA_Config_test.php @@ -67,15 +67,6 @@ class PMA_ConfigTest extends PHPUnit_Framework_TestCase $this->object->set('PMA_USR_BROWSER_VER', 5); $this->object->checkOutputCompression(); $this->assertEquals('auto', $this->object->get("OBGzip")); - -/* - Disabled as ini_set is quite often not allowed - @ini_set('zlib.output_compression', 'Off'); - $this->object->checkOutputCompression(); - $this->assertFalse($this->object->get("OBGzip")); - - @ini_set('zlib.output_compression', 'On'); - */ } /** From 3bc02735ca219dfa49c457fad3d9454bc0dfb72a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Mon, 14 May 2012 15:22:55 +0200 Subject: [PATCH 05/27] Document and coding style for SSL rewriting test --- test/classes/PMA_Config_test.php | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/test/classes/PMA_Config_test.php b/test/classes/PMA_Config_test.php index 32e45bc597..14934f29a7 100644 --- a/test/classes/PMA_Config_test.php +++ b/test/classes/PMA_Config_test.php @@ -682,7 +682,10 @@ class PMA_ConfigTest extends PHPUnit_Framework_TestCase } /** + * Tests for rewriting URL to SSL variant * + * @param string $original Original URL + * @param string $expected Expected URL rewritten to SSL * * @dataProvider sslUris */ @@ -695,10 +698,22 @@ class PMA_ConfigTest extends PHPUnit_Framework_TestCase public function sslUris() { return array( - array('http://server.foo/path/', 'https://server.foo:443/path/'), - array('http://server.foo:80/path/', 'https://server.foo:443/path/'), - array('http://server.foo.bar:123/path/', 'https://server.foo.bar:443/path/'), - array('http://[FEDC:BA98:7654:3210:FEDC:BA98:7654:3210]:80/', 'https://[FEDC:BA98:7654:3210:FEDC:BA98:7654:3210]:443/'), + array( + 'http://server.foo/path/', + 'https://server.foo:443/path/' + ), + array( + 'http://server.foo:80/path/', + 'https://server.foo:443/path/' + ), + array( + 'http://server.foo.bar:123/path/', + 'https://server.foo.bar:443/path/' + ), + array( + 'http://[FEDC:BA98:7654:3210:FEDC:BA98:7654:3210]:80/', + 'https://[FEDC:BA98:7654:3210:FEDC:BA98:7654:3210]:443/' + ), ); } } From d3b43b94a7477eba4a1bb4020d2cfc52ebc98d1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Mon, 14 May 2012 15:24:37 +0200 Subject: [PATCH 06/27] Documentation for some tests --- test/classes/PMA_Config_test.php | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/test/classes/PMA_Config_test.php b/test/classes/PMA_Config_test.php index 14934f29a7..ec4b89dd51 100644 --- a/test/classes/PMA_Config_test.php +++ b/test/classes/PMA_Config_test.php @@ -591,9 +591,7 @@ class PMA_ConfigTest extends PHPUnit_Framework_TestCase } /** - * - * - * @todo finish implementing test + dependencies + * Tests loading of config file */ public function testLoad() { @@ -603,9 +601,9 @@ class PMA_ConfigTest extends PHPUnit_Framework_TestCase } /** + * Test for loading user preferences * - * - * @todo Implement testLoadUserPreferences(). + * @todo Test actualy preferences loading */ public function testLoadUserPreferences() { @@ -615,9 +613,7 @@ class PMA_ConfigTest extends PHPUnit_Framework_TestCase } /** - * - * - * @todo Implement testSetUserValue(). + * Test for setting user config value */ public function testSetUserValue() { @@ -627,9 +623,7 @@ class PMA_ConfigTest extends PHPUnit_Framework_TestCase } /** - * - * - * @todo Implement testGetUserValue(). + * Test for getting user config value */ public function testGetUserValue() { @@ -664,9 +658,7 @@ class PMA_ConfigTest extends PHPUnit_Framework_TestCase /** - * - * - * @todo Implement testSetCookie(). + * Test for setting cookies */ public function testSetCookie() { From c5dda33bde3869aea020f949c0d7bd6bda170849 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Mon, 14 May 2012 15:30:24 +0200 Subject: [PATCH 07/27] Do not use caching when running testsuite --- libraries/Config.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/Config.class.php b/libraries/Config.class.php index 43c61dc30c..7705443c6a 100644 --- a/libraries/Config.class.php +++ b/libraries/Config.class.php @@ -1387,7 +1387,7 @@ class PMA_Config { static $cookie_path = null; - if (null !== $cookie_path) { + if (null !== $cookie_path && !defined('TESTSUITE')) { return $cookie_path; } From a09b488b1d7e90ebc50583a80e8b9e587ff7e792 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Mon, 14 May 2012 15:30:50 +0200 Subject: [PATCH 08/27] Loading of defaults can be too long and timeout --- test/classes/PMA_Config_test.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/test/classes/PMA_Config_test.php b/test/classes/PMA_Config_test.php index ec4b89dd51..bfe540adea 100644 --- a/test/classes/PMA_Config_test.php +++ b/test/classes/PMA_Config_test.php @@ -261,6 +261,11 @@ class PMA_ConfigTest extends PHPUnit_Framework_TestCase $this->assertEquals($php_int_ver, $this->object->get('PMA_PHP_INT_VERSION')); } + /** + * Tests loading of default values + * + * @group large + */ public function testLoadDefaults() { $prevDefaultSource = $this->object->default_source; From a98050db2cf058856476bc8d15a7b422e5278bf1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Mon, 14 May 2012 15:31:56 +0200 Subject: [PATCH 09/27] Implement testGetCookiePath test --- test/classes/PMA_Config_test.php | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/test/classes/PMA_Config_test.php b/test/classes/PMA_Config_test.php index bfe540adea..ae64677dfe 100644 --- a/test/classes/PMA_Config_test.php +++ b/test/classes/PMA_Config_test.php @@ -583,15 +583,30 @@ class PMA_ConfigTest extends PHPUnit_Framework_TestCase } /** + * Test for getting cookie path * + * @param string $absolute The absolute URL used for phpMyAdmin + * @param string $expected Expected cookie path * - * @todo Implement testGetCookiePath(). + * @dataProvider cookieUris */ - public function testGetCookiePath() + public function testGetCookiePath($absolute, $expected) { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' + $this->object->set('PmaAbsoluteUri', $absolute); + $this->assertEquals($expected, $this->object->getCookiePath()); + } + + public function cookieUris() + { + return array( + array( + 'http://example.net/phpmyadmin/', + '/phpmyadmin/', + ), + array( + 'http://example.net/', + '/', + ), ); } From e9e05017df0bf414f0d7ee623934e153fb14f3a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Mon, 14 May 2012 15:39:46 +0200 Subject: [PATCH 10/27] Document tests, remove test methods which do not make much sense --- test/classes/PMA_Config_test.php | 72 ++------------------------------ 1 file changed, 4 insertions(+), 68 deletions(-) diff --git a/test/classes/PMA_Config_test.php b/test/classes/PMA_Config_test.php index ae64677dfe..34bebc962b 100644 --- a/test/classes/PMA_Config_test.php +++ b/test/classes/PMA_Config_test.php @@ -449,7 +449,7 @@ class PMA_ConfigTest extends PHPUnit_Framework_TestCase } /** - * + * Test for checking cookie path * * @depends testDetectHttps */ @@ -461,7 +461,7 @@ class PMA_ConfigTest extends PHPUnit_Framework_TestCase } /** - * + * Test for backward compatibility globals * * @depends testCheckSystem * @depends testCheckWebServer @@ -505,70 +505,6 @@ class PMA_ConfigTest extends PHPUnit_Framework_TestCase ); } - /** - * - * - * @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.' - ); - } - /** * * @@ -651,7 +587,7 @@ class PMA_ConfigTest extends PHPUnit_Framework_TestCase } /** - * + * Should test getting unique value for theme * * @todo Implement testGetThemeUniqueValue(). */ @@ -664,7 +600,7 @@ class PMA_ConfigTest extends PHPUnit_Framework_TestCase } /** - * + * Should test checking of config permissions * * @todo Implement testCheckPermissions(). */ From bd8d3e0134ec16dcbe092ab0e08c10939aa2515d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Mon, 14 May 2012 15:40:20 +0200 Subject: [PATCH 11/27] Remove never implemented save method and test for it --- libraries/Config.class.php | 11 ----------- test/classes/PMA_Config_test.php | 13 ------------- 2 files changed, 24 deletions(-) diff --git a/libraries/Config.class.php b/libraries/Config.class.php index 7705443c6a..846e503649 100644 --- a/libraries/Config.class.php +++ b/libraries/Config.class.php @@ -1435,17 +1435,6 @@ class PMA_Config } } - /** - * Saves config file. - * - * @todo finish - * - * @return void - */ - function save() - { - } - /** * returns options for font size selection * diff --git a/test/classes/PMA_Config_test.php b/test/classes/PMA_Config_test.php index 34bebc962b..b373bc1678 100644 --- a/test/classes/PMA_Config_test.php +++ b/test/classes/PMA_Config_test.php @@ -492,19 +492,6 @@ class PMA_ConfigTest extends PHPUnit_Framework_TestCase } } - /** - * - * - * @todo Implement testSave(). - */ - public function testSave() - { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } - /** * * From 1208be3d1a556cab6a39b1fc6cbe9294ba6cc17d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Mon, 14 May 2012 15:44:19 +0200 Subject: [PATCH 12/27] Wrap some long lines --- test/classes/PMA_Config_test.php | 95 +++++++++++++++++++++++++------- 1 file changed, 75 insertions(+), 20 deletions(-) diff --git a/test/classes/PMA_Config_test.php b/test/classes/PMA_Config_test.php index b373bc1678..56b4c3fa5d 100644 --- a/test/classes/PMA_Config_test.php +++ b/test/classes/PMA_Config_test.php @@ -85,10 +85,16 @@ class PMA_ConfigTest extends PHPUnit_Framework_TestCase $this->object->checkClient(); $this->assertEquals($os, $this->object->get('PMA_USR_OS')); if ($os != null) { - $this->assertEquals($browser, $this->object->get('PMA_USR_BROWSER_AGENT')); + $this->assertEquals( + $browser, + $this->object->get('PMA_USR_BROWSER_AGENT') + ); } if ($version != null) { - $this->assertEquals($version, $this->object->get('PMA_USR_BROWSER_VER')); + $this->assertEquals( + $version, + $this->object->get('PMA_USR_BROWSER_VER') + ); } } @@ -171,16 +177,28 @@ class PMA_ConfigTest extends PHPUnit_Framework_TestCase 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'); + $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'); + $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'); + $this->assertEquals( + 0, + $this->object->get('PMA_IS_GD2'), + 'GD Version < 2, PMA_IS_GD2 should be 0' + ); } } @@ -192,9 +210,17 @@ class PMA_ConfigTest extends PHPUnit_Framework_TestCase 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'); + $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'); + $this->assertEquals( + 0, + $this->object->get('PMA_IS_GD2'), + 'PMA_IS_GD2 should be 0' + ); } } } @@ -219,20 +245,20 @@ class PMA_ConfigTest extends PHPUnit_Framework_TestCase 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'); + $this->assertEquals(1, $this->object->get('PMA_IS_WINDOWS')); 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)'); + $this->assertEquals(1, $this->object->get('PMA_IS_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'); + $this->assertEquals(0, $this->object->get('PMA_IS_WINDOWS')); define('PHP_OS', 'Windows'); - $this->assertEquals(1, $this->object->get('PMA_IS_WINDOWS'), 'PMA_IS_WINDOWS must be 1'); + $this->assertEquals(1, $this->object->get('PMA_IS_WINDOWS')); } } @@ -257,8 +283,14 @@ class PMA_ConfigTest extends PHPUnit_Framework_TestCase $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')); + $this->assertEquals( + $php_str_ver, + $this->object->get('PMA_PHP_STR_VERSION') + ); + $this->assertEquals( + $php_int_ver, + $this->object->get('PMA_PHP_INT_VERSION') + ); } /** @@ -282,16 +314,29 @@ class PMA_ConfigTest extends PHPUnit_Framework_TestCase $this->assertTrue($this->object->loadDefaults()); - $this->assertEquals($this->object->default_source_mtime, filemtime($prevDefaultSource)); - $this->assertEquals($loadedConf['Servers'][1], $this->object->default_server); + $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); + $expectedSettings = PMA_array_merge_recursive( + $this->object->settings, + $loadedConf + ); - $this->assertEquals($expectedSettings, $this->object->settings, 'Settings loaded wrong'); + $this->assertEquals( + $expectedSettings, + $this->object->settings, + 'Settings loaded wrong' + ); $this->assertFalse($this->object->error_config_default_file); } @@ -342,14 +387,24 @@ class PMA_ConfigTest extends PHPUnit_Framework_TestCase $this->object->setSource("config.sample.inc.php"); - $this->assertEquals("config.sample.inc.php", $this->object->getSource(), "Cant set new source"); + $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'); + $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' + ); } /** From 121b798f0e7e6ecae88ec08a289f0fd7bd66d4b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Mon, 14 May 2012 15:46:56 +0200 Subject: [PATCH 13/27] Split out checkPmaAbsoluteUri using dataProvider --- test/classes/PMA_Config_test.php | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/test/classes/PMA_Config_test.php b/test/classes/PMA_Config_test.php index 56b4c3fa5d..3d68b2baff 100644 --- a/test/classes/PMA_Config_test.php +++ b/test/classes/PMA_Config_test.php @@ -408,20 +408,33 @@ class PMA_ConfigTest extends PHPUnit_Framework_TestCase } /** + * Checks correcting of absolute URI * + * @param string $real Real URI received + * @param string $expected Expected corrected URI * * @depends testCheckPmaAbsoluteUriEmpty + * @dataProvider absoluteUris */ - public function testCheckPmaAbsoluteUriNormal() + public function testCheckPmaAbsoluteUriNormal($real, $expected) { - $this->object->set('PmaAbsoluteUri', 'http://localhost/phpmyadmin/'); + $this->object->set('PmaAbsoluteUri', $real); $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'); + $this->assertEquals($expected, $this->object->get('PmaAbsoluteUri')); + } + public function absoluteUris() + { + return array( + array( + 'http://localhost/phpmyadmin/', + 'http://localhost/phpmyadmin/', + ), + array( + 'http://localhost/phpmyadmin', + 'http://localhost/phpmyadmin/', + ), + ); } /** From db97f75d96c0d4f16d5f76ae9520a22af69d5c33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Mon, 14 May 2012 15:47:44 +0200 Subject: [PATCH 14/27] Add another test --- test/classes/PMA_Config_test.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test/classes/PMA_Config_test.php b/test/classes/PMA_Config_test.php index 3d68b2baff..426af7ca5e 100644 --- a/test/classes/PMA_Config_test.php +++ b/test/classes/PMA_Config_test.php @@ -434,6 +434,10 @@ class PMA_ConfigTest extends PHPUnit_Framework_TestCase 'http://localhost/phpmyadmin', 'http://localhost/phpmyadmin/', ), + array( + 'localhost/phpmyadmin/', + 'http://localhost/phpmyadmin/', + ), ); } From 5413a168a88d45ea6ce2371076deded7b5ecbbfb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Mon, 14 May 2012 15:48:38 +0200 Subject: [PATCH 15/27] Add missing group --- test/classes/PMA_Config_test.php | 1 + 1 file changed, 1 insertion(+) diff --git a/test/classes/PMA_Config_test.php b/test/classes/PMA_Config_test.php index 426af7ca5e..d03494dcf2 100644 --- a/test/classes/PMA_Config_test.php +++ b/test/classes/PMA_Config_test.php @@ -539,6 +539,7 @@ class PMA_ConfigTest extends PHPUnit_Framework_TestCase * @depends testCheckWebServer * @depends testLoadDefaults * @depends testLoad + * @group large */ public function testEnableBc() { From 7db8a82848992249533ef29700b6609861d3afc5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Mon, 14 May 2012 15:51:55 +0200 Subject: [PATCH 16/27] Separate group from other attrs --- test/classes/PMA_Config_test.php | 1 + 1 file changed, 1 insertion(+) diff --git a/test/classes/PMA_Config_test.php b/test/classes/PMA_Config_test.php index d03494dcf2..3c582f538e 100644 --- a/test/classes/PMA_Config_test.php +++ b/test/classes/PMA_Config_test.php @@ -539,6 +539,7 @@ class PMA_ConfigTest extends PHPUnit_Framework_TestCase * @depends testCheckWebServer * @depends testLoadDefaults * @depends testLoad + * * @group large */ public function testEnableBc() From 71836ff80ba36385e2f6614a344d67a372f9b4ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Mon, 14 May 2012 15:52:05 +0200 Subject: [PATCH 17/27] Remove debug code --- test/classes/PMA_Config_test.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/test/classes/PMA_Config_test.php b/test/classes/PMA_Config_test.php index 3c582f538e..5f583456cb 100644 --- a/test/classes/PMA_Config_test.php +++ b/test/classes/PMA_Config_test.php @@ -625,8 +625,6 @@ class PMA_ConfigTest extends PHPUnit_Framework_TestCase public function testLoadUserPreferences() { $this->assertNull($this->object->loadUserPreferences()); - -// echo $GLOBALS['cfg']['ServerDefault']; } /** From 398992670f7b629e01610d1ea4fc7d4c653a694e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Mon, 14 May 2012 15:57:31 +0200 Subject: [PATCH 18/27] Ignore config only in toplevel dir --- .gitignore | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 6cc231a221..e04571e87d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,9 +1,9 @@ # Directory for creating releases /release/ # Configuration files -config.inc.php -config.header.inc.php -config.footer.inc.php +/config.inc.php +/config.header.inc.php +/config.footer.inc.php # Upload/save dirs /upload/ /save/ @@ -36,4 +36,4 @@ revision-info.php phpunit.xml /test/bootstrap.php # Jenkins -/build/ \ No newline at end of file +/build/ From de343ab837daabb12382eb05c0d09aaf557459ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Mon, 14 May 2012 15:58:18 +0200 Subject: [PATCH 19/27] Test loading some arbitrary file --- test/classes/PMA_Config_test.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test/classes/PMA_Config_test.php b/test/classes/PMA_Config_test.php index 5f583456cb..114901c760 100644 --- a/test/classes/PMA_Config_test.php +++ b/test/classes/PMA_Config_test.php @@ -33,6 +33,7 @@ class PMA_ConfigTest extends PHPUnit_Framework_TestCase protected function setUp() { $this->object = new PMA_Config; + $GLOBALS['server'] = 0; } /** @@ -538,7 +539,6 @@ class PMA_ConfigTest extends PHPUnit_Framework_TestCase * @depends testCheckSystem * @depends testCheckWebServer * @depends testLoadDefaults - * @depends testLoad * * @group large */ @@ -614,6 +614,8 @@ class PMA_ConfigTest extends PHPUnit_Framework_TestCase { $this->assertFalse($this->object->load()); + $this->assertTrue($this->object->load('./test/test_data/config.inc.php')); + $this->assertTrue($this->object->load('./libraries/config.default.php')); } From 69f80f473bd1322d59f4460a423f3954be57048e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Mon, 14 May 2012 16:01:26 +0200 Subject: [PATCH 20/27] More tests for loading config file --- test/classes/PMA_Config_test.php | 33 +++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/test/classes/PMA_Config_test.php b/test/classes/PMA_Config_test.php index 114901c760..7fdd522747 100644 --- a/test/classes/PMA_Config_test.php +++ b/test/classes/PMA_Config_test.php @@ -609,14 +609,37 @@ class PMA_ConfigTest extends PHPUnit_Framework_TestCase /** * Tests loading of config file + * + * @param string $source File name of config to load + * @param boolean $result Expected result of loading + * + * @dataProvider configPaths */ - public function testLoad() + public function testLoad($source, $result) { - $this->assertFalse($this->object->load()); + if ($result) { + $this->assertTrue($this->object->load($source)); + } else { + $this->assertFalse($this->object->load($source)); + } + } - $this->assertTrue($this->object->load('./test/test_data/config.inc.php')); - - $this->assertTrue($this->object->load('./libraries/config.default.php')); + public function configPaths() + { + return array( + array( + './test/test_data/config.inc.php', + true, + ), + array( + './test/test_data/config-nonexisting.inc.php', + false, + ), + array( + './libraries/config.default.php', + true, + ), + ); } /** From 5c466ab97a16ef0082cfc0ad1229e72f5cb03f82 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Mon, 14 May 2012 16:07:07 +0200 Subject: [PATCH 21/27] Add some docs --- test/classes/PMA_Config_test.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/classes/PMA_Config_test.php b/test/classes/PMA_Config_test.php index 7fdd522747..39dbf91b2b 100644 --- a/test/classes/PMA_Config_test.php +++ b/test/classes/PMA_Config_test.php @@ -358,7 +358,7 @@ class PMA_ConfigTest extends PHPUnit_Framework_TestCase } /** - * + * Test getting and setting config values * * @covers PMA_Config::get * @covers PMA_Config::set @@ -375,7 +375,7 @@ class PMA_ConfigTest extends PHPUnit_Framework_TestCase } /** - * + * Tests setting configuration source * * @covers PMA_Config::getSource * @covers PMA_Config::setSource From e96a4379b088069be53a674c64de8e28035b4061 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Mon, 14 May 2012 16:07:19 +0200 Subject: [PATCH 22/27] Merge two tests for checkPmaAbsoluteUri --- test/classes/PMA_Config_test.php | 32 +++++++++++--------------------- 1 file changed, 11 insertions(+), 21 deletions(-) diff --git a/test/classes/PMA_Config_test.php b/test/classes/PMA_Config_test.php index 39dbf91b2b..1314bc9378 100644 --- a/test/classes/PMA_Config_test.php +++ b/test/classes/PMA_Config_test.php @@ -417,7 +417,7 @@ class PMA_ConfigTest extends PHPUnit_Framework_TestCase * @depends testCheckPmaAbsoluteUriEmpty * @dataProvider absoluteUris */ - public function testCheckPmaAbsoluteUriNormal($real, $expected) + public function testCheckPmaAbsoluteUri($real, $expected) { $this->object->set('PmaAbsoluteUri', $real); $this->object->checkPmaAbsoluteUri(); @@ -439,13 +439,21 @@ class PMA_ConfigTest extends PHPUnit_Framework_TestCase 'localhost/phpmyadmin/', 'http://localhost/phpmyadmin/', ), + array( + 'http://user:pwd@localhost/phpmyadmin/index.php', + "http://user:pwd@localhost/phpmyadmin/index.php/", + ), + array( + 'https://user:pwd@localhost/phpmyadmin/index.php', + "https://user:pwd@localhost/phpmyadmin/index.php/", + ), ); } /** + * Test for absolute URI composition * - * - * @depends testCheckPmaAbsoluteUriNormal + * @depends testCheckPmaAbsoluteUri */ public function testCheckPmaAbsoluteUriScheme() { @@ -460,24 +468,6 @@ class PMA_ConfigTest extends PHPUnit_Framework_TestCase $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'; From 44d4a56c20cec232cd0eeb6feb48e4d2137e1783 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Mon, 14 May 2012 16:07:39 +0200 Subject: [PATCH 23/27] Add sample config file --- test/test_data/config.inc.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 test/test_data/config.inc.php diff --git a/test/test_data/config.inc.php b/test/test_data/config.inc.php new file mode 100644 index 0000000000..86e6f6958b --- /dev/null +++ b/test/test_data/config.inc.php @@ -0,0 +1,15 @@ + Date: Mon, 14 May 2012 16:08:35 +0200 Subject: [PATCH 24/27] Remove commented out code --- test/classes/PMA_Config_test.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/test/classes/PMA_Config_test.php b/test/classes/PMA_Config_test.php index 1314bc9378..acf1da21af 100644 --- a/test/classes/PMA_Config_test.php +++ b/test/classes/PMA_Config_test.php @@ -348,9 +348,6 @@ class PMA_ConfigTest extends PHPUnit_Framework_TestCase $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()); From d597d31f9e2725623929ede8bc28ec953bb4d4da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Mon, 14 May 2012 16:09:02 +0200 Subject: [PATCH 25/27] Add doc --- test/classes/PMA_Config_test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/classes/PMA_Config_test.php b/test/classes/PMA_Config_test.php index acf1da21af..5f043d7bf5 100644 --- a/test/classes/PMA_Config_test.php +++ b/test/classes/PMA_Config_test.php @@ -554,7 +554,7 @@ class PMA_ConfigTest extends PHPUnit_Framework_TestCase } /** - * + * Should check for https detection * * @todo Implement testCheckIsHttps(). */ From 1b1f501ac8477d8a1f687c27247b76f17be77814 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Mon, 14 May 2012 16:10:23 +0200 Subject: [PATCH 26/27] Wrap some long lines --- test/classes/PMA_Config_test.php | 63 +++++++++++++++++++++++++++----- 1 file changed, 53 insertions(+), 10 deletions(-) diff --git a/test/classes/PMA_Config_test.php b/test/classes/PMA_Config_test.php index 5f043d7bf5..aaa78b8b4d 100644 --- a/test/classes/PMA_Config_test.php +++ b/test/classes/PMA_Config_test.php @@ -181,7 +181,7 @@ class PMA_ConfigTest extends PHPUnit_Framework_TestCase $this->assertEquals( 0, $this->object->get('PMA_IS_GD2'), - 'Function imagecreatetruecolor does not exist, PMA_IS_GD2 should be 0' + 'imagecreatetruecolor does not exist, PMA_IS_GD2 should be 0' ); } @@ -271,7 +271,11 @@ class PMA_ConfigTest extends PHPUnit_Framework_TestCase $php_str_ver = phpversion(); $match = array(); - preg_match('@([0-9]{1,2}).([0-9]{1,2}).([0-9]{1,2})@', phpversion(), $match); + 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; @@ -279,7 +283,12 @@ class PMA_ConfigTest extends PHPUnit_Framework_TestCase if (! isset($match[3])) { $match[3] = 0; } - $php_int_ver = (int) sprintf('%d%02d%02d', $match[1], $match[2], $match[3]); + $php_int_ver = (int) sprintf( + '%d%02d%02d', + $match[1], + $match[2], + $match[3] + ); } else { $php_int_ver = 0; } @@ -462,7 +471,10 @@ class PMA_ConfigTest extends PHPUnit_Framework_TestCase $this->object->set('PmaAbsoluteUri', ''); $this->object->checkPmaAbsoluteUri(); - $this->assertEquals("http://localhost/", $this->object->get('PmaAbsoluteUri')); + $this->assertEquals( + "http://localhost/", + $this->object->get('PmaAbsoluteUri') + ); } public function testCheckCollationConnection() @@ -470,7 +482,10 @@ class PMA_ConfigTest extends PHPUnit_Framework_TestCase $_REQUEST['collation_connection'] = 'utf-8'; $this->object->checkCollationConnection(); - $this->assertEquals($_REQUEST['collation_connection'], $this->object->get('collation_connection')); + $this->assertEquals( + $_REQUEST['collation_connection'], + $this->object->get('collation_connection') + ); } public function testIsHttps() @@ -646,7 +661,10 @@ class PMA_ConfigTest extends PHPUnit_Framework_TestCase { $this->object->setUserValue(null, 'lang', 'cs', 'en'); $this->object->setUserValue("TEST_COOKIE_USER_VAL", '', 'cfg_val_1'); - $this->assertEquals($this->object->getUserValue("TEST_COOKIE_USER_VAL", 'fail'), 'cfg_val_1'); + $this->assertEquals( + $this->object->getUserValue("TEST_COOKIE_USER_VAL", 'fail'), + 'cfg_val_1' + ); } /** @@ -689,14 +707,39 @@ class PMA_ConfigTest extends PHPUnit_Framework_TestCase */ public function testSetCookie() { - $this->assertFalse($this->object->setCookie('TEST_DEF_COOKIE', 'test_def_123', 'test_def_123')); + $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', + 'test_val_123', + null, + 3600 + ) + ); - $this->assertTrue($this->object->setCookie('TEST_CONFIG_COOKIE', '', 'default_val')); + $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')); + $this->assertTrue( + $this->object->setCookie( + 'TEST_MANUAL_COOKIE', + 'other', + 'other' + ) + ); } From 2a7358c9ab182d0d1a699442cdcd614ff050f0bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Mon, 14 May 2012 16:15:58 +0200 Subject: [PATCH 27/27] Rewrite another test using dataProvider --- test/classes/PMA_Config_test.php | 33 ++++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/test/classes/PMA_Config_test.php b/test/classes/PMA_Config_test.php index aaa78b8b4d..93fcfd7130 100644 --- a/test/classes/PMA_Config_test.php +++ b/test/classes/PMA_Config_test.php @@ -226,19 +226,36 @@ class PMA_ConfigTest extends PHPUnit_Framework_TestCase } } - public function testCheckWebServer() + /** + * Web server detection test + * + * @param string $server Server indentification + * @param boolean $iis Whether server should be detected as IIS + * + * @dataProvider serverNames + */ + public function testCheckWebServer($server, $iis) { - $_SERVER['SERVER_SOFTWARE'] = "Microsoft-IIS 7.0"; + $_SERVER['SERVER_SOFTWARE'] = $server; $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')); - + $this->assertEquals($iis, $this->object->get('PMA_IS_IIS')); unset($_SERVER['SERVER_SOFTWARE']); } + public function serverNames() + { + return array( + array( + "Microsoft-IIS 7.0", + 1, + ), + array( + "Apache/2.2.17", + 0, + ), + ); + } + public function testCheckWebServerOs() { $this->object->checkWebServerOs();