function EntityFieldManagerTest::testGetFieldDefinitionsWithCaching

Same name in other branches
  1. 9 core/tests/Drupal/Tests/Core/Entity/EntityFieldManagerTest.php \Drupal\Tests\Core\Entity\EntityFieldManagerTest::testGetFieldDefinitionsWithCaching()
  2. 10 core/tests/Drupal/Tests/Core/Entity/EntityFieldManagerTest.php \Drupal\Tests\Core\Entity\EntityFieldManagerTest::testGetFieldDefinitionsWithCaching()
  3. 11.x 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 384

Class

EntityFieldManagerTest
@coversDefaultClass \Drupal\Core\Entity\EntityFieldManager @group Entity

Namespace

Drupal\Tests\Core\Entity

Code

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'));
}

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