
| Current Path : /var/www/html1/web/core/modules/system/tests/src/Functional/File/ |
Linux ift1.ift-informatik.de 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64 |
| Current File : /var/www/html1/web/core/modules/system/tests/src/Functional/File/FileSaveHtaccessLoggingTest.php |
<?php
namespace Drupal\Tests\system\Functional\File;
use Drupal\Component\FileSecurity\FileSecurity;
use Drupal\Tests\BrowserTestBase;
/**
* Tests the log message added by file_save_htaccess().
*
* @group File
*/
class FileSaveHtaccessLoggingTest extends BrowserTestBase {
protected static $modules = ['dblog'];
/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';
/**
* Tests file_save_htaccess().
*/
public function testHtaccessSave() {
// Prepare test directories.
$private = $this->publicFilesDirectory . '/test/private';
// Verify that file_save_htaccess() returns FALSE if .htaccess cannot be
// written and writes a correctly formatted message to the error log. Set
// $private to TRUE so all possible .htaccess lines are written.
/** @var \Drupal\Core\File\HtaccessWriterInterface $htaccess */
$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);
}
}
}