3 namespace Drupal\Tests\Core\Plugin;
5 use Drupal\Component\Plugin\Definition\PluginDefinitionInterface;
6 use Drupal\Component\Plugin\DependentPluginInterface;
7 use Drupal\Component\Plugin\PluginInspectionInterface;
8 use Drupal\Core\Plugin\Definition\DependentPluginDefinitionInterface;
9 use Drupal\Core\Plugin\PluginDependencyTrait;
10 use Drupal\Tests\UnitTestCase;
11 use Prophecy\Prophecy\ProphecyInterface;
14 * @coversDefaultClass \Drupal\Core\Plugin\PluginDependencyTrait
17 class PluginDependencyTraitTest extends UnitTestCase {
20 * @covers ::calculatePluginDependencies
22 * @dataProvider providerTestCalculatePluginDependencies
24 * @param \Prophecy\Prophecy\ProphecyInterface $plugin
25 * A prophecy of a plugin instance.
26 * @param mixed $definition
27 * A plugin definition.
28 * @param array $expected
29 * The expected dependencies.
31 public function testCalculatePluginDependencies(ProphecyInterface $plugin, $definition, array $expected) {
32 $test_class = new TestPluginDependency();
34 $plugin->getPluginDefinition()->willReturn($definition);
36 $test_class->calculatePluginDependencies($plugin->reveal());
37 $this->assertEquals($expected, $test_class->getDependencies());
41 * Provides test data for ::testCalculatePluginDependencies().
43 public function providerTestCalculatePluginDependencies() {
46 $plugin = $this->prophesize(PluginInspectionInterface::class);
48 $dependent_plugin = $this->prophesize(PluginInspectionInterface::class)->willImplement(DependentPluginInterface::class);
49 $dependent_plugin->calculateDependencies()->willReturn([
50 'module' => ['test_module2'],
53 $data['dependent_plugin'] = [
55 ['provider' => 'test_module1'],
64 $data['array_with_config_dependencies'] = [
67 'provider' => 'test_module1',
68 'config_dependencies' => [
69 'module' => ['test_module2'],
80 $definition = $this->prophesize(PluginDefinitionInterface::class);
81 $definition->getProvider()->willReturn('test_module1');
82 $data['object_definition'] = [
84 $definition->reveal(),
92 $dependent_definition = $this->prophesize(PluginDefinitionInterface::class)->willImplement(DependentPluginDefinitionInterface::class);
93 $dependent_definition->getProvider()->willReturn('test_module1');
94 $dependent_definition->getConfigDependencies()->willReturn(['module' => ['test_module2']]);
95 $data['dependent_object_definition'] = [
97 $dependent_definition->reveal(),
110 class TestPluginDependency {
112 use PluginDependencyTrait {
113 calculatePluginDependencies as public;
119 public function getDependencies() {
120 return $this->dependencies;