aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorAndy Chase <asperous2@gmail.com>2013-07-01 00:11:44 -0700
committerAndy Chase <asperous2@gmail.com>2013-07-05 14:09:50 -0700
commitb8d9d7b79f98093a5870db2e3b60663ed5069d39 (patch)
treeb22b520fa935fa36bf1eae52bd800fed9f0dc7d2 /tests
parent7fd03abcab531d3e989753492ab0cce78549c1a3 (diff)
downloadforums-b8d9d7b79f98093a5870db2e3b60663ed5069d39.tar
forums-b8d9d7b79f98093a5870db2e3b60663ed5069d39.tar.gz
forums-b8d9d7b79f98093a5870db2e3b60663ed5069d39.tar.bz2
forums-b8d9d7b79f98093a5870db2e3b60663ed5069d39.tar.xz
forums-b8d9d7b79f98093a5870db2e3b60663ed5069d39.zip
[ticket/11620] Add extract_current_hostname
Add a tests for extracting the current hostname from session. PHPBB3-11620
Diffstat (limited to 'tests')
-rw-r--r--tests/session/extract_hostname_test.php58
-rw-r--r--tests/session/testable_facade.php11
2 files changed, 68 insertions, 1 deletions
diff --git a/tests/session/extract_hostname_test.php b/tests/session/extract_hostname_test.php
new file mode 100644
index 0000000000..a126626ae3
--- /dev/null
+++ b/tests/session/extract_hostname_test.php
@@ -0,0 +1,58 @@
+<?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__) . '/testable_facade.php';
+
+class phpbb_session_extract_hostname_test extends phpbb_database_test_case
+{
+ public $session_factory;
+ public $db;
+
+ public function getDataSet()
+ {
+ return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/sessions_empty.xml');
+ }
+
+ public function setUp()
+ {
+ $this->session_factory = new phpbb_session_testable_factory;
+ $this->db = $this->new_dbal();
+ }
+
+ static public function extract_current_hostname_data()
+ {
+ return array (
+ // [Input] $host, $server_name_config, $cookie_domain_config, [Expected] $output
+ // If host is ip use that ipv4
+ array("127.0.0.1", "skipped.org", "skipped.org", "127.0.0.1"),
+ // If no host but server name matches cookie_domain use that
+ array("", "example.org", "example.org", "example.org"),
+ // If there is a host uri use that
+ array("example.org", False, False, "example.org"),
+ // "best approach" guessing
+ array("", "example.org", False, "example.org"),
+ array("", False, "127.0.0.1", "127.0.0.1"),
+ array("", False, False, php_uname('n')),
+ );
+ }
+
+ /** @dataProvider extract_current_hostname_data */
+ function test_extract_current_hostname($host, $server_name_config, $cookie_domain_config, $expected)
+ {
+ $output = phpbb_session_testable_facade::extract_current_hostname(
+ $this->db,
+ $this->session_factory,
+ $host,
+ $server_name_config,
+ $cookie_domain_config
+ );
+
+ $this->assertEquals($expected, $output);
+ }
+}
diff --git a/tests/session/testable_facade.php b/tests/session/testable_facade.php
index f85332c94a..a4a3d63ed4 100644
--- a/tests/session/testable_facade.php
+++ b/tests/session/testable_facade.php
@@ -31,8 +31,17 @@ class phpbb_session_testable_facade
return phpbb_session::extract_current_page($root_path);
}
+ public static function extract_current_hostname($db, $session_factory, $host, $server_name_config, $cookie_domain_config) {
+ $session = $session_factory->get_session($db);
+ global $config, $request;
+ $config['server_name'] = $server_name_config;
+ $config['cookie_domain'] = $cookie_domain_config;
+ $request->overwrite('SERVER_NAME', $host, phpbb_request_interface::SERVER);
+ $request->overwrite('Host', $host, phpbb_request_interface::SERVER);
+ // Note: There is a php_uname fallthrough in this method that this function doesn't override
+ return $session->extract_current_hostname();
+ }
// [To be completed]
- // public static function extract_current_hostname() {}
// public static function session_begin($update_session_page = true) {}
// public static function session_create($user_id = false, $set_admin = false, $persist_login = false, $viewonline = true) {}
// public static function session_kill($new_session = true) {}