# Testing if we can pass environment variable from .htaccess to script in a RewriteRule # We pass document root, because that can easily be checked by the script RewriteEngine On RewriteRule ^test\.php$ - [E=PASSTHROUGHENV:%{DOCUMENT_ROOT},L] - filename: 'test.php' content: | $item) { if (substr($key, -$len) == $envName) { return $item; } } return false; } $result = getEnvPassedInRewriteRule('PASSTHROUGHENV'); if ($result === false) { echo '0'; exit; } echo ($result == $_SERVER['DOCUMENT_ROOT'] ? '1' : '0'); request: url: 'test.php' interpretation: - ['success', 'body', 'equals', '1'] - ['failure', 'body', 'equals', '0'] - ['inconclusive', 'body', 'begins-with', 'disableHtaccess(); $testResult = $fakeServer->runTester(new PassInfoFromRewriteToScriptThroughEnvTester()); $this->assertFailure($testResult); }*/ public function testDisallowedDirectivesFatal() { $fakeServer = new FakeServer(); $fakeServer->disallowAllDirectives('fatal'); $testResult = $fakeServer->runTester(new PassInfoFromRewriteToScriptThroughEnvTester()); $this->assertFailure($testResult); } public function testAccessAllDenied() { $fakeServer = new FakeServer(); $fakeServer->denyAllAccess(); $testResult = $fakeServer->runTester(new PassInfoFromRewriteToScriptThroughEnvTester()); $this->assertInconclusive($testResult); } /** * Test when the magic is not working * This could happen when: * - Any of the directives are forbidden (non-fatal) * - Any of the modules are not loaded * - Perhaps these advanced features are not working on all platforms * (does LiteSpeed ie support these this?) */ public function testMagicNotWorking() { $fakeServer = new FakeServer(); $fakeServer->setResponses([ '/pass-info-from-rewrite-to-script-through-env/test.php' => new HttpResponse('0', '200', []) ]); $testResult = $fakeServer->runTester(new PassInfoFromRewriteToScriptThroughEnvTester()); $this->assertFailure($testResult); } public function testPHPNotProcessed() { $fakeServer = new FakeServer(); $fakeServer->handlePHPasText(); $testResult = $fakeServer->runTester( new PassInfoFromRewriteToScriptThroughEnvTester() ); $this->assertInconclusive($testResult); } public function testSuccess() { $fakeServer = new FakeServer(); $fakeServer->setResponses([ '/pass-info-from-rewrite-to-script-through-env/test.php' => new HttpResponse('1', '200', []) ]); $testResult = $fakeServer->runTester( new PassInfoFromRewriteToScriptThroughEnvTester() ); $this->assertSuccess($testResult); } }