aboutsummaryrefslogtreecommitdiffstats
path: root/tests/session/extract_hostname_test.php
blob: bd183fd4384f93f9dd488d8e7d33a61ae8818abb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?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_extract_hostname_test extends phpbb_session_test_case
{
	public function getDataSet()
	{
		return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/sessions_empty.xml');
	}

	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'),
			//    ipv6
			array('::1', 'skipped.org', 'skipped.org', ':'),
			array('2002::3235:51f9', 'skipped.org', 'skipped.org', '2002::3235'),
			// 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 = $this->session_facade->extract_current_hostname(
			$host,
			$server_name_config,
			$cookie_domain_config
		);

		$this->assertEquals($expected, $output);
	}
}