function FileDeleteTest::testInUse

Tries deleting a file that is in use.

File

modules/simpletest/tests/file.test, line 1766

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.');
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.