function FileUsageTest::testGetUsage

Tests file_usage_list().

File

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

Class

FileUsageTest
Tests file usage functions.

Code

function testGetUsage() {
    $file = $this->createFile();
    db_insert('file_usage')->fields(array(
        'fid' => $file->fid,
        'module' => 'testing',
        'type' => 'foo',
        'id' => 1,
        'count' => 1,
    ))
        ->execute();
    db_insert('file_usage')->fields(array(
        'fid' => $file->fid,
        'module' => 'testing',
        'type' => 'bar',
        'id' => 2,
        'count' => 2,
    ))
        ->execute();
    $usage = file_usage_list($file);
    $this->assertEqual(count($usage['testing']), 2, 'Returned the correct number of items.');
    $this->assertTrue(isset($usage['testing']['foo'][1]), 'Returned the correct id.');
    $this->assertTrue(isset($usage['testing']['bar'][2]), 'Returned the correct id.');
    $this->assertEqual($usage['testing']['foo'][1], 1, 'Returned the correct count.');
    $this->assertEqual($usage['testing']['bar'][2], 2, 'Returned the correct count.');
}

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