function HtaccessTest::testHtaccessSave
Same name in other branches
- 9 core/tests/Drupal/KernelTests/Core/File/HtaccessTest.php \Drupal\KernelTests\Core\File\HtaccessTest::testHtaccessSave()
- 8.9.x core/tests/Drupal/KernelTests/Core/File/HtaccessTest.php \Drupal\KernelTests\Core\File\HtaccessTest::testHtaccessSave()
- 11.x core/tests/Drupal/KernelTests/Core/File/HtaccessTest.php \Drupal\KernelTests\Core\File\HtaccessTest::testHtaccessSave()
@covers ::write
File
-
core/
tests/ Drupal/ KernelTests/ Core/ File/ HtaccessTest.php, line 49
Class
- HtaccessTest
- Tests .htaccess file saving.
Namespace
Drupal\KernelTests\Core\FileCode
public function testHtaccessSave() : void {
// Prepare test directories.
$private = Settings::get('file_public_path') . '/test/private';
$stream = 'public://test/stream';
// Create public .htaccess file.
mkdir($this->public, 0777, TRUE);
$this->assertTrue($this->htaccessWriter
->write($this->public, FALSE));
$content = file_get_contents($this->public . '/.htaccess');
$this->assertStringContainsString("SetHandler Drupal_Security_Do_Not_Remove_See_SA_2006_006", $content);
$this->assertStringNotContainsString("Require all denied", $content);
$this->assertStringNotContainsString("Deny from all", $content);
$this->assertStringContainsString("Options -Indexes -ExecCGI -Includes -MultiViews", $content);
$this->assertStringContainsString("SetHandler Drupal_Security_Do_Not_Remove_See_SA_2013_003", $content);
$this->assertFilePermissions($this->public . '/.htaccess', 0444);
$this->assertTrue($this->htaccessWriter
->write($this->public, FALSE));
// Create private .htaccess file.
mkdir($private, 0777, TRUE);
$this->assertTrue($this->htaccessWriter
->write($private));
$content = file_get_contents($private . '/.htaccess');
$this->assertStringContainsString("SetHandler Drupal_Security_Do_Not_Remove_See_SA_2006_006", $content);
$this->assertStringContainsString("Require all denied", $content);
$this->assertStringContainsString("Deny from all", $content);
$this->assertStringContainsString("Options -Indexes -ExecCGI -Includes -MultiViews", $content);
$this->assertStringContainsString("SetHandler Drupal_Security_Do_Not_Remove_See_SA_2013_003", $content);
$this->assertFilePermissions($private . '/.htaccess', 0444);
$this->assertTrue($this->htaccessWriter
->write($private));
// Create an .htaccess file using a stream URI.
mkdir($stream, 0777, TRUE);
$this->assertTrue($this->htaccessWriter
->write($stream));
$content = file_get_contents($stream . '/.htaccess');
$this->assertStringContainsString("SetHandler Drupal_Security_Do_Not_Remove_See_SA_2006_006", $content);
$this->assertStringContainsString("Require all denied", $content);
$this->assertStringContainsString("Deny from all", $content);
$this->assertStringContainsString("Options -Indexes -ExecCGI -Includes -MultiViews", $content);
$this->assertStringContainsString("SetHandler Drupal_Security_Do_Not_Remove_See_SA_2013_003", $content);
$this->assertFilePermissions($stream . '/.htaccess', 0444);
$this->assertTrue($this->htaccessWriter
->write($stream));
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.