function EntityDefinitionUpdateTest::testEntityIndexCreateWithData

Same name and namespace in other branches
  1. 9 core/tests/Drupal/KernelTests/Core/Entity/EntityDefinitionUpdateTest.php \Drupal\KernelTests\Core\Entity\EntityDefinitionUpdateTest::testEntityIndexCreateWithData()
  2. 8.9.x core/tests/Drupal/KernelTests/Core/Entity/EntityDefinitionUpdateTest.php \Drupal\KernelTests\Core\Entity\EntityDefinitionUpdateTest::testEntityIndexCreateWithData()

Tests creating a multi-field index when there are existing entities.

File

core/tests/Drupal/KernelTests/Core/Entity/EntityDefinitionUpdateTest.php, line 712

Class

EntityDefinitionUpdateTest
Tests EntityDefinitionUpdateManager functionality.

Namespace

Drupal\KernelTests\Core\Entity

Code

public function testEntityIndexCreateWithData() : void {
  // Save an entity.
  $name = $this->randomString();
  $entity = $this->entityTypeManager
    ->getStorage('entity_test_update')
    ->create([
    'name' => $name,
  ]);
  $entity->save();
  // Add an entity index, run the update. Ensure that the index is created
  // despite having data.
  $this->addEntityIndex();
  $entity_type = \Drupal::entityTypeManager()->getDefinition('entity_test_update');
  $original = \Drupal::service('entity.last_installed_schema.repository')->getLastInstalledDefinition('entity_test_update');
  \Drupal::service('entity_type.listener')->onEntityTypeUpdate($entity_type, $original);
  $this->assertTrue($this->database
    ->schema()
    ->indexExists('entity_test_update', 'entity_test_update__new_index'), 'Index added.');
}

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