diff options
Diffstat (limited to 'tests/session/testable_factory.php')
-rw-r--r-- | tests/session/testable_factory.php | 58 |
1 files changed, 50 insertions, 8 deletions
diff --git a/tests/session/testable_factory.php b/tests/session/testable_factory.php index 00f79738ef..a58e208efc 100644 --- a/tests/session/testable_factory.php +++ b/tests/session/testable_factory.php @@ -2,12 +2,13 @@ /** * * @package testing -* @copyright (c) 2011 phpBB Group +* @copyright (c) 2013 phpBB Group * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 * */ -require_once dirname(__FILE__) . '/../mock/session_testable.php'; +require_once dirname(__FILE__) . '/../mock/container_builder.php'; +require_once dirname(__FILE__) . '/../mock/auth_provider.php'; /** * This class exists to setup an instance of phpbb's session class for testing. @@ -18,12 +19,14 @@ require_once dirname(__FILE__) . '/../mock/session_testable.php'; */ class phpbb_session_testable_factory { + protected $container; protected $config_data; protected $cache_data; protected $cookies; protected $config; protected $cache; + protected $request; /** * Initialises the factory with a set of default config and cache values. @@ -60,22 +63,35 @@ class phpbb_session_testable_factory /** * Retrieve the configured session class instance * - * @param dbal $dbal The database connection to use for session data + * @param \phpbb\db\driver\driver $dbal The database connection to use for session data * @return phpbb_mock_session_testable A session instance */ - public function get_session(dbal $dbal) + public function get_session(\phpbb\db\driver\driver $dbal) { // set up all the global variables used by session - global $SID, $_SID, $db, $config, $cache; + global $SID, $_SID, $db, $config, $cache, $request, $phpbb_container; + + $request = $this->request = new phpbb_mock_request( + array(), + array(), + $this->cookies, + $this->server_data + ); + request_var(null, null, null, null, $request); + + $config = $this->config = new \phpbb\config\config($this->get_config_data()); + set_config(null, null, null, $config); - $config = $this->config = $this->get_config_data(); $db = $dbal; $cache = $this->cache = new phpbb_mock_cache($this->get_cache_data()); $SID = $_SID = null; - $_COOKIE = $this->cookies; - $_SERVER = $this->server_data; + $phpbb_container = $this->container = new phpbb_mock_container_builder(); + $phpbb_container->set( + 'auth.provider.db', + new phpbb_mock_auth_provider() + ); $session = new phpbb_mock_session_testable; return $session; @@ -159,6 +175,32 @@ class phpbb_session_testable_factory } /** + * Set cookies, merge config and server data in one step. + * + * New values overwrite old ones. + * + * @param $session_id + * @param $user_id + * @param $user_agent + * @param $ip + * @param int $time + */ + public function merge_test_data($session_id, $user_id, $user_agent, $ip, $time = 0) + { + $this->set_cookies(array( + '_sid' => $session_id, + '_u' => $user_id, + )); + $this->merge_config_data(array( + 'session_length' => time() + $time, // need to do this to allow sessions started at time 0 + )); + $this->merge_server_data(array( + 'HTTP_USER_AGENT' => $user_agent, + 'REMOTE_ADDR' => $ip, + )); + } + + /** * Retrieve all server variables to be passed to the session. * * @return array Server variables |