mirror of
https://github.com/phpbb/phpbb.git
synced 2025-04-27 19:14:20 +02:00
[ticket/11543] Add unit tests for obtain_guest_count()
PHPBB3-11543
This commit is contained in:
parent
96b4066368
commit
057bbfa240
11
tests/functions/fixtures/obtain_online.xml
Normal file
11
tests/functions/fixtures/obtain_online.xml
Normal file
@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<dataset>
|
||||
<table name="phpbb_sessions">
|
||||
<column>session_id</column>
|
||||
<column>session_user_id</column>
|
||||
<column>session_forum_id</column>
|
||||
<column>session_time</column>
|
||||
<column>session_ip</column>
|
||||
<column>session_viewonline</column>
|
||||
</table>
|
||||
</dataset>
|
69
tests/functions/obtain_online_test.php
Normal file
69
tests/functions/obtain_online_test.php
Normal file
@ -0,0 +1,69 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @package testing
|
||||
* @copyright (c) 2013 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_functions_obtain_online_test extends phpbb_database_test_case
|
||||
{
|
||||
public function getDataSet()
|
||||
{
|
||||
return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/obtain_online.xml');
|
||||
}
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
global $config, $db;
|
||||
|
||||
$db = $this->db = $this->new_dbal();
|
||||
$config = array(
|
||||
'load_online_time' => 5,
|
||||
);
|
||||
}
|
||||
|
||||
static public function obtain_guest_count_data()
|
||||
{
|
||||
return array(
|
||||
array(0, 2),
|
||||
array(1, 1),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider obtain_guest_count_data
|
||||
*/
|
||||
public function test_obtain_guest_count($forum_id, $expected)
|
||||
{
|
||||
$this->db->sql_query('DELETE FROM phpbb_sessions');
|
||||
|
||||
$this->create_guest_sessions();
|
||||
$this->assertEquals($expected, obtain_guest_count($forum_id));
|
||||
}
|
||||
|
||||
protected function create_guest_sessions()
|
||||
{
|
||||
$this->add_session(1, '0001', 0, true, 0);
|
||||
$this->add_session(1, '0002', 1, true, 0);
|
||||
$this->add_session(1, '0003', 0, true, 10);
|
||||
$this->add_session(1, '0004', 1, true, 10);
|
||||
}
|
||||
|
||||
protected function add_session($user_id, $user_ip, $forum_id, $view_online, $time_delta)
|
||||
{
|
||||
$sql_ary = array(
|
||||
'session_id' => $user_id . '_' . $forum_id . '_session00000000000000000' . $user_ip,
|
||||
'session_user_id' => $user_id,
|
||||
'session_ip' => $user_ip,
|
||||
'session_forum_id' => $forum_id,
|
||||
'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));
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user