diff --git a/core/modules/system/lib/Drupal/system/Tests/File/HtaccessUnitTest.php b/core/modules/system/lib/Drupal/system/Tests/File/HtaccessUnitTest.php index e98097c..5f4b656 100644 --- a/core/modules/system/lib/Drupal/system/Tests/File/HtaccessUnitTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/File/HtaccessUnitTest.php @@ -7,19 +7,18 @@ namespace Drupal\system\Tests\File; +use Drupal\Component\Utility\String; use Drupal\simpletest\DrupalUnitTestBase; /** - * File system configuration related tests. - * - * @todo Use UnitTestBase after removing container dependency from error handler. + * .htaccess file saving tests. */ class HtaccessUnitTest extends DrupalUnitTestBase { public static function getInfo() { return array( - 'name' => '.htaccess file test', - 'description' => 'Tests .htaccess file saving', + 'name' => '.htaccess file saving', + 'description' => 'Tests .htaccess file saving.', 'group' => 'File API', ); } @@ -45,7 +44,7 @@ function testHtaccessSave() { $this->assertTrue(file_save_htaccess($public, FALSE)); $content = file_get_contents($public . '/.htaccess'); $this->assertIdentical($content, "SetHandler Drupal_Security_Do_Not_Remove_See_SA_2006_006\nOptions None\nOptions +FollowSymLinks"); - $this->assertIdentical(fileperms($public . '/.htaccess') & 0777, 0444); + $this->assertFilePermissions($public . '/.htaccess', 0444); $this->assertTrue(file_save_htaccess($public, FALSE)); @@ -54,7 +53,7 @@ function testHtaccessSave() { $this->assertTrue(file_save_htaccess($private)); $content = file_get_contents($private . '/.htaccess'); $this->assertIdentical($content, "SetHandler Drupal_Security_Do_Not_Remove_See_SA_2006_006\nDeny from all\nOptions None\nOptions +FollowSymLinks"); - $this->assertIdentical(fileperms($private . '/.htaccess') & 0777, 0444); + $this->assertFilePermissions($private . '/.htaccess', 0444); $this->assertTrue(file_save_htaccess($private)); @@ -63,9 +62,29 @@ function testHtaccessSave() { $this->assertTrue(file_save_htaccess($stream)); $content = file_get_contents($stream . '/.htaccess'); $this->assertIdentical($content, "SetHandler Drupal_Security_Do_Not_Remove_See_SA_2006_006\nDeny from all\nOptions None\nOptions +FollowSymLinks"); - $this->assertIdentical(fileperms($stream . '/.htaccess') & 0777, 0444); + $this->assertFilePermissions($stream . '/.htaccess', 0444); $this->assertTrue(file_save_htaccess($stream)); } + /** + * Asserts expected file permissions for a given file. + * + * @param string $uri + * The URI of the file to check. + * @param int $expected + * The expected file permissions; e.g., 0444. + * + * @return bool + * Whether the actual file permissions match the expected. + */ + protected function assertFilePermissions($uri, $expected) { + $actual = fileperms($uri) & 0777; + return $this->assertIdentical($actual, $expected, String::format('@uri file permissions @actual are identical to @expected.', array( + '@uri' => $uri, + '@actual' => 0 . decoct($actual), + '@expected' => 0 . decoct($expected), + ))); + } + }