You are here

protected function FileSystemTest::assertFilePermissions in Drupal 9

Same name and namespace in other branches
  1. 8 core/tests/Drupal/Tests/Core/File/FileSystemTest.php \Drupal\Tests\Core\File\FileSystemTest::assertFilePermissions()
  2. 10 core/tests/Drupal/Tests/Core/File/FileSystemTest.php \Drupal\Tests\Core\File\FileSystemTest::assertFilePermissions()

Asserts that the file permissions of a given URI matches.

Parameters

int $expected_mode:

string $uri:

string $message:

2 calls to FileSystemTest::assertFilePermissions()
FileSystemTest::testChmodDir in core/tests/Drupal/Tests/Core/File/FileSystemTest.php
@covers ::chmod
FileSystemTest::testChmodFile in core/tests/Drupal/Tests/Core/File/FileSystemTest.php
@covers ::chmod

File

core/tests/Drupal/Tests/Core/File/FileSystemTest.php, line 139

Class

FileSystemTest
@coversDefaultClass \Drupal\Core\File\FileSystem

Namespace

Drupal\Tests\Core\File

Code

protected function assertFilePermissions($expected_mode, $uri, $message = '') {

  // Mask out all but the last three octets.
  $actual_mode = fileperms($uri) & 0777;

  // PHP on Windows has limited support for file permissions. Usually each of
  // "user", "group" and "other" use one octal digit (3 bits) to represent the
  // read/write/execute bits. On Windows, chmod() ignores the "group" and
  // "other" bits, and fileperms() returns the "user" bits in all three
  // positions. $expected_mode is updated to reflect this.
  if (substr(PHP_OS, 0, 3) == 'WIN') {

    // Reset the "group" and "other" bits.
    $expected_mode = $expected_mode & 0700;

    // Shift the "user" bits to the "group" and "other" positions also.
    $expected_mode = $expected_mode | $expected_mode >> 3 | $expected_mode >> 6;
  }
  $this
    ->assertSame($expected_mode, $actual_mode, $message);
}