From 3d65c3c10484bc524160ebb4f4a483ba6c0dd8ed Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Sun, 27 Feb 2011 22:06:01 +0100 Subject: [task/session-tests] Make the session id replacement of dataset values clearer PHPBB3-9732 --- tests/session/continue_test.php | 44 ++++++++++++++++++++++++++++++----------- 1 file changed, 32 insertions(+), 12 deletions(-) (limited to 'tests') diff --git a/tests/session/continue_test.php b/tests/session/continue_test.php index 06b03f5780..4e5df300f2 100644 --- a/tests/session/continue_test.php +++ b/tests/session/continue_test.php @@ -19,7 +19,6 @@ 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', @@ -34,12 +33,12 @@ class phpbb_session_continue_test extends phpbb_database_test_case 'anon_session', '4', 'user agent', '127.0.0.1', array( array('session_id' => 'bar_session', 'session_user_id' => 4), - array('session_id' => null, 'session_user_id' => 1) // use generated SID + array('session_id' => '__new_session_id__', '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.', ), @@ -73,14 +72,8 @@ 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; - } - } + $expected_sessions = $this->replace_session($expected_sessions, $session->session_id); + $expected_cookies = $this->replace_session($expected_cookies, $session->session_id); $this->assertSqlResultEquals( $expected_sessions, @@ -92,5 +85,32 @@ class phpbb_session_continue_test extends phpbb_database_test_case $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; + } +} -- cgit v1.2.1 From bbf3864cb4cd3762a64b9489cfd38b7ac93df423 Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Sun, 27 Feb 2011 22:16:39 +0100 Subject: [task/session-tests] Correctly display message on session continue test failure PHPBB3-9732 --- tests/session/continue_test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/session/continue_test.php b/tests/session/continue_test.php index 4e5df300f2..27ac457c2d 100644 --- a/tests/session/continue_test.php +++ b/tests/session/continue_test.php @@ -78,7 +78,7 @@ class phpbb_session_continue_test extends phpbb_database_test_case $this->assertSqlResultEquals( $expected_sessions, $sql, - 'Check if no new session was created' + $message ); $session->check_cookies($this, $expected_cookies); -- cgit v1.2.1 From 7255ef4f6d9ea8c63036ad32fa376cd03b1b8e9b Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Sun, 27 Feb 2011 22:17:03 +0100 Subject: [task/session-tests] By default the cache check now skips over db server info PHPBB3-9732 --- tests/mock/cache.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/mock/cache.php b/tests/mock/cache.php index 2ac46f7090..738d1eaaba 100644 --- a/tests/mock/cache.php +++ b/tests/mock/cache.php @@ -53,9 +53,16 @@ class phpbb_mock_cache $test->assertEquals($data, $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); } } -- cgit v1.2.1 From 921603b09e1e34059f783c502d5dfc9ae0189057 Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Sun, 27 Feb 2011 22:20:36 +0100 Subject: [task/session-tests] Make result check independent of returned row order. PHPBB3-9732 --- tests/session/continue_test.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'tests') diff --git a/tests/session/continue_test.php b/tests/session/continue_test.php index 27ac457c2d..3080121978 100644 --- a/tests/session/continue_test.php +++ b/tests/session/continue_test.php @@ -24,7 +24,7 @@ class phpbb_session_continue_test extends phpbb_database_test_case '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.', @@ -32,8 +32,8 @@ 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' => '__new_session_id__', 'session_user_id' => 1) // use generated SID ), array( 'u' => array('1', null), @@ -70,7 +70,8 @@ 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'; $expected_sessions = $this->replace_session($expected_sessions, $session->session_id); $expected_cookies = $this->replace_session($expected_cookies, $session->session_id); -- cgit v1.2.1