You are here

public function HtaccessTest::testHtaccessSave in Drupal 8

Same name and namespace in other branches
  1. 9 core/tests/Drupal/KernelTests/Core/File/HtaccessTest.php \Drupal\KernelTests\Core\File\HtaccessTest::testHtaccessSave()
  2. 10 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 48

Class

HtaccessTest
Tests .htaccess file saving.

Namespace

Drupal\KernelTests\Core\File

Code

public function testHtaccessSave() {

  // 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));
}