Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
39 / 39
100.00% covered (success)
100.00%
1 / 1
CRAP
100.00% covered (success)
100.00%
1 / 1
ServerSignatureTester
100.00% covered (success)
100.00%
39 / 39
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
39 / 39
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3namespace HtaccessCapabilityTester\Testers;
4
5/**
6 * Class for testing if ServerSignature works
7 *
8 * Testing the ServerSignature directive is of interest because the directive is a core feature.
9 * If a core feature doesn't work, well, it it would seem that .htaccess files are disabled completely.
10 * The test is thus special. If it returns *failure* it is highly probable that the .htaccess file has
11 * not been read.
12 *
13 * Unfortunately, the test requires PHP to examine if a server variable has been set. So the test is not
14 * unlikely to come out inconclusive due to a 403 Forbidden.
15 *
16 * Note that the test assumes that the ServerSignature directive has not been disallowed even though
17 * it is technically possible to do so by setting *AllowOverride* to *None* and by setting *AllowOverrideList*
18 * to a list that does not include *ServerSignature*.
19 *
20 * @package    HtaccessCapabilityTester
21 * @author     Bjørn Rosell <it@rosell.dk>
22 * @since      Class available since 0.7
23 */
24class ServerSignatureTester extends CustomTester
25{
26
27    /**
28     * Constructor.
29     *
30     * @return void
31     */
32    public function __construct()
33    {
34        $phpOn = <<<'EOD'
35<?php
36if (isset($_SERVER['SERVER_SIGNATURE']) && ($_SERVER['SERVER_SIGNATURE'] != '')) {
37    echo 1;
38} else {
39    echo 0;
40}
41EOD;
42
43        $phpOff = <<<'EOD'
44<?php
45if (isset($_SERVER['SERVER_SIGNATURE']) && ($_SERVER['SERVER_SIGNATURE'] != '')) {
46    echo 0;
47} else {
48    echo 1;
49}
50EOD;
51
52        // PS:
53        // There is a little edge case: When .htaccess is disabled AND phps are either not processed
54        // or access is denied. This ought to return *failure*, but it currently returns *inconclusive*.
55
56        $test = [
57            'subdir' => 'server-signature',
58            'subtests' => [
59                [
60                    'subdir' => 'on',
61                    'files' => [
62                        ['.htaccess', 'ServerSignature On'],
63                        ['test.php', $phpOn],
64                    ],
65                    'request' => [
66                        'url' => 'test.php',
67                    ],
68                    'interpretation' => [
69                        ['inconclusive', 'body', 'isEmpty'],
70                        ['inconclusive', 'status-code', 'not-equals', '200'],
71                        ['failure', 'body', 'equals', '0'],
72                    ],
73                ],
74                [
75                    'subdir' => 'off',
76                    'files' => [
77                        ['.htaccess', 'ServerSignature Off'],
78                        ['test.php', $phpOff],
79                    ],
80                    'request' => 'test.php',
81                    'interpretation' => [
82                        ['inconclusive', 'body', 'isEmpty'],
83                        ['success', 'body', 'equals', '1'],
84                        ['failure', 'body', 'equals', '0'],
85                        ['inconclusive']
86                    ]
87                ]
88            ]
89        ];
90
91        parent::__construct($test);
92    }
93}