FileSaveHtaccessLoggingTest.php in Drupal 10
File
core/modules/system/tests/src/Functional/File/FileSaveHtaccessLoggingTest.php
View source
<?php
namespace Drupal\Tests\system\Functional\File;
use Drupal\Component\FileSecurity\FileSecurity;
use Drupal\Tests\BrowserTestBase;
class FileSaveHtaccessLoggingTest extends BrowserTestBase {
protected static $modules = [
'dblog',
];
protected $defaultTheme = 'stark';
public function testHtaccessSave() {
$private = $this->publicFilesDirectory . '/test/private';
$htaccess = \Drupal::service('file.htaccess_writer');
$this
->assertFalse($htaccess
->write($private, TRUE));
$this
->drupalLogin($this->rootUser);
$this
->drupalGet('admin/reports/dblog');
$this
->clickLink("Security warning: Couldn't write .htaccess file. Please…");
$lines = FileSecurity::htaccessLines(TRUE);
foreach (array_filter(explode("\n", $lines)) as $line) {
$this
->assertSession()
->assertEscaped($line);
}
}
}