function UsageTest::testGetUsage

Tests file_usage()->listUsage().

File

drupal/core/modules/file/lib/Drupal/file/Tests/UsageTest.php, line 25
Definition of Drupal\file\Tests\UsageTest.

Class

UsageTest
Tests file usage functions.

Namespace

Drupal\file\Tests

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