diff options
author | Nils Adermann <naderman@naderman.de> | 2011-01-04 17:14:36 +0100 |
---|---|---|
committer | Nils Adermann <naderman@naderman.de> | 2011-01-20 22:47:48 +0100 |
commit | 74f537e89d899831c606b9abe218383a4e71408e (patch) | |
tree | f813e889fe6c584fb0a73b3bc642cdd1c243a5b7 /tests/session/session_continue.php | |
parent | ba5c7d8e63d97650989c2866c20c11f16f4c1128 (diff) | |
download | forums-74f537e89d899831c606b9abe218383a4e71408e.tar forums-74f537e89d899831c606b9abe218383a4e71408e.tar.gz forums-74f537e89d899831c606b9abe218383a4e71408e.tar.bz2 forums-74f537e89d899831c606b9abe218383a4e71408e.tar.xz forums-74f537e89d899831c606b9abe218383a4e71408e.zip |
[task/session-tests] Added tests for the session class.
Two first simple tests to check functionality of session_begin and
session_create.
Added a mock class for the cache as well as a subclass of session
which has its cookie handling function mocked out to avoid header
sending problems.
PHPBB3-9732
Diffstat (limited to 'tests/session/session_continue.php')
-rw-r--r-- | tests/session/session_continue.php | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/tests/session/session_continue.php b/tests/session/session_continue.php new file mode 100644 index 0000000000..15be667325 --- /dev/null +++ b/tests/session/session_continue.php @@ -0,0 +1,83 @@ +<?php +/** +* +* @package testing +* @copyright (c) 2008 phpBB Group +* @license http://opensource.org/licenses/gpl-license.php GNU Public License +* +*/ + +require_once 'test_framework/framework.php'; +require_once 'mock/cache.php'; +require_once 'mock/session_testable.php'; + +class phpbb_session_continue_test extends phpbb_database_test_case +{ + public function getDataSet() + { + return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/sessions_full.xml'); + } + + public function test_session_begin_valid_session() + { + $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'] = 'bar_session'; + $_COOKIE['_u'] = '4'; + $_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'; + + $this->assertResultEquals( + $sql, + array( + array('session_id' => 'anon_session', 'session_user_id' => 1), + array('session_id' => 'bar_session', 'session_user_id' => 4) + ), + '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()); + + $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, + ); + } +} + |