You are here

function CopyTest::testExistingError in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/file/src/Tests/CopyTest.php \Drupal\file\Tests\CopyTest::testExistingError()

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

File

core/modules/file/src/Tests/CopyTest.php, line 129
Contains \Drupal\file\Tests\CopyTest.

Class

CopyTest
Tests the file copy function.

Namespace

Drupal\file\Tests

Code

function testExistingError() {
  $contents = $this
    ->randomMachineName(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
    ->getFileUri(), FILE_EXISTS_ERROR);

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

  // Check that the correct hooks were called.
  $this
    ->assertFileHooksCalled(array());
  $this
    ->assertFileUnchanged($source, File::load($source
    ->id()));
  $this
    ->assertFileUnchanged($target, File::load($target
    ->id()));
}