You are here

protected function TaxonomyEntityIndexEntityTest::assertThatTermDeletionUpdatesTheIndex in Taxonomy Entity Index 8

Assert that deleting a term deletes the item from the index.

Parameters

\Drupal\entity_test\Entity\EntityTest $entity: Test entity.

array $expected_terms: Expected terms.

array $terms_to_delete: Terms to delete.

1 call to TaxonomyEntityIndexEntityTest::assertThatTermDeletionUpdatesTheIndex()
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 177

Class

TaxonomyEntityIndexEntityTest
Defines a class for testing basic functionality of taxonomy_entity_index.

Namespace

Drupal\Tests\taxonomy_entity_index\Kernel

Code

protected function assertThatTermDeletionUpdatesTheIndex(EntityTest $entity, array $expected_terms, array $terms_to_delete) {
  foreach ($terms_to_delete as $term) {
    $term
      ->delete();
  }
  $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($expected_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(),
    ];
  }, $expected_terms), $records);
}