Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
90.91% |
10 / 11 |
|
66.67% |
2 / 3 |
CRAP | |
0.00% |
0 / 1 |
| phpbb_mock_session_testable | |
90.91% |
10 / 11 |
|
66.67% |
2 / 3 |
7.04 | |
0.00% |
0 / 1 |
| set_cookie | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| check_cookies | |
88.89% |
8 / 9 |
|
0.00% |
0 / 1 |
5.03 | |||
| setup | |
100.00% |
1 / 1 |
|
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 | /** |
| 15 | * Extends the session class to overwrite the setting of cookies. |
| 16 | * |
| 17 | * The session class directly writes cookie headers making it impossible to |
| 18 | * test it without warnings about sent headers. This class only stores cookie |
| 19 | * data for later verification. |
| 20 | */ |
| 21 | class phpbb_mock_session_testable extends \phpbb\session |
| 22 | { |
| 23 | private $_cookies = array(); |
| 24 | public $lang = []; |
| 25 | |
| 26 | public function set_cookie($name, $data, $time, $httponly = true) |
| 27 | { |
| 28 | $this->_cookies[$name] = array($data, $time); |
| 29 | } |
| 30 | |
| 31 | /** |
| 32 | * Checks if the cookies were set correctly. |
| 33 | * |
| 34 | * @param PHPUnit\Framework\Assert $test The test from which this is called |
| 35 | * @param array<string,mixed> $cookies The cookie data to check against. |
| 36 | * The keys are cookie names, the values can either be null to |
| 37 | * check only the existence of the cookie, or an array(d, t), |
| 38 | * where d is the cookie data to check, or null to skip the |
| 39 | * check and t is the cookie time to check, or null to skip. |
| 40 | */ |
| 41 | public function check_cookies(PHPUnit\Framework\Assert $test, $cookies) |
| 42 | { |
| 43 | $test->assertEquals(array_keys($cookies), array_keys($this->_cookies), 'Incorrect cookies were set'); |
| 44 | |
| 45 | foreach ($cookies as $name => $cookie) |
| 46 | { |
| 47 | if (!is_null($cookie)) |
| 48 | { |
| 49 | $data = $cookie[0]; |
| 50 | $time = $cookie[1]; |
| 51 | |
| 52 | if (!is_null($data)) |
| 53 | { |
| 54 | $test->assertEquals($data, $this->_cookies[$name][0], "Cookie $name contains incorrect data"); |
| 55 | } |
| 56 | |
| 57 | if (!is_null($time)) |
| 58 | { |
| 59 | $test->assertEquals($time, $this->_cookies[$name][1], "Cookie $name expires at the wrong time"); |
| 60 | } |
| 61 | } |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | public function setup($lang_set = false, $style_id = false) |
| 66 | { |
| 67 | } |
| 68 | } |
| 69 |