You are here

public function FileSecurityTest::testWriteHtaccessForceOverwrite in Drupal 9

Same name and namespace in other branches
  1. 8 core/tests/Drupal/Tests/Component/FileSecurity/FileSecurityTest.php \Drupal\Tests\Component\FileSecurity\FileSecurityTest::testWriteHtaccessForceOverwrite()

@covers ::writeHtaccess

File

core/tests/Drupal/Tests/Component/FileSecurity/FileSecurityTest.php, line 46

Class

FileSecurityTest
Tests the file security component.

Namespace

Drupal\Tests\Component\FileSecurity

Code

public function testWriteHtaccessForceOverwrite() {
  vfsStream::setup('root');
  $htaccess_file = vfsStream::url('root') . '/.htaccess';
  file_put_contents($htaccess_file, "foo");
  $this
    ->assertTrue(FileSecurity::writeHtaccess(vfsStream::url('root'), TRUE, TRUE));
  $htaccess_contents = file_get_contents($htaccess_file);
  $this
    ->assertStringContainsString("Require all denied", $htaccess_contents);
  $this
    ->assertStringNotContainsString("foo", $htaccess_contents);
}