FileUsageTest::testGetUsage

  1. drupal
    1. 8
    2. 7
Versions
7 FileUsageTest::testGetUsage()

Tests file_usage_list().

Code

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

<?php
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, t('Returned the correct number of items.'));
  $this->assertTrue(isset($usage['testing']['foo'][1]), t('Returned the correct id.'));
  $this->assertTrue(isset($usage['testing']['bar'][2]), t('Returned the correct id.'));
  $this->assertEqual($usage['testing']['foo'][1], 1, t('Returned the correct count.'));
  $this->assertEqual($usage['testing']['bar'][2], 2, t('Returned the correct count.'));
}
?>