You are here

function FileMoveTest::testNormal in SimpleTest 7

Move a normal file.

File

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

Class

FileMoveTest
Move related tests

Code

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

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

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

  // Check that the correct hooks were called.
  $this
    ->assertFileHooksCalled(array(
    'move',
    'update',
  ));

  // Make sure we got the same file back.
  $this
    ->assertEqual($source->fid, $result->fid, t("Source file id's' %fid is unchanged after move.", array(
    '%fid' => $source->fid,
  )));

  // Reload the file from the database and check that the changes were
  // actually saved.
  $loaded_file = file_load($result->fid, TRUE);
  $this
    ->assertTrue($loaded_file, t('File can be loaded from the database.'));
  $this
    ->assertFileUnchanged($result, $loaded_file);
}