public function EntityFieldManagerTest::testGetFieldDefinitionsWithCaching in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/tests/Drupal/Tests/Core/Entity/EntityFieldManagerTest.php \Drupal\Tests\Core\Entity\EntityFieldManagerTest::testGetFieldDefinitionsWithCaching()
Tests the getFieldDefinitions() method with caching.
@covers ::getFieldDefinitions
File
- core/
tests/ Drupal/ Tests/ Core/ Entity/ EntityFieldManagerTest.php, line 385 - Contains \Drupal\Tests\Core\Entity\EntityFieldManagerTest.
Class
- EntityFieldManagerTest
- @coversDefaultClass \Drupal\Core\Entity\EntityFieldManager @group Entity
Namespace
Drupal\Tests\Core\EntityCode
public function testGetFieldDefinitionsWithCaching() {
$field_definition = $this
->setUpEntityWithFieldDefinition(FALSE, 'id');
$expected = [
'id' => $field_definition,
];
$this->cacheBackend
->get('entity_base_field_definitions:test_entity_type:en')
->willReturn((object) [
'data' => $expected,
])
->shouldBeCalledTimes(2);
$this->cacheBackend
->get('entity_bundle_field_definitions:test_entity_type:test_bundle:en')
->willReturn(FALSE)
->shouldBeCalledTimes(1);
$this->cacheBackend
->set('entity_bundle_field_definitions:test_entity_type:test_bundle:en', Argument::any(), Cache::PERMANENT, [
'entity_types',
'entity_field_info',
])
->will(function ($args) {
$data = (object) [
'data' => $args[1],
];
$this
->get('entity_bundle_field_definitions:test_entity_type:test_bundle:en')
->willReturn($data)
->shouldBeCalled();
})
->shouldBeCalled();
$this
->assertSame($expected, $this->entityFieldManager
->getFieldDefinitions('test_entity_type', 'test_bundle'));
$this->entityFieldManager
->testClearEntityFieldInfo();
$this
->assertSame($expected, $this->entityFieldManager
->getFieldDefinitions('test_entity_type', 'test_bundle'));
}