You are here

function UsageTest::testGetUsage in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 core/modules/file/src/Tests/UsageTest.php \Drupal\file\Tests\UsageTest::testGetUsage()

Tests \Drupal\file\FileUsage\DatabaseFileUsageBackend::listUsage().

File

core/modules/file/src/Tests/UsageTest.php, line 19
Contains \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
      ->id(),
    'module' => 'testing',
    'type' => 'foo',
    'id' => 1,
    'count' => 1,
  ))
    ->execute();
  db_insert('file_usage')
    ->fields(array(
    'fid' => $file
      ->id(),
    'module' => 'testing',
    'type' => 'bar',
    'id' => 2,
    'count' => 2,
  ))
    ->execute();
  $usage = $this->container
    ->get('file.usage')
    ->listUsage($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.');
}