FileMoveTest::testExistingReplaceSelf

7 file.test FileMoveTest::testExistingReplaceSelf()
8 file.test FileMoveTest::testExistingReplaceSelf()

Test replacement when moving onto itself.

File

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

Code

function testExistingReplaceSelf() {
  // Setup a file to overwrite.
  $contents = $this->randomName(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->uri, FILE_EXISTS_REPLACE);
  $this->assertFalse($result, t('File move failed.'));
  $this->assertEqual($contents, file_get_contents($source->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));
}
Login or register to post comments