function EntityDefinitionUpdateMultipleTypesTest::testEntityTypeUpdateWithoutData

Tests updating entity schema when there are no existing entities.

File

core/tests/Drupal/KernelTests/Core/Entity/EntityDefinitionUpdateMultipleTypesTest.php, line 94

Class

EntityDefinitionUpdateMultipleTypesTest
Tests EntityDefinitionUpdateManager functionality.

Namespace

Drupal\KernelTests\Core\Entity

Code

public function testEntityTypeUpdateWithoutData() : void {
  // The 'entity_test_update' entity type starts out non-revisionable, so
  // ensure the revision table hasn't been created during setUp().
  $this->assertFalse($this->database
    ->schema()
    ->tableExists('entity_test_update_revision'), 'Revision table not created for entity_test_update.');
  // Update it to be revisionable and ensure the definition update manager
  // reports that an update is needed.
  $this->updateEntityTypeToRevisionable();
  $this->assertTrue($this->entityDefinitionUpdateManager
    ->needsUpdates(), 'EntityDefinitionUpdateManager reports that updates are needed.');
  $entity_type = $this->entityTypeManager
    ->getDefinition('entity_test_update')
    ->getLabel();
  $expected = [
    'entity_test_update' => [
      "The {$entity_type} entity type needs to be updated.",
      // The revision key is now defined, so the revision field needs to be
      // created.
'The Revision ID field needs to be installed.',
      'The Default revision field needs to be installed.',
    ],
  ];
  $this->assertEquals($expected, $this->entityDefinitionUpdateManager
    ->getChangeSummary(), 'EntityDefinitionUpdateManager reports the expected change summary.');
  // Run the update and ensure the revision table is created.
  $this->updateEntityTypeToRevisionable(TRUE);
  $this->assertTrue($this->database
    ->schema()
    ->tableExists('entity_test_update_revision'), 'Revision table created for entity_test_update.');
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.