FileSaveDataTest::testExistingError

7 file.test FileSaveDataTest::testExistingError()
8 file.test FileSaveDataTest::testExistingError()

Test that file_save_data() fails overwriting an existing file.

File

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

Code

function testExistingError() {
  $contents = $this->randomName(8);
  $existing = $this->createFile(NULL, $contents);

  // Check the overwrite error.
  $result = file_save_data('asdf', $existing->uri, FILE_EXISTS_ERROR);
  $this->assertFalse($result, t('Overwriting a file fails when FILE_EXISTS_ERROR is specified.'));
  $this->assertEqual($contents, file_get_contents($existing->uri), t('Contents of existing file were unchanged.'));

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

  // Ensure that the existing file wasn't overwritten.
  $this->assertFileUnchanged($existing, file_load($existing->fid, TRUE));
}
Login or register to post comments