aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorasperous <asperous2@gmail.com>2013-07-12 13:04:37 -0700
committerAndy Chase <asperous2@gmail.com>2013-07-22 11:07:45 -0700
commit7dbd85ad02b031fc2392adfd27c66c3725ef117b (patch)
tree478afba770234b70dff6c4d7e958faa42a82b3bd
parentaf3a4ee33a148c864c30d22a2031cfc7e1b7bcf3 (diff)
downloadforums-7dbd85ad02b031fc2392adfd27c66c3725ef117b.tar
forums-7dbd85ad02b031fc2392adfd27c66c3725ef117b.tar.gz
forums-7dbd85ad02b031fc2392adfd27c66c3725ef117b.tar.bz2
forums-7dbd85ad02b031fc2392adfd27c66c3725ef117b.tar.xz
forums-7dbd85ad02b031fc2392adfd27c66c3725ef117b.zip
[ticket/11620] Added garbage_collection_test
PHPBB3-11620
-rw-r--r--tests/session/fixtures/sessions_garbage.xml58
-rw-r--r--tests/session/garbage_collection_test.php63
2 files changed, 121 insertions, 0 deletions
diff --git a/tests/session/fixtures/sessions_garbage.xml b/tests/session/fixtures/sessions_garbage.xml
new file mode 100644
index 0000000000..23c44a975b
--- /dev/null
+++ b/tests/session/fixtures/sessions_garbage.xml
@@ -0,0 +1,58 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<dataset>
+ <table name="phpbb_users">
+ <column>user_id</column>
+ <column>username_clean</column>
+ <column>user_permissions</column>
+ <column>user_sig</column>
+ <column>user_occ</column>
+ <column>user_interests</column>
+ <row>
+ <value>4</value>
+ <value>bar</value>
+ <value></value>
+ <value></value>
+ <value></value>
+ <value></value>
+ </row>
+ </table>
+ <table name="phpbb_sessions">
+ <column>session_id</column>
+ <column>session_user_id</column>
+ <column>session_ip</column>
+ <column>session_browser</column>
+ <column>session_admin</column>
+ <row>
+ <value>anon_session00000000000000000000</value>
+ <value>1</value>
+ <value>127.0.0.1</value>
+ <value>anonymous user agent</value>
+ <value>0</value>
+ </row>
+ <row>
+ <value>bar_session000000000000000000000</value>
+ <value>4</value>
+ <value>127.0.0.1</value>
+ <value>user agent</value>
+ <value>1</value>
+ </row>
+ </table>
+ <table name="phpbb_login_attempts">
+ <column>attempt_ip</column>
+ <column>attempt_browser</column>
+ <column>attempt_forwarded_for</column>
+ <column>attempt_time</column>
+ <column>user_id</column>
+ <column>username</column>
+ <column>username_clean</column>
+ <row>
+ <value>127.0.0.1</value>
+ <value>browser</value>
+ <value></value>
+ <value>0001</value>
+ <value>4</value>
+ <value>bar</value>
+ <value>bar</value>
+ </row>
+ </table>
+</dataset>
diff --git a/tests/session/garbage_collection_test.php b/tests/session/garbage_collection_test.php
new file mode 100644
index 0000000000..1b607dfb4f
--- /dev/null
+++ b/tests/session/garbage_collection_test.php
@@ -0,0 +1,63 @@
+<?php
+/**
+ *
+ * @package testing
+ * @copyright (c) 2013 phpBB Group
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+ *
+ */
+
+require_once dirname(__FILE__) . '/../test_framework/phpbb_session_test_case.php';
+
+class phpbb_session_garbage_collection_test extends phpbb_session_test_case
+{
+ public $session;
+
+ public function getDataSet()
+ {
+ return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/sessions_garbage.xml');
+ }
+
+ public function setUp()
+ {
+ parent::setUp();
+ $this->session = $this->session_factory->get_session($this->db);
+ }
+
+ protected function assert_sessions_equal($expected, $msg)
+ {
+ $sql = 'SELECT session_id, session_user_id
+ FROM phpbb_sessions
+ ORDER BY session_user_id';
+
+ $this->assertSqlResultEquals($expected, $sql, $msg);
+ }
+
+ public function test_cleanup_all()
+ {
+ $this->assert_sessions_equal(
+ array(
+ array
+ (
+ 'session_id' => 'anon_session00000000000000000000',
+ 'session_user_id' => 1,
+ ),
+ array
+ (
+ 'session_id' => 'bar_session000000000000000000000',
+ 'session_user_id' => 4,
+ )),
+ 'Before test, should have some sessions.'
+ );
+ // Set session length so it clears all
+ global $config;
+ $config['session_length'] = 0;
+ // There is an error unless the captcha plugin is set
+ $config['captcha_plugin'] = 'phpbb_captcha_nogd';
+ $this->session->session_gc();
+ $this->assert_sessions_equal(
+ array(),
+ 'After setting session time to 0, should remove all.'
+ );
+ }
+}