You are here

public function MigrateEckTestBase::assertEck in Entity Construction Kit (ECK) 8

Asserts an Eck entity.

Parameters

array $eck: An array of eck information.

  • id: The entity id.
  • label: The entity label.
  • langcode: The entity language code.
  • fields: An array of field names and field values.
1 call to MigrateEckTestBase::assertEck()
MigrateEckTest::testEck in tests/src/Kernel/Migrate/d7/MigrateEckTest.php
Tests migrating Eck entity types.

File

tests/src/Kernel/Migrate/d7/MigrateEckTestBase.php, line 94

Class

MigrateEckTestBase
Base class for ECK migration tests.

Namespace

Drupal\Tests\eck\Kernel\Migrate\d7

Code

public function assertEck(array $eck) {
  $message = "Failure for eck entity type '" . $eck['type'] . "' with id of '" . $eck['id'] . "'";

  /** @var \Drupal\Core\Entity\ContentEntityInterface $entity */
  $entity = $this->entityTypeManager
    ->getStorage($eck['type'])
    ->load($eck['id']);
  $this
    ->assertInstanceOf(EckEntity::class, $entity, $message);
  $this
    ->assertSame($eck['label'], $entity
    ->label(), $message);
  $this
    ->assertSame($eck['bundle'], $entity
    ->bundle(), $message);
  $this
    ->assertSame($eck['langcode'], $entity
    ->language()
    ->getId(), $message);
  foreach ($eck['fields'] as $name => $value) {
    $this
      ->assertSame($value, $entity
      ->get($name)
      ->getValue(), $message);
  }

  // Verify translations.
  if (!empty($eck['translations'])) {
    foreach ($eck['translations'] as $language => $translation_data) {
      $this
        ->assertTrue($entity
        ->hasTranslation($language));
      $translation = $entity
        ->getTranslation($language);
      foreach ($translation_data['fields'] as $name => $value) {
        $this
          ->assertSame($value, $translation
          ->get($name)
          ->getValue(), $message);
      }
    }
  }
}