function EntityFieldManagerTest::testGetFieldStorageDefinitionsWithCaching
Same name in other branches
- 9 core/tests/Drupal/Tests/Core/Entity/EntityFieldManagerTest.php \Drupal\Tests\Core\Entity\EntityFieldManagerTest::testGetFieldStorageDefinitionsWithCaching()
- 8.9.x core/tests/Drupal/Tests/Core/Entity/EntityFieldManagerTest.php \Drupal\Tests\Core\Entity\EntityFieldManagerTest::testGetFieldStorageDefinitionsWithCaching()
- 10 core/tests/Drupal/Tests/Core/Entity/EntityFieldManagerTest.php \Drupal\Tests\Core\Entity\EntityFieldManagerTest::testGetFieldStorageDefinitionsWithCaching()
Tests the getFieldStorageDefinitions() method with caching.
@covers ::getFieldStorageDefinitions
File
-
core/
tests/ Drupal/ Tests/ Core/ Entity/ EntityFieldManagerTest.php, line 480
Class
- EntityFieldManagerTest
- @coversDefaultClass \Drupal\Core\Entity\EntityFieldManager @group Entity
Namespace
Drupal\Tests\Core\EntityCode
public function testGetFieldStorageDefinitionsWithCaching() : void {
$field_definition = $this->setUpEntityWithFieldDefinition(TRUE, 'id');
$field_storage_definition = $this->prophesize(FieldStorageDefinitionInterface::class);
$field_storage_definition->getName()
->willReturn('field_storage');
$definitions = [
'field_storage' => $field_storage_definition->reveal(),
];
$this->moduleHandler
->invokeAllWith('entity_field_storage_info', Argument::any())
->will(function ($arguments) use ($definitions) {
[
$hook,
$callback,
] = $arguments;
$callback(function () use ($definitions) {
return $definitions;
}, 'example_module');
});
$this->moduleHandler
->alter('entity_field_storage_info', $definitions, $this->entityType)
->willReturn(NULL);
$expected = [
'id' => $field_definition,
'field_storage' => $field_storage_definition->reveal(),
];
$cacheBackend = $this->cacheBackend;
$this->cacheBackend
->get('entity_base_field_definitions:test_entity_type:en')
->willReturn((object) [
'data' => [
'id' => $expected['id'],
],
])
->shouldBeCalledTimes(2);
$this->cacheBackend
->get('entity_field_storage_definitions:test_entity_type:en')
->willReturn(FALSE);
$this->cacheBackend
->set('entity_field_storage_definitions:test_entity_type:en', Argument::any(), Cache::PERMANENT, [
'entity_types',
'entity_field_info',
])
->will(function () use ($expected, $cacheBackend) {
$cacheBackend->get('entity_field_storage_definitions:test_entity_type:en')
->willReturn((object) [
'data' => $expected,
])
->shouldBeCalled();
})
->shouldBeCalled();
$this->assertSame($expected, $this->entityFieldManager
->getFieldStorageDefinitions('test_entity_type'));
$this->entityFieldManager
->testClearEntityFieldInfo();
$this->assertSame($expected, $this->entityFieldManager
->getFieldStorageDefinitions('test_entity_type'));
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.