You are here

function FileUsageTest::testGetUsage in Drupal 7

Tests file_usage_list().

File

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

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