function EntityFieldManagerTest::testGetExtraFields

Same name and namespace 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. 11.x 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 <a href="/api/drupal/core%21lib%21Drupal%21Core%21Entity%21EntityFieldManager.php/class/EntityFieldManager/10" title="Manages the discovery of entity fields." class="local">\Drupal\Core\Entity\EntityFieldManager</a> @group Entity

Namespace

Drupal\Tests\Core\Entity

Code

public 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_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.