Merge branch 'develop-olympus' into develop

* develop-olympus:
  [task/session-tests] Make result check independent of returned row order.
  [task/session-tests] By default the cache check now skips over db server info
  [task/session-tests] Correctly display message on session continue test failure
  [task/session-tests] Make the session id replacement of dataset values clearer

Conflicts:
	tests/mock/cache.php
This commit is contained in:
Igor Wiedler 2011-02-27 22:52:56 +01:00
commit 5913aef58f
2 changed files with 45 additions and 17 deletions

View file

@ -42,9 +42,16 @@ class phpbb_mock_cache implements phpbb_cache_driver_interface
$test->assertFalse(isset($this->data[$var_name]));
}
public function check(PHPUnit_Framework_Assert $test, $data)
public function check(PHPUnit_Framework_Assert $test, $data, $ignore_db_info = true)
{
$test->assertEquals($data, $this->data);
$cache_data = $this->data;
if ($ignore_db_info)
{
unset($cache_data['mysqli_version']);
}
$test->assertEquals($data, $cache_data);
}
function load()

View file

@ -19,13 +19,12 @@ class phpbb_session_continue_test extends phpbb_database_test_case
static public function session_begin_attempts()
{
global $_SID;
return array(
array(
'bar_session', '4', 'user agent', '127.0.0.1',
array(
array('session_id' => 'anon_session', 'session_user_id' => 1),
array('session_id' => 'bar_session', 'session_user_id' => 4)
array('session_id' => 'bar_session', 'session_user_id' => 4),
),
array(),
'If a request comes with a valid session id with matching user agent and IP, no new session should be created.',
@ -33,13 +32,13 @@ class phpbb_session_continue_test extends phpbb_database_test_case
array(
'anon_session', '4', 'user agent', '127.0.0.1',
array(
array('session_id' => '__new_session_id__', 'session_user_id' => 1), // use generated SID
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),
'sid' => array('__new_session_id__', null),
),
'If a request comes with a valid session id and IP but different user id and user agent, a new anonymous session is created and the session matching the supplied session id is deleted.',
),
@ -71,26 +70,48 @@ class phpbb_session_continue_test extends phpbb_database_test_case
$session->session_begin();
$sql = 'SELECT session_id, session_user_id
FROM phpbb_sessions';
FROM phpbb_sessions
ORDER BY session_user_id';
// 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;
}
}
$expected_sessions = $this->replace_session($expected_sessions, $session->session_id);
$expected_cookies = $this->replace_session($expected_cookies, $session->session_id);
$this->assertSqlResultEquals(
$expected_sessions,
$sql,
'Check if no new session was created'
$message
);
$session->check_cookies($this, $expected_cookies);
$session_factory->check($this);
}
/**
* Replaces recursively the value __new_session_id__ with the given session
* id.
*
* @param array $array An array of data
* @param string $session_id The new session id to use instead of the
* placeholder.
* @return array The input array with all occurances of __new_session_id__
* replaced.
*/
public function replace_session($array, $session_id)
{
foreach ($array as $key => &$value)
{
if ($value === '__new_session_id__')
{
$value = $session_id;
}
if (is_array($value))
{
$value = $this->replace_session($value, $session_id);
}
}
return $array;
}
}