From 3f75534258144dc0cdafd0e56c712b2b620b9e38 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 14 May 2013 15:54:40 +0200 Subject: [PATCH 01/11] [ticket/11540] Add unit tests for is_absolute() PHPBB3-11540 --- tests/functions/is_absolute_test.php | 34 ++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 tests/functions/is_absolute_test.php diff --git a/tests/functions/is_absolute_test.php b/tests/functions/is_absolute_test.php new file mode 100644 index 0000000000..26425d2a36 --- /dev/null +++ b/tests/functions/is_absolute_test.php @@ -0,0 +1,34 @@ +assertEquals($expected, is_absolute($path)); + } +} From 25be16748dc39b2e30bd55472d8e5d6ef60f1c39 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 14 May 2013 15:55:21 +0200 Subject: [PATCH 02/11] [ticket/11541] Add unit tests for style_select() PHPBB3-11541 --- tests/functions/fixtures/style_select.xml | 23 +++++++++++++ tests/functions/style_select_test.php | 41 +++++++++++++++++++++++ 2 files changed, 64 insertions(+) create mode 100644 tests/functions/fixtures/style_select.xml create mode 100644 tests/functions/style_select_test.php diff --git a/tests/functions/fixtures/style_select.xml b/tests/functions/fixtures/style_select.xml new file mode 100644 index 0000000000..12d6392ab5 --- /dev/null +++ b/tests/functions/fixtures/style_select.xml @@ -0,0 +1,23 @@ + + + + style_id + style_name + style_active + + 1 + prosilver + 1 + + + 2 + subsilver2 + 1 + + + 3 + zoo + 0 + +
+
diff --git a/tests/functions/style_select_test.php b/tests/functions/style_select_test.php new file mode 100644 index 0000000000..1e44f3c2cb --- /dev/null +++ b/tests/functions/style_select_test.php @@ -0,0 +1,41 @@ +createXMLDataSet(dirname(__FILE__).'/fixtures/style_select.xml'); + } + + static public function style_select_data() + { + return array( + array('', false, ''), + array('', true, ''), + array('1', false, ''), + array('1', true, ''), + array('3', false, ''), + array('3', true, ''), + ); + } + + /** + * @dataProvider style_select_data + */ + public function test_style_select($default, $all, $expected) + { + global $db; + $db = $this->new_dbal(); + + $this->assertEquals($expected, style_select($default, $all)); + } +} From 6900e8dae08b4a8c1af3529a418f5156b0cfd157 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 14 May 2013 15:55:05 +0200 Subject: [PATCH 03/11] [ticket/11542] Add unit tests for language_select() PHPBB3-11542 --- tests/functions/fixtures/language_select.xml | 18 ++++++++++ tests/functions/language_select_test.php | 38 ++++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 tests/functions/fixtures/language_select.xml create mode 100644 tests/functions/language_select_test.php diff --git a/tests/functions/fixtures/language_select.xml b/tests/functions/fixtures/language_select.xml new file mode 100644 index 0000000000..02fdee093e --- /dev/null +++ b/tests/functions/fixtures/language_select.xml @@ -0,0 +1,18 @@ + + + + lang_id + lang_iso + lang_local_name + + 1 + en + English + + + 2 + de + Deutsch + +
+
diff --git a/tests/functions/language_select_test.php b/tests/functions/language_select_test.php new file mode 100644 index 0000000000..3e7ed45bbf --- /dev/null +++ b/tests/functions/language_select_test.php @@ -0,0 +1,38 @@ +createXMLDataSet(dirname(__FILE__).'/fixtures/language_select.xml'); + } + + static public function language_select_data() + { + return array( + array('', ''), + array('en', ''), + array('de', ''), + ); + } + + /** + * @dataProvider language_select_data + */ + public function test_language_select($default, $expected) + { + global $db; + $db = $this->new_dbal(); + + $this->assertEquals($expected, language_select($default)); + } +} From ac8e8a156a771cabcd73859f1c2235c89257e76b Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Tue, 14 May 2013 22:51:10 +0200 Subject: [PATCH 04/11] [ticket/11544] Add admin_login() method to 3.0 functional test case This method is needed in order to be able to properly test acp functions. PHPBB3-11544 --- .../phpbb_functional_test_case.php | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index 83c931f924..b1352b247e 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -299,6 +299,50 @@ class phpbb_functional_test_case extends phpbb_test_case } } + /** + * Login to the ACP + * You must run login() before calling this. + */ + protected function admin_login($username = 'admin') + { + $this->add_lang('acp/common'); + + // Requires login first! + if (empty($this->sid)) + { + $this->fail('$this->sid is empty. Make sure you call login() before admin_login()'); + return; + } + + $crawler = $this->request('GET', 'adm/index.php?sid=' . $this->sid); + $this->assertContains($this->lang('LOGIN_ADMIN_CONFIRM'), $crawler->filter('html')->text()); + + $form = $crawler->selectButton($this->lang('LOGIN'))->form(); + + foreach ($form->getValues() as $field => $value) + { + if (strpos($field, 'password_') === 0) + { + $crawler = $this->client->submit($form, array('username' => $username, $field => $username)); + $this->assert_response_success(); + $this->assertContains($this->lang('LOGIN_ADMIN_SUCCESS'), $crawler->filter('html')->text()); + + $cookies = $this->cookieJar->all(); + + // The session id is stored in a cookie that ends with _sid - we assume there is only one such cookie + foreach ($cookies as $cookie); + { + if (substr($cookie->getName(), -4) == '_sid') + { + $this->sid = $cookie->getValue(); + } + } + + break; + } + } + } + protected function add_lang($lang_file) { if (is_array($lang_file)) From 06edf15ac3e63350b7973b04f07578de1c4565d0 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 15 May 2013 13:55:35 +0200 Subject: [PATCH 05/11] [ticket/11546] Fix is_absolute() throws E_NOTICE for empty string PHPBB3-11546 --- phpBB/includes/functions.php | 2 +- tests/functions/is_absolute_test.php | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index cf676a3351..4b144a20a1 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -1005,7 +1005,7 @@ if (!function_exists('stripos')) */ function is_absolute($path) { - return ($path[0] == '/' || (DIRECTORY_SEPARATOR == '\\' && preg_match('#^[a-z]:[/\\\]#i', $path))) ? true : false; + return (isset($path[0]) && $path[0] == '/' || (DIRECTORY_SEPARATOR == '\\' && preg_match('#^[a-z]:[/\\\]#i', $path))) ? true : false; } /** diff --git a/tests/functions/is_absolute_test.php b/tests/functions/is_absolute_test.php index 26425d2a36..5d70b6c2a3 100644 --- a/tests/functions/is_absolute_test.php +++ b/tests/functions/is_absolute_test.php @@ -14,6 +14,7 @@ class phpbb_functions_is_absolute_test extends phpbb_test_case static public function is_absolute_data() { return array( + array('', false), array('/etc/phpbb', true), array('etc/phpbb', false), From 63f11a802447c8641bcb9d645000232dc7181da9 Mon Sep 17 00:00:00 2001 From: Victor Nagy Date: Tue, 14 May 2013 23:04:32 +0200 Subject: [PATCH 06/11] [ticket/11536] Fixed incorrect removal of "install" in script_path Earlier the script would incorrectly remove the word "install" from the script_path when trying to remove the last folder in the path named "/install". This would lead to issues when the path you are installing phpBB contained "install". For example "/install_test/install" would become "/_test". This change gets the parent folder instead of replacing all "install". $name contains /install_test/install/index.php from start and running dirname() gives /install_test/install. Running dirname once more gives the parent folder of install, /install_test. PHPBB3-11536 --- phpBB/install/install_install.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/phpBB/install/install_install.php b/phpBB/install/install_install.php index 0575b58d92..4618cff855 100644 --- a/phpBB/install/install_install.php +++ b/phpBB/install/install_install.php @@ -1025,8 +1025,8 @@ class install_install extends module } // Replace backslashes and doubled slashes (could happen on some proxy setups) - $name = str_replace(array('\\', '//', '/install'), '/', $name); - $data['script_path'] = trim(dirname($name)); + $name = str_replace(array('\\', '//'), '/', $name); + $data['script_path'] = trim(dirname(dirname($name))); } foreach ($this->advanced_config_options as $config_key => $vars) From 14ab0ba594c1b78176452c012965fa4ec723f37f Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 15 May 2013 15:18:28 +0200 Subject: [PATCH 07/11] [ticket/11542] Add lang_english_name to fixture PHPBB3-11542 --- tests/functions/fixtures/language_select.xml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/functions/fixtures/language_select.xml b/tests/functions/fixtures/language_select.xml index 02fdee093e..921f2c0a3a 100644 --- a/tests/functions/fixtures/language_select.xml +++ b/tests/functions/fixtures/language_select.xml @@ -4,15 +4,18 @@ lang_id lang_iso lang_local_name + lang_english_name 1 en English + English 2 de Deutsch + German From 38dbfc17a782f72737451103b8e4067f152bd0b7 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 16 May 2013 17:30:23 +0200 Subject: [PATCH 08/11] [ticket/11545] Remove DIRECTORY_SEPARATOR dependency from is_absolute The given path is an absolute path in general, just not on our current system. PHPBB3-11545 --- phpBB/includes/functions.php | 2 +- tests/functions/is_absolute_test.php | 33 +++++++++++++++++++++++----- 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 4b144a20a1..b2b12c1445 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -1005,7 +1005,7 @@ if (!function_exists('stripos')) */ function is_absolute($path) { - return (isset($path[0]) && $path[0] == '/' || (DIRECTORY_SEPARATOR == '\\' && preg_match('#^[a-z]:[/\\\]#i', $path))) ? true : false; + return (isset($path[0]) && $path[0] == '/' || preg_match('#^[a-z]:[/\\\]#i', $path)) ? true : false; } /** diff --git a/tests/functions/is_absolute_test.php b/tests/functions/is_absolute_test.php index 5d70b6c2a3..7630b7c58c 100644 --- a/tests/functions/is_absolute_test.php +++ b/tests/functions/is_absolute_test.php @@ -14,14 +14,35 @@ class phpbb_functions_is_absolute_test extends phpbb_test_case static public function is_absolute_data() { return array( + // Empty array('', false), - array('/etc/phpbb', true), - array('etc/phpbb', false), - // Until we got DIRECTORY_SEPARATOR replaced in that function, - // test results vary on OS. - array('c:\windows', DIRECTORY_SEPARATOR == '\\'), - array('C:\Windows', DIRECTORY_SEPARATOR == '\\'), + // Absolute unix style + array('/etc/phpbb', true), + // Unix does not support \ so that is not an absolute path + array('\etc\phpbb', false), + + // Absolute windows style + array('c:\windows', true), + array('C:\Windows', true), + array('c:/windows', true), + array('C:/Windows', true), + + // Executable + array('etc/phpbb', false), + array('explorer.exe', false), + + // Relative subdir + array('Windows\System32', false), + array('Windows\System32\explorer.exe', false), + array('Windows/System32', false), + array('Windows/System32/explorer.exe', false), + + // Relative updir + array('..\Windows\System32', false), + array('..\Windows\System32\explorer.exe', false), + array('../Windows/System32', false), + array('../Windows/System32/explorer.exe', false), ); } From 92e1e86e5c75879c2b538cbf738de947eadb08d3 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 16 May 2013 00:14:40 +0200 Subject: [PATCH 09/11] [ticket/11542] Add non-existing default value for language select PHPBB3-11542 --- tests/functions/language_select_test.php | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/functions/language_select_test.php b/tests/functions/language_select_test.php index 3e7ed45bbf..3ec2bd4bc3 100644 --- a/tests/functions/language_select_test.php +++ b/tests/functions/language_select_test.php @@ -22,6 +22,7 @@ class phpbb_functions_language_select_test extends phpbb_database_test_case array('', ''), array('en', ''), array('de', ''), + array('cs', ''), ); } From 225aba976e0603c24d4808ad71d6b00e86326400 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Fri, 17 May 2013 01:22:22 +0200 Subject: [PATCH 10/11] [ticket/11547] Set MySQL charset to UTF8 in database_test_connection_manager. PHPBB3-11547 --- .../phpbb_database_test_connection_manager.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/test_framework/phpbb_database_test_connection_manager.php b/tests/test_framework/phpbb_database_test_connection_manager.php index 3b8c2e99ae..af7e6b1144 100644 --- a/tests/test_framework/phpbb_database_test_connection_manager.php +++ b/tests/test_framework/phpbb_database_test_connection_manager.php @@ -142,6 +142,14 @@ class phpbb_database_test_connection_manager } $this->pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); + + switch ($this->config['dbms']) + { + case 'mysql': + case 'mysqli': + $this->pdo->exec('SET NAMES utf8'); + default: + } } /** From 1ee2543309245d627c000bcd1b3d680ae7498123 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 17 May 2013 02:13:51 +0200 Subject: [PATCH 11/11] [ticket/11542] Use Czech as example as it contains non-latin characters PHPBB3-11542 --- tests/functions/fixtures/language_select.xml | 6 +++--- tests/functions/language_select_test.php | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/tests/functions/fixtures/language_select.xml b/tests/functions/fixtures/language_select.xml index 921f2c0a3a..d7232a3d28 100644 --- a/tests/functions/fixtures/language_select.xml +++ b/tests/functions/fixtures/language_select.xml @@ -13,9 +13,9 @@ 2 - de - Deutsch - German + cs + Čeština + Czech diff --git a/tests/functions/language_select_test.php b/tests/functions/language_select_test.php index 3ec2bd4bc3..3341e2a256 100644 --- a/tests/functions/language_select_test.php +++ b/tests/functions/language_select_test.php @@ -19,10 +19,10 @@ class phpbb_functions_language_select_test extends phpbb_database_test_case static public function language_select_data() { return array( - array('', ''), - array('en', ''), - array('de', ''), - array('cs', ''), + array('', ''), + array('en', ''), + array('cs', ''), + array('de', ''), ); }