ConfigEntityStaticCacheTest.php in Zircon Profile 8
File
core/modules/config/src/Tests/ConfigEntityStaticCacheTest.php
View source
<?php
namespace Drupal\config\Tests;
use Drupal\config_entity_static_cache_test\ConfigOverrider;
use Drupal\simpletest\KernelTestBase;
class ConfigEntityStaticCacheTest extends KernelTestBase {
public static $modules = array(
'config_test',
'config_entity_static_cache_test',
);
protected $entityTypeId;
protected $entityId;
public function setUp() {
parent::setUp();
$this->entityTypeId = 'config_test';
$this->entityId = 'test_1';
entity_create($this->entityTypeId, array(
'id' => $this->entityId,
'label' => 'Original label',
))
->save();
}
public function testCacheHit() {
$entity_1 = entity_load($this->entityTypeId, $this->entityId);
$entity_2 = entity_load($this->entityTypeId, $this->entityId);
$this
->assertIdentical($entity_1->_loadStamp, $entity_2->_loadStamp);
}
public function testReset() {
$entity = entity_load($this->entityTypeId, $this->entityId);
$entity->label = 'New label';
$entity
->save();
$entity = entity_load($this->entityTypeId, $this->entityId);
$this
->assertIdentical($entity->label, 'New label');
$entity
->delete();
$this
->assertNull(entity_load($this->entityTypeId, $this->entityId));
}
public function testConfigOverride() {
$storage = \Drupal::entityManager()
->getStorage($this->entityTypeId);
$storage
->load($this->entityId);
\Drupal::configFactory()
->addOverride(new ConfigOverrider());
$entity_override = $storage
->load($this->entityId);
$this
->assertIdentical($entity_override->label, 'Overridden label');
$entity_no_override = $storage
->loadOverrideFree($this->entityId);
$this
->assertNotIdentical($entity_no_override->label, 'Overridden label');
$this
->assertNotIdentical($entity_override->_loadStamp, $entity_no_override->_loadStamp);
$this
->assertIdentical($storage
->loadOverrideFree($this->entityId)->_loadStamp, $entity_no_override->_loadStamp);
$this
->assertIdentical($storage
->load($this->entityId)->_loadStamp, $entity_override->_loadStamp);
}
}