From d533e8807c1f88bd1e3c30ca518e795403b521ff Mon Sep 17 00:00:00 2001 From: asperous Date: Fri, 12 Jul 2013 09:54:38 -0700 Subject: [ticket/11620] Added a test for checking if users are banned PHPBB3-11620 --- tests/session/check_ban_test.php | 51 ++++++++++++++++++++++ tests/session/fixtures/sessions_banlist.xml | 66 +++++++++++++++++++++++++++++ 2 files changed, 117 insertions(+) create mode 100644 tests/session/check_ban_test.php create mode 100644 tests/session/fixtures/sessions_banlist.xml (limited to 'tests/session') diff --git a/tests/session/check_ban_test.php b/tests/session/check_ban_test.php new file mode 100644 index 0000000000..ec1f5e3aa1 --- /dev/null +++ b/tests/session/check_ban_test.php @@ -0,0 +1,51 @@ +createXMLDataSet(dirname(__FILE__).'/fixtures/sessions_banlist.xml'); + } + + static function check_banned_data() + { + return array( + array('All false values, should not be banned', + false, false, false, false, /* ?: */ false), + array('Matching values in the database, should be banned', + 4, '127.0.0.1', 'bar@example.org', true, /* ?: */ true), + array('IP Banned, should be banned', + false, '127.1.1.1', false, falseN, /* ?: */ true), + ); + } + + /** @dataProvider check_banned_data */ + public function test_check_is_banned($test_msg, $user_id, $user_ips, $user_email, $return, $should_be_banned) + { + $session = $this->session_factory->get_session($this->db); + // Change the global cache object for this test because + // the mock cache object does not hit the database as is + // needed for this test. + global $cache; + $old_cache = $cache; + $cache = new phpbb_cache_driver_file(); + + $is_banned = + $session->check_ban($user_id, $user_ips, $user_email, $return); + $this->assertEquals($should_be_banned, $is_banned, $test_msg); + + $cache = $old_cache; + } +} diff --git a/tests/session/fixtures/sessions_banlist.xml b/tests/session/fixtures/sessions_banlist.xml new file mode 100644 index 0000000000..9422fc0665 --- /dev/null +++ b/tests/session/fixtures/sessions_banlist.xml @@ -0,0 +1,66 @@ + + + + user_id + username_clean + user_permissions + user_sig + user_occ + user_interests + + 1 + anonymous + + + + + +
+ + session_id + session_user_id + session_ip + session_browser + session_admin + + bar_session000000000000000000000 + 4 + 127.0.0.1 + user agent + 1 + +
+ + ban_id + ban_userid + ban_ip + ban_email + ban_start + ban_end + ban_exclude + ban_reason + ban_give_reason + + 2 + 4 + 127.0.0.1 + bar@example.org + 1111 + 0 + 0 + HAHAHA + 1 + + + 3 + 0 + 127.1.1.1 + + 1111 + 0 + 0 + HAHAHA + 1 + +
+
-- cgit v1.2.1