You are here

protected function FieldableEntityDefinitionUpdateTest::assertEntityData in Drupal 9

Same name and namespace in other branches
  1. 8 core/tests/Drupal/KernelTests/Core/Entity/FieldableEntityDefinitionUpdateTest.php \Drupal\KernelTests\Core\Entity\FieldableEntityDefinitionUpdateTest::assertEntityData()
  2. 10 core/tests/Drupal/KernelTests/Core/Entity/FieldableEntityDefinitionUpdateTest.php \Drupal\KernelTests\Core\Entity\FieldableEntityDefinitionUpdateTest::assertEntityData()

Asserts test entity data after a fieldable entity type update.

Parameters

bool $revisionable: Whether the entity type was revisionable prior to the update.

bool $translatable: Whether the entity type was translatable prior to the update.

1 call to FieldableEntityDefinitionUpdateTest::assertEntityData()
FieldableEntityDefinitionUpdateTest::testFieldableEntityTypeUpdates in core/tests/Drupal/KernelTests/Core/Entity/FieldableEntityDefinitionUpdateTest.php
@covers ::updateFieldableEntityType @dataProvider providerTestFieldableEntityTypeUpdates

File

core/tests/Drupal/KernelTests/Core/Entity/FieldableEntityDefinitionUpdateTest.php, line 385

Class

FieldableEntityDefinitionUpdateTest
Tests EntityDefinitionUpdateManager's fieldable entity update functionality.

Namespace

Drupal\KernelTests\Core\Entity

Code

protected function assertEntityData($revisionable, $translatable) {
  $entities = $this->entityTypeManager
    ->getStorage($this->entityTypeId)
    ->loadMultiple();
  $this
    ->assertCount(3, $entities);
  foreach ($entities as $entity_id => $entity) {

    /** @var \Drupal\Core\Entity\ContentEntityInterface $entity */
    $this
      ->assertEquals("test entity - {$entity->id()} - en", $entity
      ->label());
    $this
      ->assertEquals("bundle field - {$entity->id()} - en", $entity->new_bundle_field->value);
    $this
      ->assertEquals("shared table - {$entity->id()} - value 1 - en", $entity->test_multiple_properties->value1);
    $this
      ->assertEquals("shared table - {$entity->id()} - value 2 - en", $entity->test_multiple_properties->value2);
    $this
      ->assertEquals("dedicated table - {$entity->id()} - delta 0 - value 1 - en", $entity->test_multiple_properties_multiple_values[0]->value1);
    $this
      ->assertEquals("dedicated table - {$entity->id()} - delta 0 - value 2 - en", $entity->test_multiple_properties_multiple_values[0]->value2);
    $this
      ->assertEquals("dedicated table - {$entity->id()} - delta 1 - value 1 - en", $entity->test_multiple_properties_multiple_values[1]->value1);
    $this
      ->assertEquals("dedicated table - {$entity->id()} - delta 1 - value 2 - en", $entity->test_multiple_properties_multiple_values[1]->value2);
    if ($translatable) {
      $translation = $entity
        ->getTranslation('ro');
      $this
        ->assertEquals("test entity - {$translation->id()} - ro", $translation
        ->label());
      $this
        ->assertEquals("bundle field - {$entity->id()} - ro", $translation->new_bundle_field->value);
      $this
        ->assertEquals("shared table - {$translation->id()} - value 1 - ro", $translation->test_multiple_properties->value1);
      $this
        ->assertEquals("shared table - {$translation->id()} - value 2 - ro", $translation->test_multiple_properties->value2);
      $this
        ->assertEquals("dedicated table - {$translation->id()} - delta 0 - value 1 - ro", $translation->test_multiple_properties_multiple_values[0]->value1);
      $this
        ->assertEquals("dedicated table - {$translation->id()} - delta 0 - value 2 - ro", $translation->test_multiple_properties_multiple_values[0]->value2);
      $this
        ->assertEquals("dedicated table - {$translation->id()} - delta 1 - value 1 - ro", $translation->test_multiple_properties_multiple_values[1]->value1);
      $this
        ->assertEquals("dedicated table - {$translation->id()} - delta 1 - value 2 - ro", $translation->test_multiple_properties_multiple_values[1]->value2);
    }
  }
  if ($revisionable) {
    $revisions_result = $this->entityTypeManager
      ->getStorage($this->entityTypeId)
      ->getQuery()
      ->accessCheck(FALSE)
      ->allRevisions()
      ->execute();
    $revisions = $this->entityTypeManager
      ->getStorage($this->entityTypeId)
      ->loadMultipleRevisions(array_keys($revisions_result));
    $this
      ->assertCount(6, $revisions);
    foreach ($revisions as $revision) {

      /** @var \Drupal\Core\Entity\ContentEntityInterface $revision */
      $revision_label = $revision
        ->isDefaultRevision() ? NULL : ' - rev2';
      $this
        ->assertEquals("test entity - {$revision->id()} - en{$revision_label}", $revision
        ->label());
      $this
        ->assertEquals("bundle field - {$revision->id()} - en{$revision_label}", $revision->new_bundle_field->value);
      $this
        ->assertEquals("shared table - {$revision->id()} - value 1 - en{$revision_label}", $revision->test_multiple_properties->value1);
      $this
        ->assertEquals("shared table - {$revision->id()} - value 2 - en{$revision_label}", $revision->test_multiple_properties->value2);
      $this
        ->assertEquals("dedicated table - {$revision->id()} - delta 0 - value 1 - en{$revision_label}", $revision->test_multiple_properties_multiple_values[0]->value1);
      $this
        ->assertEquals("dedicated table - {$revision->id()} - delta 0 - value 2 - en{$revision_label}", $revision->test_multiple_properties_multiple_values[0]->value2);
      $this
        ->assertEquals("dedicated table - {$revision->id()} - delta 1 - value 1 - en{$revision_label}", $revision->test_multiple_properties_multiple_values[1]->value1);
      $this
        ->assertEquals("dedicated table - {$revision->id()} - delta 1 - value 2 - en{$revision_label}", $revision->test_multiple_properties_multiple_values[1]->value2);
      if ($translatable) {
        $translation = $revision
          ->getTranslation('ro');
        $this
          ->assertEquals("test entity - {$translation->id()} - ro{$revision_label}", $translation
          ->label());
        $this
          ->assertEquals("bundle field - {$entity->id()} - ro{$revision_label}", $translation->new_bundle_field->value);
        $this
          ->assertEquals("shared table - {$revision->id()} - value 1 - ro{$revision_label}", $translation->test_multiple_properties->value1);
        $this
          ->assertEquals("shared table - {$revision->id()} - value 2 - ro{$revision_label}", $translation->test_multiple_properties->value2);
        $this
          ->assertEquals("dedicated table - {$translation->id()} - delta 0 - value 1 - ro{$revision_label}", $translation->test_multiple_properties_multiple_values[0]->value1);
        $this
          ->assertEquals("dedicated table - {$translation->id()} - delta 0 - value 2 - ro{$revision_label}", $translation->test_multiple_properties_multiple_values[0]->value2);
        $this
          ->assertEquals("dedicated table - {$translation->id()} - delta 1 - value 1 - ro{$revision_label}", $translation->test_multiple_properties_multiple_values[1]->value1);
        $this
          ->assertEquals("dedicated table - {$translation->id()} - delta 1 - value 2 - ro{$revision_label}", $translation->test_multiple_properties_multiple_values[1]->value2);
      }
    }
  }
}