You are here

function FileCopyTest::testNormal in SimpleTest 7

Test file copying in the normal, base case.

File

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

Class

FileCopyTest
Copy related tests.

Code

function testNormal() {
  $contents = $this
    ->randomName(10);
  $source = $this
    ->createFile(NULL, $contents);
  $desired_uri = 'public://' . $this
    ->randomName();

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

  // Check the return status and that the contents changed.
  $this
    ->assertTrue($result, t('File copied sucessfully.'));
  $this
    ->assertEqual($contents, file_get_contents($result->uri), t('Contents of file were copied correctly.'));

  // Check that the correct hooks were called.
  $this
    ->assertFileHooksCalled(array(
    'copy',
    'insert',
  ));
  $this
    ->assertDifferentFile($source, $result);
  $this
    ->assertEqual($result->uri, $desired_uri, t('The copied file object has the desired filepath.'));
  $this
    ->assertTrue(file_exists($source->uri), t('The original file still exists.'));
  $this
    ->assertTrue(file_exists($result->uri), t('The copied file exists.'));

  // Reload the file from the database and check that the changes were
  // actually saved.
  $this
    ->assertFileUnchanged($result, file_load($result->fid, TRUE));
}