function ConfigEntityBaseUnitTest::testCalculateDependenciesWithPluginCollections

Same name in other branches
  1. 9 core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityBaseUnitTest.php \Drupal\Tests\Core\Config\Entity\ConfigEntityBaseUnitTest::testCalculateDependenciesWithPluginCollections()
  2. 8.9.x core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityBaseUnitTest.php \Drupal\Tests\Core\Config\Entity\ConfigEntityBaseUnitTest::testCalculateDependenciesWithPluginCollections()
  3. 10 core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityBaseUnitTest.php \Drupal\Tests\Core\Config\Entity\ConfigEntityBaseUnitTest::testCalculateDependenciesWithPluginCollections()

@covers ::getDependencies @covers ::calculateDependencies

@dataProvider providerCalculateDependenciesWithPluginCollections

File

core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityBaseUnitTest.php, line 251

Class

ConfigEntityBaseUnitTest
@coversDefaultClass \Drupal\Core\Config\Entity\ConfigEntityBase @group Config

Namespace

Drupal\Tests\Core\Config\Entity

Code

public function testCalculateDependenciesWithPluginCollections(array $definition, array $expected_dependencies) : void {
    $this->moduleHandler
        ->moduleExists('the_provider_of_the_entity_type')
        ->willReturn(TRUE);
    $this->moduleHandler
        ->moduleExists('test')
        ->willReturn(TRUE);
    $this->moduleHandler
        ->moduleExists('test_theme')
        ->willReturn(FALSE);
    $this->themeHandler
        ->themeExists('test_theme')
        ->willReturn(TRUE);
    $values = [];
    $this->entity = $this->getMockBuilder('\\Drupal\\Tests\\Core\\Config\\Entity\\Fixtures\\ConfigEntityBaseWithPluginCollections')
        ->setConstructorArgs([
        $values,
        $this->entityTypeId,
    ])
        ->onlyMethods([
        'getPluginCollections',
    ])
        ->getMock();
    // Create a configurable plugin that would add a dependency.
    $instance_id = $this->randomMachineName();
    $instance = new TestConfigurablePlugin([], $instance_id, $definition);
    // Create a plugin collection to contain the instance.
    $pluginCollection = $this->getMockBuilder('\\Drupal\\Core\\Plugin\\DefaultLazyPluginCollection')
        ->disableOriginalConstructor()
        ->onlyMethods([
        'get',
    ])
        ->getMock();
    $pluginCollection->expects($this->atLeastOnce())
        ->method('get')
        ->with($instance_id)
        ->willReturn($instance);
    $pluginCollection->addInstanceId($instance_id);
    // Return the mocked plugin collection.
    $this->entity
        ->expects($this->once())
        ->method('getPluginCollections')
        ->willReturn([
        $pluginCollection,
    ]);
    $this->assertEquals($expected_dependencies, $this->entity
        ->calculateDependencies()
        ->getDependencies());
}

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