You are here

protected function MigrateMediaTestBase::assertEntities in Media Migration 8

Asserts that the expected entities exist.

1 call to MigrateMediaTestBase::assertEntities()
MigrateMediaTestBase::assertMediaMigrationResults in tests/src/Functional/MigrateMediaTestBase.php
Checks that migrations have been performed successfully.

File

tests/src/Functional/MigrateMediaTestBase.php, line 560

Class

MigrateMediaTestBase
Provides a base class for testing media migration via the UI.

Namespace

Drupal\Tests\media_migration\Functional

Code

protected function assertEntities() {
  foreach ($this
    ->getExpectedEntities() as $entity_type_id => $expected_entity_labels) {
    if ($storage = $this
      ->getEntityStorage($entity_type_id)) {
      $ignored_entities = $this
        ->getIgnoredEntities()[$entity_type_id] ?? [];
      $entities = $storage
        ->loadMultiple();
      $actual_labels = array_reduce($entities, function ($carry, EntityInterface $entity) use ($ignored_entities) {
        $label = $entity
          ->label();
        $id = $entity
          ->id();
        if (empty($ignored_entities) || array_search($label, $ignored_entities) === FALSE && array_search($id, $ignored_entities) === FALSE) {
          $carry[$id] = $label;
        }
        return $carry;
      });
      $this
        ->assertEquals($expected_entity_labels, $actual_labels, sprintf('The expected %s entities are not matching the actual ones.', $entity_type_id));
    }
    else {
      $this
        ->fail(sprintf('The expected %s entity type is missing.', $entity_type_id));
    }
  }
}