Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
18 / 18 |
|
100.00% |
1 / 1 |
CRAP | |
100.00% |
1 / 1 |
| RequestHeaderTester | |
100.00% |
18 / 18 |
|
100.00% |
1 / 1 |
1 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
18 / 18 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace HtaccessCapabilityTester\Testers; |
| 4 | |
| 5 | /** |
| 6 | * Class for testing if RequestHeader works |
| 7 | * |
| 8 | * @package HtaccessCapabilityTester |
| 9 | * @author Bjørn Rosell <it@rosell.dk> |
| 10 | * @since Class available since 0.7 |
| 11 | */ |
| 12 | class RequestHeaderTester extends CustomTester |
| 13 | { |
| 14 | |
| 15 | /** |
| 16 | * Constructor. |
| 17 | * |
| 18 | * @return void |
| 19 | */ |
| 20 | public function __construct() |
| 21 | { |
| 22 | $htaccessFile = <<<'EOD' |
| 23 | <IfModule mod_headers.c> |
| 24 | # Certain hosts seem to strip non-standard request headers, |
| 25 | # so we use a standard one to avoid a false negative |
| 26 | RequestHeader set User-Agent "request-header-test" |
| 27 | </IfModule> |
| 28 | EOD; |
| 29 | |
| 30 | $phpFile = <<<'EOD' |
| 31 | <?php |
| 32 | if (isset($_SERVER['HTTP_USER_AGENT'])) { |
| 33 | echo (($_SERVER['HTTP_USER_AGENT'] == 'request-header-test') ? "1" : "0"); |
| 34 | } else { |
| 35 | echo "0"; |
| 36 | } |
| 37 | EOD; |
| 38 | |
| 39 | // PS: |
| 40 | // There is a little edge case: When .htaccess is disabled AND phps are either not processed |
| 41 | // or access is denied. This ought to return *failure*, but it currently returns *inconclusive*. |
| 42 | |
| 43 | $test = [ |
| 44 | 'subdir' => 'request-header', |
| 45 | 'files' => [ |
| 46 | ['.htaccess', $htaccessFile], |
| 47 | ['test.php', $phpFile], |
| 48 | ], |
| 49 | 'request' => 'test.php', |
| 50 | 'interpretation' => [ |
| 51 | ['success', 'body', 'equals', '1'], |
| 52 | ['failure', 'body', 'equals', '0'], |
| 53 | ['inconclusive', 'body', 'begins-with', '<' . '?php'], |
| 54 | ] |
| 55 | ]; |
| 56 | |
| 57 | parent::__construct($test); |
| 58 | } |
| 59 | } |