Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
15.79% covered (danger)
15.79%
3 / 19
50.00% covered (danger)
50.00%
1 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
phpbb_session_append_sid_test
15.79% covered (danger)
15.79%
3 / 19
50.00% covered (danger)
50.00%
1 / 2
4.39
0.00% covered (danger)
0.00%
0 / 1
 append_sid_data
0.00% covered (danger)
0.00%
0 / 16
0.00% covered (danger)
0.00%
0 / 1
2
 test_append_sid
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
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
14class phpbb_session_append_sid_test extends phpbb_test_case
15{
16
17    public static function append_sid_data()
18    {
19        return array(
20            array('viewtopic.php?t=1&amp;f=2', false, true, false, 'viewtopic.php?t=1&amp;f=2', 'parameters in url-argument'),
21            array('viewtopic.php', 't=1&amp;f=2', true, false, 'viewtopic.php?t=1&amp;f=2', 'parameters in params-argument using amp'),
22            array('viewtopic.php', 't=1&f=2', false, false, 'viewtopic.php?t=1&f=2', 'parameters in params-argument using &'),
23            array('viewtopic.php', array('t' => 1, 'f' => 2), true, false, 'viewtopic.php?t=1&amp;f=2', 'parameters in params-argument as array'),
24
25            // Custom sid parameter
26            array('viewtopic.php', 't=1&amp;f=2', true, 'custom-sid', 'viewtopic.php?t=1&amp;f=2&amp;sid=custom-sid', 'using session_id'),
27
28            // Testing anchors
29            array('viewtopic.php?t=1&amp;f=2#anchor', false, true, false, 'viewtopic.php?t=1&amp;f=2#anchor', 'anchor in url-argument'),
30            array('viewtopic.php', 't=1&amp;f=2#anchor', true, false, 'viewtopic.php?t=1&amp;f=2#anchor', 'anchor in params-argument'),
31            array('viewtopic.php', array('t' => 1, 'f' => 2, '#' => 'anchor'), true, false, 'viewtopic.php?t=1&amp;f=2#anchor', 'anchor in params-argument (array)'),
32
33            // Anchors and custom sid
34            array('viewtopic.php?t=1&amp;f=2#anchor', false, true, 'custom-sid', 'viewtopic.php?t=1&amp;f=2&amp;sid=custom-sid#anchor', 'anchor in url-argument using session_id'),
35            array('viewtopic.php', 't=1&amp;f=2#anchor', true, 'custom-sid', 'viewtopic.php?t=1&amp;f=2&amp;sid=custom-sid#anchor', 'anchor in params-argument using session_id'),
36            array('viewtopic.php', array('t' => 1, 'f' => 2, '#' => 'anchor'), true, 'custom-sid', 'viewtopic.php?t=1&amp;f=2&amp;sid=custom-sid#anchor', 'anchor in params-argument (array) using session_id'),
37
38            // Empty parameters should not append the ?
39            array('viewtopic.php', false, true, false, 'viewtopic.php', 'no params using bool false'),
40            array('viewtopic.php', '', true, false, 'viewtopic.php', 'no params using empty string'),
41            array('viewtopic.php', array(), true, false, 'viewtopic.php', 'no params using empty array'),
42        );
43    }
44
45    /**
46    * @dataProvider append_sid_data
47    */
48    public function test_append_sid($url, $params, $is_amp, $session_id, $expected, $description)
49    {
50        global $phpbb_dispatcher;
51
52        $phpbb_dispatcher = new phpbb_mock_event_dispatcher;
53        $this->assertEquals($expected, append_sid($url, $params, $is_amp, $session_id));
54    }
55}
56