aboutsummaryrefslogtreecommitdiffstats
path: root/tests/functions
diff options
context:
space:
mode:
Diffstat (limited to 'tests/functions')
-rw-r--r--tests/functions/build_hidden_fields_for_query_params_test.php71
-rw-r--r--tests/functions/clean_path_test.php44
-rw-r--r--tests/functions/convert_30_dbms_to_31_test.php40
-rw-r--r--tests/functions/fixtures/obtain_online.xml22
-rw-r--r--tests/functions/fixtures/style_select.xml4
-rw-r--r--tests/functions/fixtures/validate_email.xml4
-rw-r--r--tests/functions/fixtures/validate_username.xml6
-rw-r--r--tests/functions/is_absolute_test.php2
-rw-r--r--tests/functions/obtain_online_test.php39
-rw-r--r--tests/functions/quoteattr_test.php44
-rw-r--r--tests/functions/validate_password_test.php1
11 files changed, 175 insertions, 102 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=\"&lt;less&gt;\" />",
+ ),
+ array(
+ array('a' => "quotes'\""),
+ array(),
+ array(),
+ "<input type='hidden' name=\"a\" value=\"quotes'&quot;\" />",
+ ),
+ 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/obtain_online.xml b/tests/functions/fixtures/obtain_online.xml
index 05bbe6a05e..14621a3287 100644
--- a/tests/functions/fixtures/obtain_online.xml
+++ b/tests/functions/fixtures/obtain_online.xml
@@ -15,8 +15,6 @@
<column>user_allow_viewonline</column>
<column>user_permissions</column>
<column>user_sig</column>
- <column>user_occ</column>
- <column>user_interests</column>
<row>
<value>1</value>
<value>anonymous</value>
@@ -24,8 +22,6 @@
<value>1</value>
<value></value>
<value></value>
- <value></value>
- <value></value>
</row>
<row>
<value>2</value>
@@ -34,8 +30,6 @@
<value>1</value>
<value></value>
<value></value>
- <value></value>
- <value></value>
</row>
<row>
<value>3</value>
@@ -44,8 +38,6 @@
<value>1</value>
<value></value>
<value></value>
- <value></value>
- <value></value>
</row>
<row>
<value>4</value>
@@ -54,8 +46,6 @@
<value>1</value>
<value></value>
<value></value>
- <value></value>
- <value></value>
</row>
<row>
<value>5</value>
@@ -64,8 +54,6 @@
<value>1</value>
<value></value>
<value></value>
- <value></value>
- <value></value>
</row>
<row>
<value>6</value>
@@ -74,8 +62,6 @@
<value>0</value>
<value></value>
<value></value>
- <value></value>
- <value></value>
</row>
<row>
<value>7</value>
@@ -84,8 +70,6 @@
<value>0</value>
<value></value>
<value></value>
- <value></value>
- <value></value>
</row>
<row>
<value>8</value>
@@ -94,8 +78,6 @@
<value>0</value>
<value></value>
<value></value>
- <value></value>
- <value></value>
</row>
<row>
<value>9</value>
@@ -104,8 +86,6 @@
<value>0</value>
<value></value>
<value></value>
- <value></value>
- <value></value>
</row>
<row>
<value>10</value>
@@ -114,8 +94,6 @@
<value>0</value>
<value></value>
<value></value>
- <value></value>
- <value></value>
</row>
</table>
</dataset>
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/fixtures/validate_email.xml b/tests/functions/fixtures/validate_email.xml
index de7fce8a08..eb4fd90217 100644
--- a/tests/functions/fixtures/validate_email.xml
+++ b/tests/functions/fixtures/validate_email.xml
@@ -6,8 +6,6 @@
<column>username_clean</column>
<column>user_permissions</column>
<column>user_sig</column>
- <column>user_occ</column>
- <column>user_interests</column>
<column>user_email_hash</column>
<row>
<value>1</value>
@@ -15,8 +13,6 @@
<value>admin</value>
<value></value>
<value></value>
- <value></value>
- <value></value>
<value>143317126117</value>
</row>
</table>
diff --git a/tests/functions/fixtures/validate_username.xml b/tests/functions/fixtures/validate_username.xml
index fbe398469c..1b85a2f06d 100644
--- a/tests/functions/fixtures/validate_username.xml
+++ b/tests/functions/fixtures/validate_username.xml
@@ -14,16 +14,12 @@
<column>username_clean</column>
<column>user_permissions</column>
<column>user_sig</column>
- <column>user_occ</column>
- <column>user_interests</column>
<row>
<value>1</value>
<value>admin</value>
<value>admin</value>
<value></value>
<value></value>
- <value></value>
- <value></value>
</row>
<row>
<value>2</value>
@@ -31,8 +27,6 @@
<value>moderator</value>
<value></value>
<value></value>
- <value></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 de6451a0db..cf42fd5b58 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
{
@@ -126,27 +125,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',
)),
);
}
@@ -158,18 +157,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);
@@ -215,25 +217,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, '"&lt;a&gt;"'),
+ array('&amp;', null, '"&amp;amp;"'),
+ array('"hello"', null, "'\"hello\"'"),
+ array("'hello'", null, "\"'hello'\""),
+ array("\"'", null, "\"&quot;'\""),
+ array("a\nb", null, '"a&#10;b"'),
+ array("a\r\nb", null, '"a&#13;&#10;b"'),
+ array("a\tb", null, '"a&#9;b"'),
+ array('a b', null, '"a b"'),
+ array('"a<b"', null, "'\"a&lt;b\"'"),
+ array('foo', array('f' => 'z'), '"zoo"'),
+ array('<a>', array('a' => '&amp;'), '"&lt;&amp;&gt;"'),
+ );
+ }
+
+ /**
+ * @dataProvider quoteattr_test_data
+ */
+ public function test_quoteattr($input, $entities, $expected)
+ {
+ $output = phpbb_quoteattr($input, $entities);
+
+ $this->assertEquals($expected, $output);
+ }
+}
diff --git a/tests/functions/validate_password_test.php b/tests/functions/validate_password_test.php
index 4639f6cc89..82c5fa03c1 100644
--- a/tests/functions/validate_password_test.php
+++ b/tests/functions/validate_password_test.php
@@ -7,6 +7,7 @@
*
*/
+require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php';
require_once dirname(__FILE__) . '/../../phpBB/includes/functions_user.php';
require_once dirname(__FILE__) . '/validate_data_helper.php';