Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
13.57% |
19 / 140 |
|
66.67% |
2 / 3 |
CRAP | |
0.00% |
0 / 1 |
| phpbb_session_extract_page_test | |
13.57% |
19 / 140 |
|
66.67% |
2 / 3 |
14.33 | |
0.00% |
0 / 1 |
| getDataSet | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| extract_current_page_data | |
0.00% |
0 / 121 |
|
0.00% |
0 / 1 |
2 | |||
| test_extract_current_page | |
100.00% |
18 / 18 |
|
100.00% |
1 / 1 |
2 | |||
| 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_page_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_page_data() |
| 24 | { |
| 25 | return array( |
| 26 | array( |
| 27 | './', |
| 28 | '/phpBB/index.php', |
| 29 | '', |
| 30 | '/phpBB/', |
| 31 | '/', |
| 32 | array( |
| 33 | 'page_name' => 'index.php', |
| 34 | 'page_dir' => '', |
| 35 | 'query_string' => '', |
| 36 | 'script_path' => '/phpBB/', |
| 37 | 'root_script_path' => '/phpBB/', |
| 38 | 'page' => 'index.php', |
| 39 | 'forum' => 0, |
| 40 | ), |
| 41 | ), |
| 42 | array( |
| 43 | './', |
| 44 | '/phpBB/ucp.php', |
| 45 | 'mode=login', |
| 46 | '/phpBB/', |
| 47 | '/', |
| 48 | array( |
| 49 | 'page_name' => 'ucp.php', |
| 50 | 'page_dir' => '', |
| 51 | 'query_string' => 'mode=login', |
| 52 | 'script_path' => '/phpBB/', |
| 53 | 'root_script_path' => '/phpBB/', |
| 54 | 'page' => 'ucp.php?mode=login', |
| 55 | 'forum' => 0, |
| 56 | ), |
| 57 | ), |
| 58 | array( |
| 59 | './', |
| 60 | '/phpBB/ucp.php', |
| 61 | 'mode=register', |
| 62 | '/phpBB/', |
| 63 | '/', |
| 64 | array( |
| 65 | 'page_name' => 'ucp.php', |
| 66 | 'page_dir' => '', |
| 67 | 'query_string' => 'mode=register', |
| 68 | 'script_path' => '/phpBB/', |
| 69 | 'root_script_path' => '/phpBB/', |
| 70 | 'page' => 'ucp.php?mode=register', |
| 71 | 'forum' => 0, |
| 72 | ), |
| 73 | ), |
| 74 | array( |
| 75 | './', |
| 76 | '/phpBB/ucp.php', |
| 77 | 'mode=register', |
| 78 | '/phpBB/', |
| 79 | '/', |
| 80 | array( |
| 81 | 'page_name' => 'ucp.php', |
| 82 | 'page_dir' => '', |
| 83 | 'query_string' => 'mode=register', |
| 84 | 'script_path' => '/phpBB/', |
| 85 | 'root_script_path' => '/phpBB/', |
| 86 | 'page' => 'ucp.php?mode=register', |
| 87 | 'forum' => 0, |
| 88 | ), |
| 89 | ), |
| 90 | array( |
| 91 | './../', |
| 92 | '/phpBB/adm/index.php', |
| 93 | 'sid=e7215d958cdd41a6fc13509bebe53e42', |
| 94 | '/phpBB/adm/', |
| 95 | '/', |
| 96 | array( |
| 97 | 'page_name' => 'index.php', |
| 98 | //'page_dir' => 'adm', |
| 99 | // ^-- Ignored because .. returns different directory in live vs testing |
| 100 | 'query_string' => '', |
| 101 | 'script_path' => '/phpBB/adm/', |
| 102 | //'root_script_path' => '/phpBB/adm/', |
| 103 | //'page' => 'adm/index.php', |
| 104 | 'forum' => 0, |
| 105 | ), |
| 106 | ), |
| 107 | array( |
| 108 | './', |
| 109 | '/phpBB/adm/app.php', |
| 110 | 'page=1&test=2', |
| 111 | '/phpBB/adm/', |
| 112 | '/foo/bar', |
| 113 | array( |
| 114 | 'page_name' => 'app.php/foo/bar', |
| 115 | //'page_dir' => '', |
| 116 | 'query_string' => 'page=1&test=2', |
| 117 | 'script_path' => '/phpBB/adm/', |
| 118 | //'root_script_path' => '/phpBB/adm/', |
| 119 | //'page' => 'app.php/foo/bar?page=1&test=2', |
| 120 | 'forum' => 0, |
| 121 | ), |
| 122 | ), |
| 123 | array( |
| 124 | './../phpBB/', |
| 125 | '/test/test.php', |
| 126 | 'page=1&test=2', |
| 127 | '/test/', |
| 128 | '', |
| 129 | array( |
| 130 | 'page_name' => 'test.php', |
| 131 | //'page_dir' => '', |
| 132 | 'query_string' => 'page=1&test=2', |
| 133 | 'script_path' => '/test/', |
| 134 | //'root_script_path' => '../phpBB/', |
| 135 | //'page' => '../test/test.php/foo/bar?page=1&test=2', |
| 136 | 'forum' => 0, |
| 137 | ), |
| 138 | ), |
| 139 | array( |
| 140 | './community', |
| 141 | '/app.php', |
| 142 | '', |
| 143 | '/', |
| 144 | '/kb', |
| 145 | array( |
| 146 | 'page_name' => 'app.php/kb', |
| 147 | 'page_dir' => '..', |
| 148 | 'query_string' => '', |
| 149 | 'script_path' => '/', |
| 150 | 'root_script_path' => '/community/', |
| 151 | 'page' => '../app.php/kb', |
| 152 | 'forum' => 0, |
| 153 | ), |
| 154 | ), |
| 155 | ); |
| 156 | } |
| 157 | |
| 158 | /** @dataProvider extract_current_page_data */ |
| 159 | function test_extract_current_page($root_path, $getScriptName, $getQueryString, $getBasePath, $getPathInfo, $expected) |
| 160 | { |
| 161 | global $symfony_request, $request, $phpbb_filesystem; |
| 162 | |
| 163 | $phpbb_filesystem = new \phpbb\filesystem\filesystem(); |
| 164 | |
| 165 | $server['HTTP_HOST'] = 'localhost'; |
| 166 | $server['SERVER_NAME'] = 'localhost'; |
| 167 | $server['SERVER_ADDR'] = '127.0.0.1'; |
| 168 | $server['SERVER_PORT'] = 80; |
| 169 | $server['REMOTE_ADDR'] = '127.0.0.1'; |
| 170 | $server['QUERY_STRING'] = $getQueryString; |
| 171 | $server['REQUEST_URI'] = $getScriptName . $getPathInfo . ($getQueryString === '' ? '' : '?' . $getQueryString); |
| 172 | $server['SCRIPT_NAME'] = $getScriptName; |
| 173 | $server['SCRIPT_FILENAME'] = '/var/www/' . $getScriptName; |
| 174 | $server['PHP_SELF'] = $getScriptName; |
| 175 | $server['HTTP_USER_AGENT'] = 'Mozilla/5.0 (Windows; U; Windows NT 6.0; de; rv:1.8.1.14) Gecko/20080404 Firefox/2.0.0.14'; |
| 176 | $server['HTTP_ACCEPT_LANGUAGE'] = 'de-de,de;q=0.8,en-us;q=0.5,en;q=0.3'; |
| 177 | |
| 178 | $request = new phpbb_mock_request(array(), array(), array(), $server); |
| 179 | $symfony_request = new \phpbb\symfony_request($request); |
| 180 | |
| 181 | $output = \phpbb\session::extract_current_page($root_path); |
| 182 | |
| 183 | // This compares the result of the output. |
| 184 | // Any keys that are not in the expected array are overwritten by the output (aka not checked). |
| 185 | $this->assert_array_content_equals(array_merge($output, $expected), $output); |
| 186 | } |
| 187 | } |