function EntityTypeBundleInfoTest::testGetAllBundleInfo

Same name and namespace in other branches
  1. 8.9.x core/tests/Drupal/Tests/Core/Entity/EntityTypeBundleInfoTest.php \Drupal\Tests\Core\Entity\EntityTypeBundleInfoTest::testGetAllBundleInfo()
  2. 10 core/tests/Drupal/Tests/Core/Entity/EntityTypeBundleInfoTest.php \Drupal\Tests\Core\Entity\EntityTypeBundleInfoTest::testGetAllBundleInfo()
  3. 11.x core/tests/Drupal/Tests/Core/Entity/EntityTypeBundleInfoTest.php \Drupal\Tests\Core\Entity\EntityTypeBundleInfoTest::testGetAllBundleInfo()

Tests the getAllBundleInfo() method.

@covers ::getAllBundleInfo

File

core/tests/Drupal/Tests/Core/Entity/EntityTypeBundleInfoTest.php, line 213

Class

EntityTypeBundleInfoTest
@coversDefaultClass <a href="/api/drupal/core%21lib%21Drupal%21Core%21Entity%21EntityTypeBundleInfo.php/class/EntityTypeBundleInfo/9" title="Provides discovery and retrieval of entity type bundles." class="local">\Drupal\Core\Entity\EntityTypeBundleInfo</a> @group Entity

Namespace

Drupal\Tests\Core\Entity

Code

public function testGetAllBundleInfo() {
    $this->moduleHandler
        ->invokeAll('entity_bundle_info')
        ->willReturn([]);
    $this->moduleHandler
        ->alter('entity_bundle_info', Argument::type('array'))
        ->willReturn(NULL);
    $apple = $this->prophesize(EntityTypeInterface::class);
    $apple->getLabel()
        ->willReturn('Apple');
    $apple->getBundleEntityType()
        ->willReturn(NULL);
    $banana = $this->prophesize(EntityTypeInterface::class);
    $banana->getLabel()
        ->willReturn('Banana');
    $banana->getBundleEntityType()
        ->willReturn(NULL);
    $this->setUpEntityTypeDefinitions([
        'apple' => $apple,
        'banana' => $banana,
    ]);
    $this->cacheBackend
        ->get('entity_bundle_info:en')
        ->willReturn(FALSE);
    $this->cacheBackend
        ->set('entity_bundle_info:en', Argument::any(), Cache::PERMANENT, [
        'entity_types',
        'entity_bundles',
    ])
        ->will(function () {
        $this->get('entity_bundle_info:en')
            ->willReturn((object) [
            'data' => 'cached data',
        ])
            ->shouldBeCalled();
    })
        ->shouldBeCalled();
    $this->cacheTagsInvalidator
        ->invalidateTags([
        'entity_bundles',
    ])
        ->shouldBeCalled();
    $this->typedDataManager
        ->clearCachedDefinitions()
        ->shouldBeCalled();
    $expected = [
        'apple' => [
            'apple' => [
                'label' => 'Apple',
            ],
        ],
        'banana' => [
            'banana' => [
                'label' => 'Banana',
            ],
        ],
    ];
    $bundle_info = $this->entityTypeBundleInfo
        ->getAllBundleInfo();
    $this->assertSame($expected, $bundle_info);
    $bundle_info = $this->entityTypeBundleInfo
        ->getAllBundleInfo();
    $this->assertSame($expected, $bundle_info);
    $this->entityTypeBundleInfo
        ->clearCachedBundles();
    $bundle_info = $this->entityTypeBundleInfo
        ->getAllBundleInfo();
    $this->assertSame('cached data', $bundle_info);
}

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