From 5cdcb689df37fd7cbaaa1b5475caa830e87be318 Mon Sep 17 00:00:00 2001 From: Andy Chase Date: Fri, 5 Jul 2013 14:49:30 -0700 Subject: [ticket/11620] Implemented a provider mock object. Due to an auth_refactor, there is a new dependency in session.php on phpbb_container and a provider. For purposes of testing, implemented a simple one. PHPBB3-11620 --- tests/session/testable_factory.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'tests/session/testable_factory.php') diff --git a/tests/session/testable_factory.php b/tests/session/testable_factory.php index 1e2b194ece..d0d0dabbec 100644 --- a/tests/session/testable_factory.php +++ b/tests/session/testable_factory.php @@ -7,6 +7,9 @@ * */ +require_once dirname(__FILE__) . '/../mock/container_builder.php'; +require_once dirname(__FILE__) . '/../mock/provider.php'; + /** * This class exists to setup an instance of phpbb's session class for testing. * @@ -16,6 +19,7 @@ */ class phpbb_session_testable_factory { + protected $container; protected $config_data; protected $cache_data; protected $cookies; @@ -65,7 +69,7 @@ class phpbb_session_testable_factory public function get_session(phpbb_db_driver $dbal) { // set up all the global variables used by session - global $SID, $_SID, $db, $config, $cache, $request; + global $SID, $_SID, $db, $config, $cache, $request, $phpbb_container; $request = $this->request = new phpbb_mock_request( array(), @@ -83,6 +87,12 @@ class phpbb_session_testable_factory $cache = $this->cache = new phpbb_mock_cache($this->get_cache_data()); $SID = $_SID = null; + $phpbb_container = $this->container = new phpbb_mock_container_builder(); + $phpbb_container->set( + 'auth.provider.db', + new phpbb_provider() + ); + $session = new phpbb_mock_session_testable; return $session; } -- cgit v1.2.1 From f51721e905af68624df422889f92a069abd7b750 Mon Sep 17 00:00:00 2001 From: Andy Chase Date: Mon, 8 Jul 2013 16:38:53 -0700 Subject: [ticket/11620] Rename provider -> mock_auth_provider Rename the class and file name to better match what the class is mocking, as well as implement the interface of that class. PHPBB3-11620 --- tests/session/testable_factory.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tests/session/testable_factory.php') diff --git a/tests/session/testable_factory.php b/tests/session/testable_factory.php index d0d0dabbec..ace968eb43 100644 --- a/tests/session/testable_factory.php +++ b/tests/session/testable_factory.php @@ -8,7 +8,7 @@ */ require_once dirname(__FILE__) . '/../mock/container_builder.php'; -require_once dirname(__FILE__) . '/../mock/provider.php'; +require_once dirname(__FILE__) . '/../mock/auth_provider.php'; /** * This class exists to setup an instance of phpbb's session class for testing. @@ -90,7 +90,7 @@ class phpbb_session_testable_factory $phpbb_container = $this->container = new phpbb_mock_container_builder(); $phpbb_container->set( 'auth.provider.db', - new phpbb_provider() + new phpbb_mock_auth_provider() ); $session = new phpbb_mock_session_testable; -- cgit v1.2.1 From e74abfaa2c25b7c9b4f2f865fbf6800de0761a6b Mon Sep 17 00:00:00 2001 From: Andy Chase Date: Tue, 25 Jun 2013 12:24:02 -0700 Subject: [ticket/11615] Refactored isvalid test to be more imperative Refactoring the continue/is_valid test to remove the confusing data provider work around, while still keeping redundancies down to a minimum. PHPBB3-11615 --- tests/session/testable_factory.php | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) (limited to 'tests/session/testable_factory.php') diff --git a/tests/session/testable_factory.php b/tests/session/testable_factory.php index ace968eb43..8733ce15ef 100644 --- a/tests/session/testable_factory.php +++ b/tests/session/testable_factory.php @@ -2,7 +2,7 @@ /** * * @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 * */ @@ -174,6 +174,32 @@ class phpbb_session_testable_factory return $this->server_data = array_merge($this->server_data, $server_data); } + /** + * 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. * -- cgit v1.2.1