You are here

function FileTestCase::assertFilePermissions in SimpleTest 7

Helper function to test the permissions of a file.

Parameters

$filepath: String file path.

$expected_mode: Octal integer like 0664 or 0777.

$message: Optional message.

4 calls to FileTestCase::assertFilePermissions()
FileUnmanagedCopyTest::testNormal in tests/file.test
Copy a normal file.
FileUnmanagedCopyTest::testOverwriteSelf in tests/file.test
Copy a file onto itself.
FileUnmanagedMoveTest::testNormal in tests/file.test
Move a normal file.
FileUnmanagedSaveDataTest::testFileSaveData in tests/file.test
Test the file_unmanaged_save_data() function.

File

tests/file.test, line 105
This provides SimpleTests for the core file handling functionality. These include FileValidateTest and FileSaveTest.

Class

FileTestCase
Base class for file tests that adds some additional file specific assertions and helper functions.

Code

function assertFilePermissions($filepath, $expected_mode, $message = NULL) {

  // Clear out PHP's file stat cache to be sure we see the current value.
  clearstatcache();

  // Mask out all but the last three octets.
  $actual_mode = fileperms($filepath) & 511;
  if (!isset($message)) {
    $message = t('Expected file permission to be %expected, actually were %actual.', array(
      '%actual' => decoct($actual_mode),
      '%expected' => decoct($expected_mode),
    ));
  }
  $this
    ->assertEqual($actual_mode, $expected_mode, $message);
}