public function EntityFieldManagerTest::testGetFieldStorageDefinitionsWithCaching in Drupal 9
Same name and namespace in other branches
- 8 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 432 - Contains \Drupal\Tests\Core\Entity\EntityFieldManagerTest.
Class
- EntityFieldManagerTest
- @coversDefaultClass \Drupal\Core\Entity\EntityFieldManager @group Entity
Namespace
Drupal\Tests\Core\EntityCode
public function testGetFieldStorageDefinitionsWithCaching() {
$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
->getImplementations('entity_field_storage_info')
->willReturn([
'example_module',
]);
$this->moduleHandler
->invoke('example_module', 'entity_field_storage_info', [
$this->entityType,
])
->willReturn($definitions);
$this->moduleHandler
->alter('entity_field_storage_info', $definitions, $this->entityType)
->willReturn(NULL);
$expected = [
'id' => $field_definition,
'field_storage' => $field_storage_definition
->reveal(),
];
$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) {
$this
->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'));
}