function SqlContentEntityStorageTest::testEntityWithManyFieldsLoad

Tests that entities with a large number (65+) of fields load successfully.

Attributes

#[DataProvider('providerCardinality')]

File

core/tests/Drupal/KernelTests/Core/Entity/Sql/SqlContentEntityStorageTest.php, line 128

Class

SqlContentEntityStorageTest
Tests that the deleteFromDedicatedTables() method only executes one DELETE query.

Namespace

Drupal\KernelTests\Core\Entity\Sql

Code

public function testEntityWithManyFieldsLoad(int $cardinality) : void {
  $fieldCount = 71;
  for ($i = 1; $i <= $fieldCount; $i++) {
    $fieldStorage = FieldStorageConfig::create([
      'field_name' => 'field_test_' . $i,
      'entity_type' => 'entity_test_rev',
      'type' => 'string',
      'cardinality' => $cardinality,
    ]);
    $fieldStorage->save();
    FieldConfig::create([
      'field_storage' => $fieldStorage,
      'bundle' => 'entity_test_rev',
    ])->save();
  }
  $values = [
    'name' => 'Test entity',
    'bundle' => 'entity_test_rev',
  ];
  for ($i = 1; $i <= $fieldCount; $i++) {
    $values['field_test_' . $i] = 'value_' . $i;
  }
  $storage = $this->container
    ->get('entity_type.manager')
    ->getStorage('entity_test_rev');
  $entity = $storage->create($values);
  $entity->save();
  $id = $entity->id();
  $storage->resetCache();
  $entity = $storage->load($id);
  for ($i = 1; $i <= $fieldCount; $i++) {
    $this->assertSame("value_{$i}", $entity->get("field_test_{$i}")->value);
  }
  $revision_id = $entity->getRevisionId();
  $storage->resetCache();
  $revision = $storage->loadRevision($revision_id);
  for ($i = 1; $i <= $fieldCount; $i++) {
    $this->assertSame("value_{$i}", $revision->get("field_test_{$i}")->value);
  }
}

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