You are here

protected function TaxonomyEntityIndexEntityTest::assertThatEntityUpdatesModifyTheIndex in Taxonomy Entity Index 8

Test that updates to entities modify the index.

Parameters

\Drupal\entity_test\Entity\EntityTest $entity: Entity to update.

\Drupal\taxonomy\TermInterface[] $terms: Terms to reference.

Return value

\Drupal\entity_test\Entity\EntityTest Test entity.

1 call to TaxonomyEntityIndexEntityTest::assertThatEntityUpdatesModifyTheIndex()
TaxonomyEntityIndexEntityTest::testWritingToIndexTable in tests/src/Kernel/TaxonomyEntityIndexEntityTest.php
Tests operations that insert/update/delete to the index table.

File

tests/src/Kernel/TaxonomyEntityIndexEntityTest.php, line 139

Class

TaxonomyEntityIndexEntityTest
Defines a class for testing basic functionality of taxonomy_entity_index.

Namespace

Drupal\Tests\taxonomy_entity_index\Kernel

Code

protected function assertThatEntityUpdatesModifyTheIndex(EntityTest $entity, array $terms) {
  $entity->termz = $terms;
  $entity
    ->save();
  $records = $this->database
    ->select('taxonomy_entity_index', 'tei')
    ->fields('tei')
    ->condition('entity_id', $entity
    ->id())
    ->condition('entity_type', $entity
    ->getEntityTypeId())
    ->execute()
    ->fetchAll();
  $this
    ->assertCount(count($terms), $records);
  $delta = 0;
  $this
    ->assertEquals(array_map(function (TermInterface $term) use ($entity, &$delta) {
    return (object) [
      'entity_type' => 'entity_test',
      'bundle' => 'termz',
      'entity_id' => $entity
        ->id(),
      'revision_id' => $entity
        ->id(),
      'field_name' => 'termz',
      'delta' => $delta++,
      'tid' => $term
        ->id(),
    ];
  }, $terms), $records);
  return $entity;
}