You are here

function UnmanagedMoveTest::testOverwriteSelf in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 core/modules/system/src/Tests/File/UnmanagedMoveTest.php \Drupal\system\Tests\File\UnmanagedMoveTest::testOverwriteSelf()

Try to move a file onto itself.

File

core/modules/system/src/Tests/File/UnmanagedMoveTest.php, line 62
Contains \Drupal\system\Tests\File\UnmanagedMoveTest.

Class

UnmanagedMoveTest
Tests the unmanaged file move function.

Namespace

Drupal\system\Tests\File

Code

function testOverwriteSelf() {

  // Create a file for testing.
  $uri = $this
    ->createUri();

  // Move the file onto itself without renaming shouldn't make changes.
  $new_filepath = file_unmanaged_move($uri, $uri, FILE_EXISTS_REPLACE);
  $this
    ->assertFalse($new_filepath, 'Moving onto itself without renaming fails.');
  $this
    ->assertTrue(file_exists($uri), 'File exists after moving onto itself.');

  // Move the file onto itself with renaming will result in a new filename.
  $new_filepath = file_unmanaged_move($uri, $uri, FILE_EXISTS_RENAME);
  $this
    ->assertTrue($new_filepath, 'Moving onto itself with renaming works.');
  $this
    ->assertFalse(file_exists($uri), 'Original file has been removed.');
  $this
    ->assertTrue(file_exists($new_filepath), 'File exists after moving onto itself.');
}