function MoveTest::testExistingError

Test that moving onto an existing file fails when FILE_EXISTS_ERROR is specified.

File

drupal/core/modules/file/lib/Drupal/file/Tests/MoveTest.php, line 145
Definition of Drupal\file\Tests\MoveTest.

Class

MoveTest
Move related tests

Namespace

Drupal\file\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_move(clone $source, $target->uri, FILE_EXISTS_ERROR);

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

  // Check that no hooks were called while failing.
  $this
    ->assertFileHooksCalled(array());

  // Load the file from the database and make sure it is identical to what
  // was returned.
  $this
    ->assertFileUnchanged($source, file_load($source->fid, TRUE));
  $this
    ->assertFileUnchanged($target, file_load($target->fid, TRUE));
}