You are here

function FileCopyTest::testExistingError in SimpleTest 7

Test that copying over an existing file fails when FILE_EXISTS_ERROR is specified.

File

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

Class

FileCopyTest
Copy related tests.

Code

function testExistingError() {
  $contents = $this
    ->randomName(10);
  $source = $this
    ->createFile();
  $target = $this
    ->createFile(NULL, $contents);
  $this
    ->assertDifferentFile($source, $target);

  // Clone the object so we don't have to worry about the function changing
  // our reference copy.
  $result = file_copy(clone $source, $target->uri, FILE_EXISTS_ERROR);

  // Check the return status and that the contents were not changed.
  $this
    ->assertFalse($result, t('File copy failed.'));
  $this
    ->assertEqual($contents, file_get_contents($target->uri), t('Contents of file were not altered.'));

  // Check that the correct hooks were called.
  $this
    ->assertFileHooksCalled(array());
  $this
    ->assertFileUnchanged($source, file_load($source->fid, TRUE));
  $this
    ->assertFileUnchanged($target, file_load($target->fid, TRUE));
}