You are here

protected function AssertFileUsageTrait::assertFileUsage in Helper 8

Assert file usage.

Parameters

int $expectedUsage: The expected usage count.

int $fid: The file ID to check for usage.

string $module: The module to check for usage.

\Drupal\Core\Entity\EntityInterface $entity: The attached entity to check for usage.

File

src/Tests/AssertFileUsageTrait.php, line 23

Class

AssertFileUsageTrait
Provides assertions for file usage.

Code

protected function assertFileUsage($expectedUsage, $fid, $module, EntityInterface $entity) {
  $file = File::load($fid);
  $usage = \Drupal::service('file.usage')
    ->listUsage($file);
  $usage = isset($usage[$module][$entity
    ->getEntityTypeId()][$entity
    ->id()]) ? $usage[$module][$entity
    ->getEntityTypeId()][$entity
    ->id()] : 0;
  $this
    ->assertEquals($expectedUsage, $usage);
}