PluginProbe
WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance / 3.2.5
WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance v3.2.5
4.7.0 4.6.1 4.6.0 4.5.5 4.5.4 4.5.3 4.5.2 3.2.20 3.2.21 3.2.22 3.2.3 3.2.5 3.2.6 3.2.7 3.2.9 3.3.0 3.3.1 3.3.2 3.4.0 3.4.1 3.4.2 3.5.0 3.6.0 3.7.0 3.7.1 All 111 releases
wp-optimize / vendor / rosell-dk / htaccess-capability-tester / src / Testers / CrashTester.php

CrashTester.php in WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance 3.2.5, at vendor/rosell-dk/htaccess-capability-tester/src/Testers/CrashTester.php

88 lines 3.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace HtaccessCapabilityTester\Testers;
4
5 use \HtaccessCapabilityTester\TestResult;
6
7 /**
8 * Class for testing if a .htaccess results in a 500 Internal Server Error
9 * (ie due to being malformed or containing directives that are unknown or not allowed)
10 *
11 * Notes:
12 * - The tester only reports failure on a 500 Internal Server Error. All other status codes (even server errors)
13 * are treated as a success. The assumption here is that malformed .htaccess files / .htaccess
14 * files containing unknown or disallowed directives always results in a 500
15 * - If your purpose is to test if a request succeeds (response 200 Ok), you should create your own class.
16 * (note that if you want to ensure that a php will succeed, make sure that a php is requested)
17 *
18 * @package HtaccessCapabilityTester
19 * @author Bjørn Rosell <[email protected]>
20 * @since Class available since 0.7
21 */
22 class CrashTester extends CustomTester
23 {
24
25 /**
26 * @param string $htaccessRules The rules to check
27 * @param string $subSubDir subdir for the test files. If not supplied, a fingerprint of the rules will be used
28 */
29 public function __construct($htaccessRules, $subSubDir = null)
30 {
31 if (is_null($subSubDir)) {
32 $subSubDir = hash('md5', $htaccessRules);
33 }
34
35 $test = [
36 'subdir' => 'crash-tester/' . $subSubDir,
37 'subtests' => [
38 [
39 'subdir' => 'the-suspect',
40 'files' => [
41 ['.htaccess', $htaccessRules],
42 ['request-me.txt', 'thanks'],
43 ],
44 'request' => [
45 'url' => 'request-me.txt',
46 'bypass-standard-error-handling' => ['403', '404', '500']
47 ],
48 'interpretation' => [
49 ['success', 'status-code', 'not-equals', '500'],
50 // Otherwise fall through to next subtest
51 ]
52 ],
53 [
54 'subdir' => 'the-innocent',
55 'files' => [
56 ['.htaccess', '# I am no trouble'],
57 ['request-me.txt', 'thanks'],
58 ],
59 'request' => [
60 'url' => 'request-me.txt',
61 'bypass-standard-error-handling' => ['403', '404', '500']
62 ],
63 'interpretation' => [
64 // The suspect crashed. But if the innocent crashes too, we cannot judge
65 ['inconclusive', 'status-code', 'equals', '500'],
66
67 // The innocent did not crash. The suspect is guilty!
68 ['failure'],
69 ]
70 ],
71 ]
72 ];
73
74 parent::__construct($test);
75 }
76
77 /**
78 * Child classes must implement this method, which tells which subdir the
79 * test files are to be put.
80 *
81 * @return string A subdir for the test files
82 */
83 public function getSubDir()
84 {
85 return 'crash-tester';
86 }
87 }
88