You are here

public function ConfigEntityStaticCacheTest::testReset in Drupal 9

Same name and namespace in other branches
  1. 8 core/tests/Drupal/KernelTests/Core/Config/ConfigEntityStaticCacheTest.php \Drupal\KernelTests\Core\Config\ConfigEntityStaticCacheTest::testReset()
  2. 10 core/tests/Drupal/KernelTests/Core/Config/ConfigEntityStaticCacheTest.php \Drupal\KernelTests\Core\Config\ConfigEntityStaticCacheTest::testReset()

Tests that the static cache is reset on entity save and delete.

File

core/tests/Drupal/KernelTests/Core/Config/ConfigEntityStaticCacheTest.php, line 69

Class

ConfigEntityStaticCacheTest
Tests the entity static cache when used by config entities.

Namespace

Drupal\KernelTests\Core\Config

Code

public function testReset() {
  $storage = $this->container
    ->get('entity_type.manager')
    ->getStorage($this->entityTypeId);
  $entity = $storage
    ->load($this->entityId);

  // Ensure loading after a save retrieves the updated entity rather than an
  // obsolete cached one.
  $entity->label = 'New label';
  $entity
    ->save();
  $entity = $storage
    ->load($this->entityId);
  $this
    ->assertSame('New label', $entity->label);

  // Ensure loading after a delete retrieves NULL rather than an obsolete
  // cached one.
  $entity
    ->delete();
  $this
    ->assertNull($storage
    ->load($this->entityId));
}