You are here

function MoveTest::testExistingReplaceSelf in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 core/modules/file/src/Tests/MoveTest.php \Drupal\file\Tests\MoveTest::testExistingReplaceSelf()

Test replacement when moving onto itself.

File

core/modules/file/src/Tests/MoveTest.php, line 118
Contains \Drupal\file\Tests\MoveTest.

Class

MoveTest
Tests the file move function.

Namespace

Drupal\file\Tests

Code

function testExistingReplaceSelf() {

  // Setup a file to overwrite.
  $contents = $this
    ->randomMachineName(10);
  $source = $this
    ->createFile(NULL, $contents);

  // Copy the file over itself. Clone the object so we don't have to worry
  // about the function changing our reference copy.
  $result = file_move(clone $source, $source
    ->getFileUri(), FILE_EXISTS_REPLACE);
  $this
    ->assertFalse($result, 'File move failed.');
  $this
    ->assertEqual($contents, file_get_contents($source
    ->getFileUri()), '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
    ->id()));
}