You are here

public function ConfigEntityBaseUnitTest::testCalculateDependenciesWithPluginCollections in Drupal 9

Same name and namespace in other branches
  1. 8 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 248
Contains \Drupal\Tests\Core\Config\Entity\ConfigEntityBaseUnitTest.

Class

ConfigEntityBaseUnitTest
@coversDefaultClass \Drupal\Core\Config\Entity\ConfigEntityBase @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,
  ])
    ->setMethods([
    '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()
    ->setMethods([
    'get',
  ])
    ->getMock();
  $pluginCollection
    ->expects($this
    ->atLeastOnce())
    ->method('get')
    ->with($instance_id)
    ->will($this
    ->returnValue($instance));
  $pluginCollection
    ->addInstanceId($instance_id);

  // Return the mocked plugin collection.
  $this->entity
    ->expects($this
    ->once())
    ->method('getPluginCollections')
    ->will($this
    ->returnValue([
    $pluginCollection,
  ]));
  $this
    ->assertEquals($expected_dependencies, $this->entity
    ->calculateDependencies()
    ->getDependencies());
}