You are here

public function EntityDefinitionUpdateTest::testEntityIndexCreateWithData in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/system/src/Tests/Entity/EntityDefinitionUpdateTest.php \Drupal\system\Tests\Entity\EntityDefinitionUpdateTest::testEntityIndexCreateWithData()

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

File

core/modules/system/src/Tests/Entity/EntityDefinitionUpdateTest.php, line 530
Contains \Drupal\system\Tests\Entity\EntityDefinitionUpdateTest.

Class

EntityDefinitionUpdateTest
Tests EntityDefinitionUpdateManager functionality.

Namespace

Drupal\system\Tests\Entity

Code

public function testEntityIndexCreateWithData() {

  // Save an entity.
  $name = $this
    ->randomString();
  $entity = $this->entityManager
    ->getStorage('entity_test_update')
    ->create(array(
    'name' => $name,
  ));
  $entity
    ->save();

  // Add an entity index, run the update. Ensure that the index is created
  // despite having data.
  $this
    ->addEntityIndex();
  $this->entityDefinitionUpdateManager
    ->applyUpdates();
  $this
    ->assertTrue($this->database
    ->schema()
    ->indexExists('entity_test_update', 'entity_test_update__new_index'), 'Index added.');
}