Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
41.18% |
7 / 17 |
|
66.67% |
2 / 3 |
CRAP | |
0.00% |
0 / 1 |
| phpbb_session_extract_hostname_test | |
41.18% |
7 / 17 |
|
66.67% |
2 / 3 |
4.83 | |
0.00% |
0 / 1 |
| getDataSet | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| extract_current_hostname_data | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
2 | |||
| test_extract_current_hostname | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * |
| 4 | * This file is part of the phpBB Forum Software package. |
| 5 | * |
| 6 | * @copyright (c) phpBB Limited <https://www.phpbb.com> |
| 7 | * @license GNU General Public License, version 2 (GPL-2.0) |
| 8 | * |
| 9 | * For full copyright and license information, please see |
| 10 | * the docs/CREDITS.txt file. |
| 11 | * |
| 12 | */ |
| 13 | |
| 14 | require_once __DIR__ . '/../test_framework/phpbb_session_test_case.php'; |
| 15 | |
| 16 | class phpbb_session_extract_hostname_test extends phpbb_session_test_case |
| 17 | { |
| 18 | public function getDataSet() |
| 19 | { |
| 20 | return $this->createXMLDataSet(__DIR__ . '/fixtures/sessions_empty.xml'); |
| 21 | } |
| 22 | |
| 23 | static public function extract_current_hostname_data() |
| 24 | { |
| 25 | return array ( |
| 26 | // [Input] $host, $server_name_config, $cookie_domain_config, [Expected] $output |
| 27 | // If host is ip use that |
| 28 | // ipv4 |
| 29 | array('127.0.0.1', 'skipped.org', 'skipped.org', '127.0.0.1'), |
| 30 | // ipv6 |
| 31 | array('::1', 'skipped.org', 'skipped.org', ':'), |
| 32 | array('2002::3235:51f9', 'skipped.org', 'skipped.org', '2002::3235'), |
| 33 | // If no host but server name matches cookie_domain use that |
| 34 | array('', 'example.org', 'example.org', 'example.org'), |
| 35 | // If there is a host uri use that |
| 36 | array('example.org', false, false, 'example.org'), |
| 37 | // 'best approach' guessing |
| 38 | array('', 'example.org', false, 'example.org'), |
| 39 | array('', false, '127.0.0.1', '127.0.0.1'), |
| 40 | array('', false, false, php_uname('n')), |
| 41 | ); |
| 42 | } |
| 43 | |
| 44 | /** @dataProvider extract_current_hostname_data */ |
| 45 | function test_extract_current_hostname($host, $server_name_config, $cookie_domain_config, $expected) |
| 46 | { |
| 47 | $output = $this->session_facade->extract_current_hostname( |
| 48 | $host, |
| 49 | $server_name_config, |
| 50 | $cookie_domain_config |
| 51 | ); |
| 52 | |
| 53 | $this->assertEquals($expected, $output); |
| 54 | } |
| 55 | } |