function ConfigEntityBaseUnitTest::testCalculateDependenciesWithPluginCollections

Same name and namespace in other branches
  1. 8.9.x core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityBaseUnitTest.php \Drupal\Tests\Core\Config\Entity\ConfigEntityBaseUnitTest::testCalculateDependenciesWithPluginCollections()
  2. 10 core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityBaseUnitTest.php \Drupal\Tests\Core\Config\Entity\ConfigEntityBaseUnitTest::testCalculateDependenciesWithPluginCollections()
  3. 11.x 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 249

Class

ConfigEntityBaseUnitTest
@coversDefaultClass <a href="/api/drupal/core%21lib%21Drupal%21Core%21Config%21Entity%21ConfigEntityBase.php/class/ConfigEntityBase/9" title="Defines a base configuration entity class." class="local">\Drupal\Core\Config\Entity\ConfigEntityBase</a> @group Config

Namespace

Drupal\Tests\Core\Config\Entity

Code

public function testCalculateDependenciesWithPluginCollections($definition, $expected_dependencies) {
    $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.