FileDeleteTest::testInUse

7 file.test FileDeleteTest::testInUse()
8 file.test FileDeleteTest::testInUse()

Tries deleting a file that is in use.

File

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

Code

function testInUse() {
  $file = $this->createFile();
  file_usage_add($file, 'testing', 'test', 1);
  file_usage_add($file, 'testing', 'test', 1);

  file_usage_delete($file, 'testing', 'test', 1);
  file_delete($file);
  $usage = file_usage_list($file);
  $this->assertEqual($usage['testing']['test'], array(1 => 1), t('Test file is still in use.'));
  $this->assertTrue(file_exists($file->uri), t('File still exists on the disk.'));
  $this->assertTrue(file_load($file->fid), t('File still exists in the database.'));

  // Clear out the call to hook_file_load().
  file_test_reset();

  file_usage_delete($file, 'testing', 'test', 1);
  file_delete($file);
  $usage = file_usage_list($file);
  $this->assertFileHooksCalled(array('delete'));
  $this->assertTrue(empty($usage), t('File usage data was removed.'));
  $this->assertFalse(file_exists($file->uri), t('File has been deleted after its last usage was removed.'));
  $this->assertFalse(file_load($file->fid), t('File was removed from the database.'));
}
Login or register to post comments