You are here

function FileDeleteTest::testInUse in Drupal 7

Tries deleting a file that is in use.

File

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

Class

FileDeleteTest
Deletion related tests.

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,
  ), 'Test file is still in use.');
  $this
    ->assertTrue(file_exists($file->uri), 'File still exists on the disk.');
  $this
    ->assertTrue(file_load($file->fid), '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), 'File usage data was removed.');
  $this
    ->assertFalse(file_exists($file->uri), 'File has been deleted after its last usage was removed.');
  $this
    ->assertFalse(file_load($file->fid), 'File was removed from the database.');
}