function EntityFieldManagerTest::testGetBaseFieldDefinitionsWithCaching

Same name in other branches
  1. 9 core/tests/Drupal/Tests/Core/Entity/EntityFieldManagerTest.php \Drupal\Tests\Core\Entity\EntityFieldManagerTest::testGetBaseFieldDefinitionsWithCaching()
  2. 10 core/tests/Drupal/Tests/Core/Entity/EntityFieldManagerTest.php \Drupal\Tests\Core\Entity\EntityFieldManagerTest::testGetBaseFieldDefinitionsWithCaching()
  3. 11.x core/tests/Drupal/Tests/Core/Entity/EntityFieldManagerTest.php \Drupal\Tests\Core\Entity\EntityFieldManagerTest::testGetBaseFieldDefinitionsWithCaching()

Tests the getBaseFieldDefinitions() method with caching.

@covers ::getBaseFieldDefinitions

File

core/tests/Drupal/Tests/Core/Entity/EntityFieldManagerTest.php, line 357

Class

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

Namespace

Drupal\Tests\Core\Entity

Code

public function testGetBaseFieldDefinitionsWithCaching() {
    $field_definition = $this->setUpEntityWithFieldDefinition();
    $expected = [
        'id' => $field_definition,
    ];
    $this->cacheBackend
        ->get('entity_base_field_definitions:test_entity_type:en')
        ->willReturn(FALSE)
        ->shouldBeCalled();
    $this->cacheBackend
        ->set('entity_base_field_definitions:test_entity_type:en', Argument::any(), Cache::PERMANENT, [
        'entity_types',
        'entity_field_info',
    ])
        ->will(function ($args) {
        $data = (object) [
            'data' => $args[1],
        ];
        $this->get('entity_base_field_definitions:test_entity_type:en')
            ->willReturn($data)
            ->shouldBeCalled();
    })
        ->shouldBeCalled();
    $this->assertSame($expected, $this->entityFieldManager
        ->getBaseFieldDefinitions('test_entity_type'));
    $this->entityFieldManager
        ->testClearEntityFieldInfo();
    $this->assertSame($expected, $this->entityFieldManager
        ->getBaseFieldDefinitions('test_entity_type'));
}

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