protected function MigrateUiParagraphsTestBase::assertEntities

Asserts that the expected entities exist.

1 call to MigrateUiParagraphsTestBase::assertEntities()
MigrateUiParagraphsTestBase::assertParagraphsMigrationResults in paragraphs/tests/src/Functional/Migrate/MigrateUiParagraphsTestBase.php
Checks that migrations have been performed successfully.

File

paragraphs/tests/src/Functional/Migrate/MigrateUiParagraphsTestBase.php, line 510

Class

MigrateUiParagraphsTestBase
Provides a base class for testing Paragraphs migration via the UI.

Namespace

Drupal\Tests\paragraphs\Functional\Migrate

Code

protected function assertEntities() {
  foreach ($this
    ->getExpectedEntities() as $entity_type_id => $expected_entity_labels) {
    if ($storage = $this
      ->getEntityStorage($entity_type_id)) {
      $entities = $storage
        ->loadMultiple();
      $actual_labels = array_reduce($entities, function ($carry, EntityInterface $entity) {
        $carry[$entity
          ->id()] = (string) $entity
          ->label();
        return $carry;
      });
      if (\Drupal::database()
        ->driver() === 'pgsql') {

        // On PostgreSQL the entity IDs are not the same so only compare the
        // labels to ensure we've migrated the expected number of entities.
        $this
          ->assertEqualsCanonicalizing($expected_entity_labels, $actual_labels, sprintf('The expected %s entities are not matching the actual ones.', $entity_type_id));
      }
      else {
        $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));
    }
  }
}