mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-27 21:58:52 +00:00
[task/session-tests] Test additional combinations of session_begin.
PHPBB3-9732
This commit is contained in:
parent
74f537e89d
commit
8538561b31
1 changed files with 46 additions and 12 deletions
|
@ -18,7 +18,38 @@ class phpbb_session_continue_test extends phpbb_database_test_case
|
|||
return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/sessions_full.xml');
|
||||
}
|
||||
|
||||
public function test_session_begin_valid_session()
|
||||
static public function session_begin_attempts()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
'bar_session', '4', 'user agent',
|
||||
array(
|
||||
array('session_id' => 'anon_session', 'session_user_id' => 1),
|
||||
array('session_id' => 'bar_session', 'session_user_id' => 4)
|
||||
),
|
||||
array(),
|
||||
'Check if no new session was created',
|
||||
),
|
||||
array(
|
||||
'anon_session', '4', 'user agent',
|
||||
array(
|
||||
array('session_id' => 'bar_session', 'session_user_id' => 4),
|
||||
array('session_id' => null, 'session_user_id' => 1) // use generated SID
|
||||
),
|
||||
array(
|
||||
'u' => array('1', null),
|
||||
'k' => array(null, null),
|
||||
'sid' => array($_SID, null),
|
||||
),
|
||||
'Check if an anonymous new session was created',
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider session_begin_attempts
|
||||
*/
|
||||
public function test_session_begin_valid_session($session_id, $user_id, $user_agent, $expected_sessions, $expected_cookies, $message)
|
||||
{
|
||||
$session = new phpbb_mock_session_testable;
|
||||
$session->page = array('page' => 'page', 'forum' => 0);
|
||||
|
@ -34,9 +65,9 @@ class phpbb_session_continue_test extends phpbb_database_test_case
|
|||
$cache = new phpbb_mock_cache;
|
||||
$SID = $_SID = null;
|
||||
|
||||
$_COOKIE['_sid'] = 'bar_session';
|
||||
$_COOKIE['_u'] = '4';
|
||||
$_SERVER['HTTP_USER_AGENT'] = 'user agent';
|
||||
$_COOKIE['_sid'] = $session_id;
|
||||
$_COOKIE['_u'] = $user_id;
|
||||
$_SERVER['HTTP_USER_AGENT'] = $user_agent;
|
||||
|
||||
$config['session_length'] = time(); // need to do this to allow sessions started at time 0
|
||||
$session->session_begin();
|
||||
|
@ -44,22 +75,25 @@ class phpbb_session_continue_test extends phpbb_database_test_case
|
|||
$sql = 'SELECT session_id, session_user_id
|
||||
FROM phpbb_sessions';
|
||||
|
||||
// little tickery to allow using a dataProvider with dynamic expected result
|
||||
foreach ($expected_sessions as $i => $s)
|
||||
{
|
||||
if (is_null($s['session_id']))
|
||||
{
|
||||
$expected_sessions[$i]['session_id'] = $session->session_id;
|
||||
}
|
||||
}
|
||||
|
||||
$this->assertResultEquals(
|
||||
$sql,
|
||||
array(
|
||||
array('session_id' => 'anon_session', 'session_user_id' => 1),
|
||||
array('session_id' => 'bar_session', 'session_user_id' => 4)
|
||||
),
|
||||
$expected_sessions,
|
||||
'Check if no new session was created'
|
||||
);
|
||||
|
||||
$cookie_expire = $session->time_now + (($config['max_autologin_time']) ? 86400 * (int) $config['max_autologin_time'] : 31536000);
|
||||
|
||||
$session->check_cookies($this, array());
|
||||
$session->check_cookies($this, $expected_cookies);
|
||||
|
||||
$cache->check($this, $cache_data);
|
||||
}
|
||||
|
||||
static public function get_config()
|
||||
{
|
||||
return array(
|
||||
|
|
Loading…
Add table
Reference in a new issue