You are here

public function EntityFieldManagerTest::testGetBaseFieldDefinitionsWithCaching in Drupal 9

Same name and namespace in other branches
  1. 8 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 375
Contains \Drupal\Tests\Core\Entity\EntityFieldManagerTest.

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