diff options
Diffstat (limited to 'tests/functions')
-rw-r--r-- | tests/functions/build_hidden_fields_for_query_params_test.php | 71 | ||||
-rw-r--r-- | tests/functions/clean_path_test.php | 44 | ||||
-rw-r--r-- | tests/functions/convert_30_dbms_to_31_test.php | 40 | ||||
-rw-r--r-- | tests/functions/fixtures/style_select.xml | 4 | ||||
-rw-r--r-- | tests/functions/is_absolute_test.php | 2 | ||||
-rw-r--r-- | tests/functions/obtain_online_test.php | 39 | ||||
-rw-r--r-- | tests/functions/quoteattr_test.php | 44 |
7 files changed, 174 insertions, 70 deletions
diff --git a/tests/functions/build_hidden_fields_for_query_params_test.php b/tests/functions/build_hidden_fields_for_query_params_test.php new file mode 100644 index 0000000000..ef2f5744d3 --- /dev/null +++ b/tests/functions/build_hidden_fields_for_query_params_test.php @@ -0,0 +1,71 @@ +<?php +/** +* +* @package testing +* @copyright (c) 2012 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php'; + +class phpbb_build_hidden_fields_for_query_params_test extends phpbb_test_case +{ + public function build_hidden_fields_for_query_params_test_data() + { + return array( + // get + // post + // exclude + // expected + array( + array('foo' => 'bar'), + array(), + array(), + "<input type='hidden' name=\"foo\" value=\"bar\" />", + ), + array( + array('foo' => 'bar', 'a' => 'b'), + array(), + array(), + "<input type='hidden' name=\"foo\" value=\"bar\" /><input type='hidden' name=\"a\" value=\"b\" />", + ), + array( + array('a' => 'quote"', 'b' => '<less>'), + array(), + array(), + "<input type='hidden' name=\"a\" value='quote\"' /><input type='hidden' name=\"b\" value=\"<less>\" />", + ), + array( + array('a' => "quotes'\""), + array(), + array(), + "<input type='hidden' name=\"a\" value=\"quotes'"\" />", + ), + array( + array('foo' => 'bar', 'a' => 'b'), + array('a' => 'c'), + array(), + "<input type='hidden' name=\"foo\" value=\"bar\" />", + ), + // strict equality check + array( + array('foo' => 'bar', 'a' => '0'), + array('a' => ''), + array(), + "<input type='hidden' name=\"foo\" value=\"bar\" />", + ), + ); + } + + /** + * @dataProvider build_hidden_fields_for_query_params_test_data + */ + public function test_build_hidden_fields_for_query_params($get, $post, $exclude, $expected) + { + $request = new phpbb_mock_request($get, $post); + $result = phpbb_build_hidden_fields_for_query_params($request, $exclude); + + $this->assertEquals($expected, $result); + } +} diff --git a/tests/functions/clean_path_test.php b/tests/functions/clean_path_test.php deleted file mode 100644 index bcbe9838d9..0000000000 --- a/tests/functions/clean_path_test.php +++ /dev/null @@ -1,44 +0,0 @@ -<?php -/** -* -* @package testing -* @copyright (c) 2012 phpBB Group -* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 -* -*/ - -require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php'; - -class phpbb_clean_path_test extends phpbb_test_case -{ - public function clean_path_test_data() - { - return array( - array('foo', 'foo'), - array('foo/bar', 'foo/bar'), - array('foo/bar/', 'foo/bar/'), - array('foo/./bar', 'foo/bar'), - array('foo/./././bar', 'foo/bar'), - array('foo/bar/.', 'foo/bar'), - array('./foo/bar', './foo/bar'), - array('../foo/bar', '../foo/bar'), - array('one/two/three', 'one/two/three'), - array('one/two/../three', 'one/three'), - array('one/../two/three', 'two/three'), - array('one/two/..', 'one'), - array('one/two/../', 'one/'), - array('one/two/../three/../four', 'one/four'), - array('one/two/three/../../four', 'one/four'), - ); - } - - /** - * @dataProvider clean_path_test_data - */ - public function test_clean_path($input, $expected) - { - $output = phpbb_clean_path($input); - - $this->assertEquals($expected, $output); - } -} diff --git a/tests/functions/convert_30_dbms_to_31_test.php b/tests/functions/convert_30_dbms_to_31_test.php new file mode 100644 index 0000000000..4d210d7b29 --- /dev/null +++ b/tests/functions/convert_30_dbms_to_31_test.php @@ -0,0 +1,40 @@ +<?php +/** +* +* @package testing +* @copyright (c) 2012 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php'; + +class phpbb_convert_30_dbms_to_31_test extends phpbb_test_case +{ + public function convert_30_dbms_to_31_data() + { + return array( + array('firebird'), + array('mssql'), + array('mssql_odbc'), + array('mssqlnative'), + array('mysql'), + array('mysqli'), + array('oracle'), + array('postgres'), + array('sqlite'), + ); + } + + /** + * @dataProvider convert_30_dbms_to_31_data + */ + public function test_convert_30_dbms_to_31($input) + { + $expected = "phpbb\\db\\driver\\$input"; + + $output = phpbb_convert_30_dbms_to_31($input); + + $this->assertEquals($expected, $output); + } +} diff --git a/tests/functions/fixtures/style_select.xml b/tests/functions/fixtures/style_select.xml index 12d6392ab5..ca95f94461 100644 --- a/tests/functions/fixtures/style_select.xml +++ b/tests/functions/fixtures/style_select.xml @@ -4,20 +4,24 @@ <column>style_id</column> <column>style_name</column> <column>style_active</column> + <column>style_parent_tree</column> <row> <value>1</value> <value>prosilver</value> <value>1</value> + <value></value> </row> <row> <value>2</value> <value>subsilver2</value> <value>1</value> + <value></value> </row> <row> <value>3</value> <value>zoo</value> <value>0</value> + <value></value> </row> </table> </dataset> diff --git a/tests/functions/is_absolute_test.php b/tests/functions/is_absolute_test.php index 7630b7c58c..6d26793d82 100644 --- a/tests/functions/is_absolute_test.php +++ b/tests/functions/is_absolute_test.php @@ -51,6 +51,6 @@ class phpbb_functions_is_absolute_test extends phpbb_test_case */ public function test_is_absolute($path, $expected) { - $this->assertEquals($expected, is_absolute($path)); + $this->assertEquals($expected, phpbb_is_absolute($path)); } } diff --git a/tests/functions/obtain_online_test.php b/tests/functions/obtain_online_test.php index b3beb55a96..624e05f77f 100644 --- a/tests/functions/obtain_online_test.php +++ b/tests/functions/obtain_online_test.php @@ -9,7 +9,6 @@ require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php'; require_once dirname(__FILE__) . '/../../phpBB/includes/functions_content.php'; -require_once dirname(__FILE__) . '/../../phpBB/includes/auth.php'; class phpbb_functions_obtain_online_test extends phpbb_database_test_case { @@ -125,27 +124,27 @@ class phpbb_functions_obtain_online_test extends phpbb_database_test_case return array( array(0, false, array( 'online_userlist' => 'REGISTERED_USERS 2, 3', - 'l_online_users' => 'ONLINE_USERS_TOTAL 5REG_USERS_TOTAL_AND 2HIDDEN_USERS_TOTAL 3', + 'l_online_users' => 'ONLINE_USERS_TOTAL 5 REG_USERS_TOTAL 2 HIDDEN_USERS_TOTAL 3', )), array(0, true, array( 'online_userlist' => 'REGISTERED_USERS 2, 3', - 'l_online_users' => 'ONLINE_USERS_TOTAL 7REG_USERS_TOTAL 2HIDDEN_USERS_TOTAL_AND 3GUEST_USERS_TOTAL 2', + 'l_online_users' => 'ONLINE_USERS_TOTAL_GUESTS 7 REG_USERS_TOTAL 2 HIDDEN_USERS_TOTAL 3 GUEST_USERS_TOTAL 2', )), array(1, false, array( 'online_userlist' => 'BROWSING_FORUM 3', - 'l_online_users' => 'ONLINE_USERS_TOTAL 2REG_USER_TOTAL_AND 1HIDDEN_USER_TOTAL 1', + 'l_online_users' => 'ONLINE_USERS_TOTAL 2 REG_USERS_TOTAL 1 HIDDEN_USERS_TOTAL 1', )), array(1, true, array( - 'online_userlist' => 'BROWSING_FORUM_GUEST 3 1', - 'l_online_users' => 'ONLINE_USERS_TOTAL 3REG_USER_TOTAL 1HIDDEN_USER_TOTAL_AND 1GUEST_USER_TOTAL 1', + 'online_userlist' => 'BROWSING_FORUM_GUESTS 1 3', + 'l_online_users' => 'ONLINE_USERS_TOTAL_GUESTS 3 REG_USERS_TOTAL 1 HIDDEN_USERS_TOTAL 1 GUEST_USERS_TOTAL 1', )), array(2, false, array( 'online_userlist' => 'BROWSING_FORUM NO_ONLINE_USERS', - 'l_online_users' => 'ONLINE_USERS_ZERO_TOTAL 0REG_USERS_ZERO_TOTAL_AND 0HIDDEN_USERS_ZERO_TOTAL 0', + 'l_online_users' => 'ONLINE_USERS_TOTAL 0 REG_USERS_TOTAL 0 HIDDEN_USERS_TOTAL 0', )), array(2, true, array( - 'online_userlist' => 'BROWSING_FORUM_GUESTS NO_ONLINE_USERS 0', - 'l_online_users' => 'ONLINE_USERS_ZERO_TOTAL 0REG_USERS_ZERO_TOTAL 0HIDDEN_USERS_ZERO_TOTAL_AND 0GUEST_USERS_ZERO_TOTAL 0', + 'online_userlist' => 'BROWSING_FORUM_GUESTS 0 NO_ONLINE_USERS', + 'l_online_users' => 'ONLINE_USERS_TOTAL_GUESTS 0 REG_USERS_TOTAL 0 HIDDEN_USERS_TOTAL 0 GUEST_USERS_TOTAL 0', )), ); } @@ -157,18 +156,21 @@ class phpbb_functions_obtain_online_test extends phpbb_database_test_case { $this->db->sql_query('DELETE FROM phpbb_sessions'); - global $config, $user, $auth; + global $config, $user, $auth, $phpbb_dispatcher; $config['load_online_guests'] = $display_guests; + $user = new phpbb_mock_lang(); $user->lang = $this->load_language(); - $auth = $this->getMock('auth'); + $auth = $this->getMock('\phpbb\auth\auth'); $acl_get_map = array( array('u_viewonline', true), + array('u_viewprofile', true), ); $auth->expects($this->any()) ->method('acl_get') ->with($this->stringContains('_'), $this->anything()) ->will($this->returnValueMap($acl_get_map)); + $phpbb_dispatcher = new phpbb_mock_event_dispatcher(); $time = time(); $this->create_guest_sessions($time); @@ -214,25 +216,12 @@ class phpbb_functions_obtain_online_test extends phpbb_database_test_case protected function load_language() { - $lang = array( + return array( 'NO_ONLINE_USERS' => 'NO_ONLINE_USERS', 'REGISTERED_USERS' => 'REGISTERED_USERS', 'BROWSING_FORUM' => 'BROWSING_FORUM %s', 'BROWSING_FORUM_GUEST' => 'BROWSING_FORUM_GUEST %s %d', 'BROWSING_FORUM_GUESTS' => 'BROWSING_FORUM_GUESTS %s %d', ); - $vars_online = array('ONLINE', 'REG', 'HIDDEN', 'GUEST'); - foreach ($vars_online as $online) - { - $lang = array_merge($lang, array( - $online . '_USERS_ZERO_TOTAL' => $online . '_USERS_ZERO_TOTAL %d', - $online . '_USER_TOTAL' => $online . '_USER_TOTAL %d', - $online . '_USERS_TOTAL' => $online . '_USERS_TOTAL %d', - $online . '_USERS_ZERO_TOTAL_AND' => $online . '_USERS_ZERO_TOTAL_AND %d', - $online . '_USER_TOTAL_AND' => $online . '_USER_TOTAL_AND %d', - $online . '_USERS_TOTAL_AND' => $online . '_USERS_TOTAL_AND %d', - )); - } - return $lang; } } diff --git a/tests/functions/quoteattr_test.php b/tests/functions/quoteattr_test.php new file mode 100644 index 0000000000..9d2a7d470e --- /dev/null +++ b/tests/functions/quoteattr_test.php @@ -0,0 +1,44 @@ +<?php +/** +* +* @package testing +* @copyright (c) 2012 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php'; + +class phpbb_quoteattr_test extends phpbb_test_case +{ + public function quoteattr_test_data() + { + return array( + array('foo', null, '"foo"'), + array('', null, '""'), + array(' ', null, '" "'), + array('<a>', null, '"<a>"'), + array('&', null, '"&amp;"'), + array('"hello"', null, "'\"hello\"'"), + array("'hello'", null, "\"'hello'\""), + array("\"'", null, "\""'\""), + array("a\nb", null, '"a b"'), + array("a\r\nb", null, '"a b"'), + array("a\tb", null, '"a	b"'), + array('a b', null, '"a b"'), + array('"a<b"', null, "'\"a<b\"'"), + array('foo', array('f' => 'z'), '"zoo"'), + array('<a>', array('a' => '&'), '"<&>"'), + ); + } + + /** + * @dataProvider quoteattr_test_data + */ + public function test_quoteattr($input, $entities, $expected) + { + $output = phpbb_quoteattr($input, $entities); + + $this->assertEquals($expected, $output); + } +} |