You are here

function BackupMigrateUnitTest::testFileReadableRemotely in Backup and Migrate 5

File

tests/BackupMigrateUnitTest.test, line 55

Class

BackupMigrateUnitTest
Unit tests for Backup and Migrate module.

Code

function testFileReadableRemotely() {
  $filename = $this
    ->randomName(5, 'readtest_') . ".txt";
  $filepath = file_directory_path() . '/' . $filename;
  $contents = $this
    ->randomName(5, 'contents_');

  // public file access:
  $this
    ->drupalVariableSet('file_downloads', FILE_DOWNLOADS_PUBLIC);
  $this
    ->assertFalse(_backup_migrate_test_file_readable_remotely($filename, $contents), t('Checking false on non existant file read'));
  if (($fp = @fopen($filepath, 'w')) && @fputs($fp, $contents)) {
    fclose($fp);
  }
  else {
    $this
      ->assertTrue(false, t('Need to be able to write to a file in files to complete this test'));
  }
  $this
    ->assertTrue(_backup_migrate_test_file_readable_remotely($filename, $contents), t('Checking readable file'));
  unlink(realpath($filepath));
}