Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
27 / 27 |
|
100.00% |
3 / 3 |
CRAP | |
100.00% |
1 / 1 |
| HtaccessEnabledTester | |
100.00% |
27 / 27 |
|
100.00% |
3 / 3 |
12 | |
100.00% |
1 / 1 |
| getSubDir | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| registerTestFiles | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| run | |
100.00% |
25 / 25 |
|
100.00% |
1 / 1 |
10 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace HtaccessCapabilityTester\Testers; |
| 4 | |
| 5 | use \HtaccessCapabilityTester\HtaccessCapabilityTester; |
| 6 | use \HtaccessCapabilityTester\TestResult; |
| 7 | |
| 8 | /** |
| 9 | * Class for testing if .htaccess files are processed |
| 10 | * |
| 11 | * @package HtaccessCapabilityTester |
| 12 | * @author Bjørn Rosell <it@rosell.dk> |
| 13 | * @since Class available since 0.7 |
| 14 | */ |
| 15 | class HtaccessEnabledTester extends AbstractTester |
| 16 | { |
| 17 | |
| 18 | /** |
| 19 | * Child classes must implement this method, which tells which subdir the |
| 20 | * test files are to be put. |
| 21 | * |
| 22 | * @return string A subdir for the test files |
| 23 | */ |
| 24 | public function getSubDir() |
| 25 | { |
| 26 | return 'htaccess-enabled'; |
| 27 | } |
| 28 | |
| 29 | /** |
| 30 | * Register the test files using the "registerTestFile" method |
| 31 | * |
| 32 | * @return void |
| 33 | */ |
| 34 | public function registerTestFiles() |
| 35 | { |
| 36 | // No test files for this test |
| 37 | } |
| 38 | |
| 39 | /** |
| 40 | * Run the test. |
| 41 | * |
| 42 | * @param string $baseDir Directory on the server where the test files can be put |
| 43 | * @param string $baseUrl The base URL of the test files |
| 44 | * |
| 45 | * @return TestResult Returns a test result |
| 46 | */ |
| 47 | public function run($baseDir, $baseUrl) |
| 48 | { |
| 49 | $this->prepareForRun($baseDir, $baseUrl); |
| 50 | |
| 51 | /* |
| 52 | PS: We could implement this as a definition: |
| 53 | |
| 54 | |
| 55 | - [success, serverSignatureWorks, is-success] |
| 56 | - [success, contentDigestWorks, is-success] |
| 57 | - [failure, serverSignatureWorks, is-failure] |
| 58 | - [success, canCrash, is-success] |
| 59 | */ |
| 60 | |
| 61 | |
| 62 | $status = null; |
| 63 | $info = ''; |
| 64 | $hct = $this->getHtaccessCapabilityTester(); |
| 65 | |
| 66 | // If we can find anything that works, well the .htaccess must have been proccesed! |
| 67 | if ($hct->serverSignatureWorks() // Override: None, Status: Core, REQUIRES PHP |
| 68 | || $hct->contentDigestWorks() // Override: Options, Status: Core |
| 69 | || $hct->addTypeWorks() // Override: FileInfo, Status: Base, Module: mime |
| 70 | || $hct->directoryIndexWorks() // Override: Indexes, Status: Base, Module: mod_dir |
| 71 | || $hct->rewriteWorks() // Override: FileInfo, Status: Extension, Module: rewrite |
| 72 | || $hct->headerSetWorks() // Override: FileInfo, Status: Extension, Module: headers |
| 73 | ) { |
| 74 | $status = true; |
| 75 | } else { |
| 76 | // The serverSignatureWorks() test is special because if it comes out as a failure, |
| 77 | // we can be *almost* certain that the .htaccess has been completely disabled |
| 78 | |
| 79 | $serverSignatureWorks = $hct->serverSignatureWorks(); |
| 80 | if ($serverSignatureWorks === false) { |
| 81 | $status = false; |
| 82 | $info = 'ServerSignature directive does not work - and it is in core'; |
| 83 | } else { |
| 84 | // Last bullet in the gun: |
| 85 | // Try an .htaccess with syntax errors in it. |
| 86 | // (we do this lastly because it may generate an entry in the error log) |
| 87 | $crashTestResult = $hct->crashTest('aoeu', 'htaccess-enabled-malformed-htaccess'); |
| 88 | if (is_null($crashTestResult)) { |
| 89 | // Two scenarios: |
| 90 | // 1: All requests fails (without response code) |
| 91 | // 2: The crash test could not figure it out (ie if even innocent requests crashes) |
| 92 | $status = null; |
| 93 | $info = 'all requests fails (even innocent ones)'; |
| 94 | } elseif ($crashTestResult === false) { |
| 95 | // It crashed, - which means .htaccess is processed! |
| 96 | $status = true; |
| 97 | $info = 'syntax error in an .htaccess causes crash'; |
| 98 | } else { |
| 99 | // It did not crash. So the .htaccess is not processed, as syntax errors |
| 100 | // makes servers crash |
| 101 | $status = false; |
| 102 | $info = 'syntax error in an .htaccess does not cause crash'; |
| 103 | } |
| 104 | } |
| 105 | } |
| 106 | return new TestResult($status, $info); |
| 107 | } |
| 108 | } |