function ConfigEntityStaticCacheTest::testConfigOverride

Same name and namespace in other branches
  1. 9 core/tests/Drupal/KernelTests/Core/Config/ConfigEntityStaticCacheTest.php \Drupal\KernelTests\Core\Config\ConfigEntityStaticCacheTest::testConfigOverride()
  2. 8.9.x core/tests/Drupal/KernelTests/Core/Config/ConfigEntityStaticCacheTest.php \Drupal\KernelTests\Core\Config\ConfigEntityStaticCacheTest::testConfigOverride()
  3. 11.x core/tests/Drupal/KernelTests/Core/Config/ConfigEntityStaticCacheTest.php \Drupal\KernelTests\Core\Config\ConfigEntityStaticCacheTest::testConfigOverride()

Tests that the static cache is sensitive to config overrides.

File

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

Class

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

Namespace

Drupal\KernelTests\Core\Config

Code

public function testConfigOverride() : void {
  /** @var \Drupal\Core\Config\Entity\ConfigEntityStorage $storage */
  $storage = \Drupal::entityTypeManager()->getStorage($this->entityTypeId);
  // Prime the cache prior to adding a config override.
  $storage->load($this->entityId);
  // Add the config override, and ensure that what is loaded is correct
  // despite the prior cache priming.
  \Drupal::configFactory()->addOverride(new ConfigOverrider());
  $entity_override = $storage->load($this->entityId);
  $this->assertSame('Overridden label', $entity_override->label);
  // Load override free to ensure that loading the config entity again does
  // not return the overridden value.
  $entity_no_override = $storage->loadOverrideFree($this->entityId);
  $this->assertNotSame('Overridden label', $entity_no_override->label);
  $this->assertNotSame($entity_override->_loadStamp, $entity_no_override->_loadStamp);
  // Reload the entity and ensure the cache is used.
  $this->assertSame($entity_no_override->_loadStamp, $storage->loadOverrideFree($this->entityId)->_loadStamp);
  // Enable overrides and reload the entity and ensure the cache is used.
  $this->assertSame($entity_override->_loadStamp, $storage->load($this->entityId)->_loadStamp);
}

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