You are here

public function FileSecurityTest::testWriteHtaccessPrivate in Drupal 10

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

@covers ::writeHtaccess

File

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

Class

FileSecurityTest
Tests the file security component.

Namespace

Drupal\Tests\Component\FileSecurity

Code

public function testWriteHtaccessPrivate() {
  vfsStream::setup('root');
  FileSecurity::writeHtaccess(vfsStream::url('root'));
  $htaccess_file = vfsStream::url('root') . '/.htaccess';
  $this
    ->assertFileExists($htaccess_file);
  $this
    ->assertEquals('0444', substr(sprintf('%o', fileperms($htaccess_file)), -4));
  $htaccess_contents = file_get_contents($htaccess_file);
  $this
    ->assertStringContainsString("Require all denied", $htaccess_contents);
}