Skip to content
Snippets Groups Projects

Ensure that entity_id is integer in taxonomy_entity_index_entity_delete() function

Files
2
@@ -3,6 +3,7 @@
namespace Drupal\Tests\taxonomy_entity_index\Kernel;
use Drupal\entity_test\Entity\EntityTest;
use Drupal\entity_test\Entity\EntityTestStringId;
use Drupal\taxonomy\TermInterface;
use Drupal\Tests\node\Traits\ContentTypeCreationTrait;
use Drupal\Tests\node\Traits\NodeCreationTrait;
@@ -22,6 +23,7 @@ class TaxonomyEntityIndexEntityTest extends TaxonomyEntityIndexKernelTestBase {
*/
protected $entityTypes = [
'entity_test',
'entity_test_string_id',
];
/**
@@ -36,6 +38,16 @@ class TaxonomyEntityIndexEntityTest extends TaxonomyEntityIndexKernelTestBase {
*/
protected static $modules = ['node', 'text', 'filter', 'options'];
/**
* Mapping for entity type and related bundles.
*
* @var string[]
*/
protected static array $bundles = [
'entity_test' => 'entity_test_termz',
'entity_test_string_id' => 'entity_test_string_id_termz',
];
/**
* {@inheritdoc}
*/
@@ -51,9 +63,10 @@ class TaxonomyEntityIndexEntityTest extends TaxonomyEntityIndexKernelTestBase {
/**
* {@inheritdoc}
*/
protected function createBundles($entity_type_id) {
entity_test_create_bundle('termz');
return ['termz'];
protected function createBundles($entity_type_id): array {
$bundleName = self::$bundles[$entity_type_id];
entity_test_create_bundle($bundleName);
return [$bundleName];
}
/**
@@ -77,6 +90,9 @@ class TaxonomyEntityIndexEntityTest extends TaxonomyEntityIndexKernelTestBase {
]);
$this->assertThatTermDeletionUpdatesTheIndex($entity, [$term1, $term2], [$term4]);
$this->assertThatEntityDeletionUpdatesTheIndex($entity);
// Test the entity with entity id as string and delete it.
$this->assertEntityWithStringIdDelete();
}
/**
@@ -110,7 +126,7 @@ class TaxonomyEntityIndexEntityTest extends TaxonomyEntityIndexKernelTestBase {
*/
protected function assertThatEntityInsertWritesToTheIndex(array $terms) {
$entity = EntityTest::create([
'type' => 'termz',
'type' => self::$bundles['entity_test'],
'termz' => $terms,
]);
$entity->save();
@@ -125,6 +141,18 @@ class TaxonomyEntityIndexEntityTest extends TaxonomyEntityIndexKernelTestBase {
return $entity;
}
/**
* Test that entity creation/deletion with string entity id works fine.
*/
protected function assertEntityWithStringIdDelete(): void {
$entity = EntityTestStringId::create([
'type' => self::$bundles['entity_test_string_id'],
'id' => $this->randomMachineName(),
]);
$entity->save();
$this->assertNull($entity->delete());
}
/**
* Test that updates to entities modify the index.
*
@@ -152,7 +180,7 @@ class TaxonomyEntityIndexEntityTest extends TaxonomyEntityIndexKernelTestBase {
$this->assertEquals(array_map(function (TermInterface $term) use ($entity, &$delta) {
return (object) [
'entity_type' => 'entity_test',
'bundle' => 'termz',
'bundle' => self::$bundles['entity_test'],
'entity_id' => $entity->id(),
'revision_id' => $entity->id(),
'field_name' => 'termz',
@@ -188,8 +216,8 @@ class TaxonomyEntityIndexEntityTest extends TaxonomyEntityIndexKernelTestBase {
$delta = 0;
$this->assertEquals(array_map(function (TermInterface $term) use ($entity, &$delta) {
return (object) [
'entity_type' => 'entity_test',
'bundle' => 'termz',
'entity_type' => $entity->getEntityTypeId(),
'bundle' => self::$bundles[$entity->getEntityTypeId()],
'entity_id' => $entity->id(),
'revision_id' => $entity->id(),
'field_name' => 'termz',
Loading