You are here

protected function FieldableEntityDefinitionUpdateTest::assertRevisionable in Drupal 10

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

Asserts the revisionable characteristics of an entity type.

@internal

2 calls to FieldableEntityDefinitionUpdateTest::assertRevisionable()
FieldableEntityDefinitionUpdateTest::assertEntityTypeSchema in core/tests/Drupal/KernelTests/Core/Entity/FieldableEntityDefinitionUpdateTest.php
Asserts revisionable and/or translatable characteristics of an entity type.
FieldableEntityDefinitionUpdateTest::assertRevisionableAndTranslatable in core/tests/Drupal/KernelTests/Core/Entity/FieldableEntityDefinitionUpdateTest.php
Asserts the revisionable / translatable characteristics of an entity type.

File

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

Class

FieldableEntityDefinitionUpdateTest
Tests EntityDefinitionUpdateManager's fieldable entity update functionality.

Namespace

Drupal\KernelTests\Core\Entity

Code

protected function assertRevisionable() : void {

  /** @var \Drupal\Core\Entity\ContentEntityTypeInterface $entity_type */
  $entity_type = $this->entityDefinitionUpdateManager
    ->getEntityType($this->entityTypeId);
  $this
    ->assertTrue($entity_type
    ->isRevisionable());

  // Check that the required field definitions of a revisionable entity type
  // exists and are stored in the correct tables.
  $revision_key = $entity_type
    ->getKey('revision');
  $revision_default_key = $entity_type
    ->getRevisionMetadataKey('revision_default');
  $revision_field = $this->entityDefinitionUpdateManager
    ->getFieldStorageDefinition($revision_key, $entity_type
    ->id());
  $revision_default_field = $this->entityDefinitionUpdateManager
    ->getFieldStorageDefinition($revision_default_key, $entity_type
    ->id());
  $this
    ->assertNotNull($revision_field);
  $this
    ->assertNotNull($revision_default_field);
  $database_schema = $this->database
    ->schema();
  $base_table = $entity_type
    ->getBaseTable();
  $revision_table = $entity_type
    ->getRevisionTable();
  $this
    ->assertTrue($database_schema
    ->tableExists($revision_table));
  $this
    ->assertTrue($database_schema
    ->fieldExists($base_table, $revision_key));
  $this
    ->assertTrue($database_schema
    ->fieldExists($revision_table, $revision_key));
  $this
    ->assertFalse($database_schema
    ->fieldExists($base_table, $revision_default_key));
  $this
    ->assertTrue($database_schema
    ->fieldExists($revision_table, $revision_default_key));

  // Also check the revision metadata keys, if they exist.
  foreach ([
    'revision_log_message',
    'revision_user',
    'revision_created',
  ] as $key) {
    if ($revision_metadata_key = $entity_type
      ->getRevisionMetadataKey($key)) {
      $revision_metadata_field = $this->entityDefinitionUpdateManager
        ->getFieldStorageDefinition($revision_metadata_key, $entity_type
        ->id());
      $this
        ->assertNotNull($revision_metadata_field);
      $this
        ->assertFalse($database_schema
        ->fieldExists($base_table, $revision_metadata_key));
      $this
        ->assertTrue($database_schema
        ->fieldExists($revision_table, $revision_metadata_key));
    }
  }
}