You are here

function FileUsageTest::testGetUsage in MongoDB 8

Tests file_usage()->listUsage().

File

src/Tests/FileUsageTest.php, line 36
Definition of Drupal\mongodb\Tests\FileUsageTest.

Class

FileUsageTest
Tests file usage functions.

Namespace

Drupal\mongodb\Tests

Code

function testGetUsage() {
  $file = $this
    ->createFile();
  $database = \Drupal::service('mongo');
  $database
    ->get('file_usage')
    ->insert(array(
    'fid' => (int) $file
      ->id(),
    'module' => 'testing',
    'type' => 'foo',
    'id' => 1,
    'count' => 1,
  ));
  $database
    ->get('file_usage')
    ->insert(array(
    'fid' => (int) $file
      ->id(),
    'module' => 'testing',
    'type' => 'bar',
    'id' => 2,
    'count' => 2,
  ));
  $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.'));
}