From 1abf7ad80932cdb2651dbefff51406c9d234f3bd Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Sat, 19 Feb 2011 20:30:46 -0500 Subject: [ticket/10049] Renamed session test files to proper file names. phpunit.xml.dist specifies that only files ending in _test.php are test files; with the old names session tests were not run as a result. PHPBB3-10049 --- tests/session/continue_test.php | 117 +++++++++++++++++++++++++++++++++++++ tests/session/init_test.php | 76 ++++++++++++++++++++++++ tests/session/session_continue.php | 117 ------------------------------------- tests/session/session_init.php | 76 ------------------------ 4 files changed, 193 insertions(+), 193 deletions(-) create mode 100644 tests/session/continue_test.php create mode 100644 tests/session/init_test.php delete mode 100644 tests/session/session_continue.php delete mode 100644 tests/session/session_init.php (limited to 'tests') diff --git a/tests/session/continue_test.php b/tests/session/continue_test.php new file mode 100644 index 0000000000..58956c18a9 --- /dev/null +++ b/tests/session/continue_test.php @@ -0,0 +1,117 @@ +createXMLDataSet(dirname(__FILE__).'/fixtures/sessions_full.xml'); + } + + 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); + + // set up all the global variables used in session_create + global $SID, $_SID, $db, $config, $cache; + + $config = $this->get_config(); + $db = $this->new_dbal(); + $cache_data = array( + '_bots' => array(), + ); + $cache = new phpbb_mock_cache; + $SID = $_SID = null; + + $_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(); + + $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, + $expected_sessions, + 'Check if no new session was created' + ); + + $session->check_cookies($this, $expected_cookies); + + $cache->check($this, $cache_data); + } + static public function get_config() + { + return array( + 'allow_autologin' => false, + 'auth_method' => 'db', + 'forwarded_for_check' => true, + 'active_sessions' => 0, // disable + 'rand_seed' => 'foo', + 'rand_seed_last_update' => 0, + 'max_autologin_time' => 0, + 'session_length' => 100, + 'form_token_lifetime' => 100, + 'cookie_name' => '', + 'limit_load' => 0, + 'limit_search_load' => 0, + 'ip_check' => 3, + 'browser_check' => 1, + ); + } +} + diff --git a/tests/session/init_test.php b/tests/session/init_test.php new file mode 100644 index 0000000000..f6fa564880 --- /dev/null +++ b/tests/session/init_test.php @@ -0,0 +1,76 @@ +createXMLDataSet(dirname(__FILE__).'/fixtures/sessions_empty.xml'); + } + + // also see security/extract_current_page.php + + public function test_login_session_create() + { + $session = new phpbb_mock_session_testable; + $session->page = array('page' => 'page', 'forum' => 0); + + // set up all the global variables used in session_create + global $SID, $_SID, $db, $config, $cache; + + $config = $this->get_config(); + $db = $this->new_dbal(); + $cache_data = array( + '_bots' => array(), + ); + $cache = new phpbb_mock_cache; + $SID = $_SID = null; + + $session->session_create(3); + + $sql = 'SELECT session_user_id + FROM phpbb_sessions'; + + $this->assertResultEquals( + $sql, + array(array('session_user_id' => 3)), + 'Check if exacly one session for user id 3 was created' + ); + + $cookie_expire = $session->time_now + (($config['max_autologin_time']) ? 86400 * (int) $config['max_autologin_time'] : 31536000); + + $session->check_cookies($this, array( + 'u' => array(null, $cookie_expire), + 'k' => array(null, $cookie_expire), + 'sid' => array($_SID, $cookie_expire), + )); + + $cache->check($this, $cache_data); + } + + static public function get_config() + { + return array( + 'allow_autologin' => false, + 'auth_method' => 'db', + 'forwarded_for_check' => true, + 'active_sessions' => 0, // disable + 'rand_seed' => 'foo', + 'rand_seed_last_update' => 0, + 'max_autologin_time' => 0, + 'session_length' => 100, + 'form_token_lifetime' => 100, + ); + } +} + diff --git a/tests/session/session_continue.php b/tests/session/session_continue.php deleted file mode 100644 index 58956c18a9..0000000000 --- a/tests/session/session_continue.php +++ /dev/null @@ -1,117 +0,0 @@ -createXMLDataSet(dirname(__FILE__).'/fixtures/sessions_full.xml'); - } - - 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); - - // set up all the global variables used in session_create - global $SID, $_SID, $db, $config, $cache; - - $config = $this->get_config(); - $db = $this->new_dbal(); - $cache_data = array( - '_bots' => array(), - ); - $cache = new phpbb_mock_cache; - $SID = $_SID = null; - - $_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(); - - $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, - $expected_sessions, - 'Check if no new session was created' - ); - - $session->check_cookies($this, $expected_cookies); - - $cache->check($this, $cache_data); - } - static public function get_config() - { - return array( - 'allow_autologin' => false, - 'auth_method' => 'db', - 'forwarded_for_check' => true, - 'active_sessions' => 0, // disable - 'rand_seed' => 'foo', - 'rand_seed_last_update' => 0, - 'max_autologin_time' => 0, - 'session_length' => 100, - 'form_token_lifetime' => 100, - 'cookie_name' => '', - 'limit_load' => 0, - 'limit_search_load' => 0, - 'ip_check' => 3, - 'browser_check' => 1, - ); - } -} - diff --git a/tests/session/session_init.php b/tests/session/session_init.php deleted file mode 100644 index f6fa564880..0000000000 --- a/tests/session/session_init.php +++ /dev/null @@ -1,76 +0,0 @@ -createXMLDataSet(dirname(__FILE__).'/fixtures/sessions_empty.xml'); - } - - // also see security/extract_current_page.php - - public function test_login_session_create() - { - $session = new phpbb_mock_session_testable; - $session->page = array('page' => 'page', 'forum' => 0); - - // set up all the global variables used in session_create - global $SID, $_SID, $db, $config, $cache; - - $config = $this->get_config(); - $db = $this->new_dbal(); - $cache_data = array( - '_bots' => array(), - ); - $cache = new phpbb_mock_cache; - $SID = $_SID = null; - - $session->session_create(3); - - $sql = 'SELECT session_user_id - FROM phpbb_sessions'; - - $this->assertResultEquals( - $sql, - array(array('session_user_id' => 3)), - 'Check if exacly one session for user id 3 was created' - ); - - $cookie_expire = $session->time_now + (($config['max_autologin_time']) ? 86400 * (int) $config['max_autologin_time'] : 31536000); - - $session->check_cookies($this, array( - 'u' => array(null, $cookie_expire), - 'k' => array(null, $cookie_expire), - 'sid' => array($_SID, $cookie_expire), - )); - - $cache->check($this, $cache_data); - } - - static public function get_config() - { - return array( - 'allow_autologin' => false, - 'auth_method' => 'db', - 'forwarded_for_check' => true, - 'active_sessions' => 0, // disable - 'rand_seed' => 'foo', - 'rand_seed_last_update' => 0, - 'max_autologin_time' => 0, - 'session_length' => 100, - 'form_token_lifetime' => 100, - ); - } -} - -- cgit v1.2.1