aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--tests/functions/fixtures/obtain_online.xml100
-rw-r--r--tests/functions/obtain_online_test.php86
2 files changed, 185 insertions, 1 deletions
diff --git a/tests/functions/fixtures/obtain_online.xml b/tests/functions/fixtures/obtain_online.xml
index ea4d6f9238..1c5a4454f2 100644
--- a/tests/functions/fixtures/obtain_online.xml
+++ b/tests/functions/fixtures/obtain_online.xml
@@ -8,4 +8,104 @@
<column>session_ip</column>
<column>session_viewonline</column>
</table>
+ <table name="phpbb_users">
+ <column>user_id</column>
+ <column>username_clean</column>
+ <column>username</column>
+ <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>
+ <value>anonymous</value>
+ <value>1</value>
+ <value></value>
+ <value></value>
+ <value></value>
+ <value></value>
+ </row>
+ <row>
+ <value>2</value>
+ <value>2</value>
+ <value>2</value>
+ <value>1</value>
+ <value></value>
+ <value></value>
+ <value></value>
+ <value></value>
+ </row>
+ <row>
+ <value>3</value>
+ <value>3</value>
+ <value>3</value>
+ <value>1</value>
+ <value></value>
+ <value></value>
+ <value></value>
+ <value></value>
+ </row>
+ <row>
+ <value>4</value>
+ <value>4</value>
+ <value>4</value>
+ <value>1</value>
+ <value></value>
+ <value></value>
+ <value></value>
+ <value></value>
+ </row>
+ <row>
+ <value>5</value>
+ <value>5</value>
+ <value>5</value>
+ <value>1</value>
+ <value></value>
+ <value></value>
+ <value></value>
+ <value></value>
+ </row>
+ <row>
+ <value>6</value>
+ <value>6</value>
+ <value>6</value>
+ <value>0</value>
+ <value></value>
+ <value></value>
+ <value></value>
+ <value></value>
+ </row>
+ <row>
+ <value>7</value>
+ <value>7</value>
+ <value>7</value>
+ <value>0</value>
+ <value></value>
+ <value></value>
+ <value></value>
+ <value></value>
+ </row>
+ <row>
+ <value>8</value>
+ <value>8</value>
+ <value>8</value>
+ <value>0</value>
+ <value></value>
+ <value></value>
+ <value></value>
+ <value></value>
+ </row>
+ <row>
+ <value>9</value>
+ <value>9</value>
+ <value>9</value>
+ <value>0</value>
+ <value></value>
+ <value></value>
+ <value></value>
+ <value></value>
+ </row>
+ </table>
</dataset>
diff --git a/tests/functions/obtain_online_test.php b/tests/functions/obtain_online_test.php
index 8fd7e6a977..64f368164c 100644
--- a/tests/functions/obtain_online_test.php
+++ b/tests/functions/obtain_online_test.php
@@ -8,6 +8,8 @@
*/
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
{
@@ -18,6 +20,8 @@ class phpbb_functions_obtain_online_test extends phpbb_database_test_case
protected function setUp()
{
+ parent::setUp();
+
global $config, $db;
$db = $this->db = $this->new_dbal();
@@ -114,6 +118,63 @@ class phpbb_functions_obtain_online_test extends phpbb_database_test_case
$this->assertEquals($expected, obtain_users_online($forum_id));
}
+ static public function obtain_users_online_string_data()
+ {
+ return array(
+ array(0, false, array(
+ 'online_userlist' => 'REGISTERED_USERS 2, 3',
+ 'l_online_users' => 'ONLINE_USERS_TOTAL 4REG_USERS_TOTAL_AND 2HIDDEN_USERS_TOTAL 2',
+ )),
+ array(0, true, array(
+ 'online_userlist' => 'REGISTERED_USERS 2, 3',
+ 'l_online_users' => 'ONLINE_USERS_TOTAL 6REG_USERS_TOTAL 2HIDDEN_USERS_TOTAL_AND 2GUEST_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',
+ )),
+ 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',
+ )),
+ 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',
+ )),
+ 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',
+ )),
+ );
+ }
+
+ /**
+ * @dataProvider obtain_users_online_string_data
+ */
+ public function test_obtain_users_online_string($forum_id, $display_guests, $expected)
+ {
+ $this->db->sql_query('DELETE FROM phpbb_sessions');
+
+ global $config, $user, $auth;
+ $config['load_online_guests'] = $display_guests;
+ $user->lang = $this->load_language();
+ $auth = $this->getMock('auth');
+ $acl_get_map = array(
+ array('u_viewonline', true),
+ );
+ $auth->expects($this->any())
+ ->method('acl_get')
+ ->with($this->stringContains('_'),
+ $this->anything())
+ ->will($this->returnValueMap($acl_get_map));
+
+ $this->create_guest_sessions();
+ $this->create_user_sessions();
+
+ $online_users = obtain_users_online($forum_id);
+ $this->assertEquals($expected, obtain_users_online_string($online_users, $forum_id));
+ }
+
protected function create_guest_sessions()
{
$this->add_session(1, '0001', 0, true, 0);
@@ -144,7 +205,30 @@ class phpbb_functions_obtain_online_test extends phpbb_database_test_case
'session_time' => time() - $time_delta * 60,
'session_viewonline' => $view_online,
);
-
$this->db->sql_query('INSERT INTO phpbb_sessions ' . $this->db->sql_build_array('INSERT', $sql_ary));
}
+
+ protected function load_language()
+ {
+ $lang = 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;
+ }
}