You are here

function EntityFieldManagerTest::testGetExtraFields in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/tests/Drupal/Tests/Core/Entity/EntityFieldManagerTest.php \Drupal\Tests\Core\Entity\EntityFieldManagerTest::testGetExtraFields()

@covers ::getExtraFields

File

core/tests/Drupal/Tests/Core/Entity/EntityFieldManagerTest.php, line 573
Contains \Drupal\Tests\Core\Entity\EntityFieldManagerTest.

Class

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

Namespace

Drupal\Tests\Core\Entity

Code

function testGetExtraFields() {
  $this
    ->setUpEntityTypeDefinitions();
  $entity_type_id = $this
    ->randomMachineName();
  $bundle = $this
    ->randomMachineName();
  $language_code = 'en';
  $hook_bundle_extra_fields = [
    $entity_type_id => [
      $bundle => [
        'form' => [
          'foo_extra_field' => [
            'label' => 'Foo',
          ],
        ],
      ],
    ],
  ];
  $processed_hook_bundle_extra_fields = $hook_bundle_extra_fields;
  $processed_hook_bundle_extra_fields[$entity_type_id][$bundle] += [
    'display' => [],
  ];
  $cache_id = 'entity_bundle_extra_fields:' . $entity_type_id . ':' . $bundle . ':' . $language_code;
  $language = new Language([
    'id' => $language_code,
  ]);
  $this->languageManager
    ->getCurrentLanguage()
    ->willReturn($language)
    ->shouldBeCalledTimes(1);
  $this->cacheBackend
    ->get($cache_id)
    ->shouldBeCalled();
  $this->moduleHandler
    ->invokeAll('entity_extra_field_info')
    ->willReturn($hook_bundle_extra_fields);
  $this->moduleHandler
    ->alter('entity_extra_field_info', $hook_bundle_extra_fields)
    ->shouldBeCalled();
  $this->cacheBackend
    ->set($cache_id, $processed_hook_bundle_extra_fields[$entity_type_id][$bundle], Cache::PERMANENT, [
    'entity_field_info',
  ])
    ->shouldBeCalled();
  $this
    ->assertSame($processed_hook_bundle_extra_fields[$entity_type_id][$bundle], $this->entityFieldManager
    ->getExtraFields($entity_type_id, $bundle));
}