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/init_test.php | 76 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 tests/session/init_test.php (limited to 'tests/session/init_test.php') 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, + ); + } +} + -- cgit v1.2.1 From 0cf741f3434ed5ad6550e3e8384d3f5665a23fe8 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Sat, 19 Feb 2011 20:40:32 -0500 Subject: [ticket/10049] Fixed requires in session tests and mock. PHPBB3-10049 --- tests/session/init_test.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'tests/session/init_test.php') diff --git a/tests/session/init_test.php b/tests/session/init_test.php index f6fa564880..6cda7a0c2c 100644 --- a/tests/session/init_test.php +++ b/tests/session/init_test.php @@ -7,9 +7,8 @@ * */ -require_once 'test_framework/framework.php'; -require_once 'mock/cache.php'; -require_once 'mock/session_testable.php'; +require_once dirname(__FILE__) . '/../mock/cache.php'; +require_once dirname(__FILE__) . '/../mock/session_testable.php'; class phpbb_session_init_test extends phpbb_database_test_case { -- cgit v1.2.1 From 26b922ac3f220902bb527426039c552a0bcb8f5c Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Sat, 19 Feb 2011 20:44:59 -0500 Subject: [ticket/10049] Chase assertResultEquals rename. cd694e9b9dfd59c8be00a52b30db8e6c280b97a9 renamed assertResultEquals to assertSqlResultEquals. However, since the session tests were never executed calls in them were never updated. Parameter order also changed; chase that too. PHPBB3-10049 --- tests/session/init_test.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tests/session/init_test.php') diff --git a/tests/session/init_test.php b/tests/session/init_test.php index 6cda7a0c2c..c810bd6c3c 100644 --- a/tests/session/init_test.php +++ b/tests/session/init_test.php @@ -40,9 +40,9 @@ class phpbb_session_init_test extends phpbb_database_test_case $sql = 'SELECT session_user_id FROM phpbb_sessions'; - $this->assertResultEquals( - $sql, + $this->assertSqlResultEquals( array(array('session_user_id' => 3)), + $sql, 'Check if exacly one session for user id 3 was created' ); -- cgit v1.2.1 From 6902ecf6a97df44b6874c0bf4c9fa28275b7c9f7 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Sun, 20 Feb 2011 08:53:15 -0500 Subject: [ticket/10049] Mark session init test incomplete for now. This test passes by itself but fails when run as part of the compete suite. Mark it incomplete to avoid breaking the suite. PHPBB3-10049 --- tests/session/init_test.php | 2 ++ 1 file changed, 2 insertions(+) (limited to 'tests/session/init_test.php') diff --git a/tests/session/init_test.php b/tests/session/init_test.php index c810bd6c3c..ccb0554409 100644 --- a/tests/session/init_test.php +++ b/tests/session/init_test.php @@ -21,6 +21,8 @@ class phpbb_session_init_test extends phpbb_database_test_case public function test_login_session_create() { + $this->markTestIncomplete('Test fails when run as part of the test suite'); + $session = new phpbb_mock_session_testable; $session->page = array('page' => 'page', 'forum' => 0); -- cgit v1.2.1 From 11262afa93fc7e1eea31873e3d1a7139230c427e Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Wed, 23 Feb 2011 17:21:51 +0100 Subject: [ticket/10052] Correct session tests, and separate session factory from tests PHPBB3-10052 --- tests/session/init_test.php | 45 ++++++++++++--------------------------------- 1 file changed, 12 insertions(+), 33 deletions(-) (limited to 'tests/session/init_test.php') diff --git a/tests/session/init_test.php b/tests/session/init_test.php index ccb0554409..cad327a490 100644 --- a/tests/session/init_test.php +++ b/tests/session/init_test.php @@ -2,13 +2,13 @@ /** * * @package testing -* @copyright (c) 2008 phpBB Group +* @copyright (c) 2011 phpBB Group * @license http://opensource.org/licenses/gpl-license.php GNU Public License * */ require_once dirname(__FILE__) . '/../mock/cache.php'; -require_once dirname(__FILE__) . '/../mock/session_testable.php'; +require_once dirname(__FILE__) . '/testable_factory.php'; class phpbb_session_init_test extends phpbb_database_test_case { @@ -21,21 +21,11 @@ class phpbb_session_init_test extends phpbb_database_test_case public function test_login_session_create() { - $this->markTestIncomplete('Test fails when run as part of the test suite'); - - $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_factory = new phpbb_session_testable_factory; + + $session = $session_factory->get_session($db); + $session->page = array('page' => 'page', 'forum' => 0); $session->session_create(3); @@ -48,30 +38,19 @@ class phpbb_session_init_test extends phpbb_database_test_case '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); + $cookie_expire = $session->time_now + 31536000; $session->check_cookies($this, array( 'u' => array(null, $cookie_expire), 'k' => array(null, $cookie_expire), - 'sid' => array($_SID, $cookie_expire), + 'sid' => array($session->session_id, $cookie_expire), )); - $cache->check($this, $cache_data); - } + global $SID, $_SID; + $this->assertEquals($session->session_id, $_SID); + $this->assertEquals('?sid=' . $session->session_id, $SID); - 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, - ); + $session_factory->check($this); } } -- cgit v1.2.1 From cb56ab2dbda6c2c33f6437069de35bd09aeadb82 Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Wed, 23 Feb 2011 19:41:11 +0100 Subject: [ticket/10052] Add comments to the session testable factory. PHPBB3-10052 --- tests/session/init_test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests/session/init_test.php') diff --git a/tests/session/init_test.php b/tests/session/init_test.php index cad327a490..1181fab636 100644 --- a/tests/session/init_test.php +++ b/tests/session/init_test.php @@ -38,7 +38,7 @@ class phpbb_session_init_test extends phpbb_database_test_case 'Check if exacly one session for user id 3 was created' ); - $cookie_expire = $session->time_now + 31536000; + $cookie_expire = $session->time_now + 31536000; // default is one year $session->check_cookies($this, array( 'u' => array(null, $cookie_expire), -- cgit v1.2.1