function EntityFieldManagerTest::testGetExtraFields

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

Class

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

Namespace

Drupal\Tests\Core\Entity

Code

public function testGetExtraFields() : void {
    $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_extra_field_info:' . $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, Cache::PERMANENT, [
        'entity_field_info',
    ])
        ->shouldBeCalled();
    $this->assertSame($processed_hook_bundle_extra_fields[$entity_type_id][$bundle], $this->entityFieldManager
        ->getExtraFields($entity_type_id, $bundle));
}

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