class PluginDependencyTraitTest
Same name in other branches
- 9 core/tests/Drupal/Tests/Core/Plugin/PluginDependencyTraitTest.php \Drupal\Tests\Core\Plugin\PluginDependencyTraitTest
- 8.9.x core/tests/Drupal/Tests/Core/Plugin/PluginDependencyTraitTest.php \Drupal\Tests\Core\Plugin\PluginDependencyTraitTest
- 10 core/tests/Drupal/Tests/Core/Plugin/PluginDependencyTraitTest.php \Drupal\Tests\Core\Plugin\PluginDependencyTraitTest
@coversDefaultClass \Drupal\Core\Plugin\PluginDependencyTrait @group Plugin
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses \Drupal\Tests\PhpUnitCompatibilityTrait, \Prophecy\PhpUnit\ProphecyTrait, \Drupal\TestTools\Extension\DeprecationBridge\ExpectDeprecationTrait, \Drupal\Tests\RandomGeneratorTrait
- class \Drupal\Tests\Core\Plugin\PluginDependencyTraitTest extends \Drupal\Tests\UnitTestCase
Expanded class hierarchy of PluginDependencyTraitTest
File
-
core/
tests/ Drupal/ Tests/ Core/ Plugin/ PluginDependencyTraitTest.php, line 22
Namespace
Drupal\Tests\Core\PluginView source
class PluginDependencyTraitTest extends UnitTestCase {
/**
* @covers ::getPluginDependencies
*
* @dataProvider providerTestPluginDependencies
*/
public function testGetPluginDependencies(ProphecyInterface $plugin, $definition, array $expected) : void {
$test_class = new TestPluginDependency();
$module_handler = $this->prophesize(ModuleHandlerInterface::class);
$module_handler->moduleExists('test_module1')
->willReturn(TRUE);
$module_handler->moduleExists('test_theme1')
->willReturn(FALSE);
$test_class->setModuleHandler($module_handler->reveal());
$theme_handler = $this->prophesize(ThemeHandlerInterface::class);
$theme_handler->themeExists('test_module1')
->willReturn(FALSE);
$theme_handler->themeExists('test_theme1')
->willReturn(TRUE);
$test_class->setThemeHandler($theme_handler->reveal());
$plugin->getPluginDefinition()
->willReturn($definition);
$actual = $test_class->getPluginDependencies($plugin->reveal());
$this->assertEquals($expected, $actual);
$this->assertEmpty($test_class->getDependencies());
}
/**
* @covers ::calculatePluginDependencies
*
* @dataProvider providerTestPluginDependencies
*
* @param \Prophecy\Prophecy\ProphecyInterface $plugin
* A prophecy of a plugin instance.
* @param mixed $definition
* A plugin definition.
* @param array $expected
* The expected dependencies.
*/
public function testCalculatePluginDependencies(ProphecyInterface $plugin, $definition, array $expected) : void {
$test_class = new TestPluginDependency();
$module_handler = $this->prophesize(ModuleHandlerInterface::class);
$module_handler->moduleExists('test_module1')
->willReturn(TRUE);
$module_handler->moduleExists('test_theme1')
->willReturn(FALSE);
$test_class->setModuleHandler($module_handler->reveal());
$theme_handler = $this->prophesize(ThemeHandlerInterface::class);
$theme_handler->themeExists('test_module1')
->willReturn(FALSE);
$theme_handler->themeExists('test_theme1')
->willReturn(TRUE);
$test_class->setThemeHandler($theme_handler->reveal());
$plugin->getPluginDefinition()
->willReturn($definition);
$test_class->calculatePluginDependencies($plugin->reveal());
$this->assertEquals($expected, $test_class->getDependencies());
}
/**
* Provides test data for plugin dependencies.
*/
public static function providerTestPluginDependencies() {
$prophet = new Prophet();
$data = [];
$plugin = $prophet->prophesize(PluginInspectionInterface::class);
$dependent_plugin = $prophet->prophesize(PluginInspectionInterface::class)
->willImplement(DependentPluginInterface::class);
$dependent_plugin->calculateDependencies()
->willReturn([
'module' => [
'test_module2',
],
]);
$data['dependent_plugin_from_module'] = [
$dependent_plugin,
[
'provider' => 'test_module1',
],
[
'module' => [
'test_module1',
'test_module2',
],
],
];
$data['dependent_plugin_from_core'] = [
$dependent_plugin,
[
'provider' => 'core',
],
[
'module' => [
'core',
'test_module2',
],
],
];
$data['dependent_plugin_from_theme'] = [
$dependent_plugin,
[
'provider' => 'test_theme1',
],
[
'module' => [
'test_module2',
],
'theme' => [
'test_theme1',
],
],
];
$data['array_with_config_dependencies'] = [
$plugin,
[
'provider' => 'test_module1',
'config_dependencies' => [
'module' => [
'test_module2',
],
],
],
[
'module' => [
'test_module1',
'test_module2',
],
],
];
$definition = $prophet->prophesize(PluginDefinitionInterface::class);
$definition->getProvider()
->willReturn('test_module1');
$data['object_definition'] = [
$plugin,
$definition->reveal(),
[
'module' => [
'test_module1',
],
],
];
$dependent_definition = $prophet->prophesize(PluginDefinitionInterface::class)
->willImplement(DependentPluginDefinitionInterface::class);
$dependent_definition->getProvider()
->willReturn('test_module1');
$dependent_definition->getConfigDependencies()
->willReturn([
'module' => [
'test_module2',
],
]);
$data['dependent_object_definition'] = [
$plugin,
$dependent_definition->reveal(),
[
'module' => [
'test_module1',
'test_module2',
],
],
];
return $data;
}
}
Members
Title Sort descending | Modifiers | Object type | Summary | Overrides |
---|---|---|---|---|
ExpectDeprecationTrait::expectDeprecation | public | function | Adds an expected deprecation. | |
ExpectDeprecationTrait::getCallableName | private static | function | Returns a callable as a string suitable for inclusion in a message. | |
ExpectDeprecationTrait::setUpErrorHandler | public | function | Sets up the test error handler. | |
ExpectDeprecationTrait::tearDownErrorHandler | public | function | Tears down the test error handler. | |
PluginDependencyTraitTest::providerTestPluginDependencies | public static | function | Provides test data for plugin dependencies. | |
PluginDependencyTraitTest::testCalculatePluginDependencies | public | function | @covers ::calculatePluginDependencies | |
PluginDependencyTraitTest::testGetPluginDependencies | public | function | @covers ::getPluginDependencies | |
RandomGeneratorTrait::getRandomGenerator | protected | function | Gets the random generator for the utility methods. | |
RandomGeneratorTrait::randomMachineName | protected | function | Generates a unique random string containing letters and numbers. | |
RandomGeneratorTrait::randomObject | public | function | Generates a random PHP object. | |
RandomGeneratorTrait::randomString | public | function | Generates a pseudo-random string of ASCII characters of codes 32 to 126. | |
UnitTestCase::$root | protected | property | The app root. | |
UnitTestCase::getClassResolverStub | protected | function | Returns a stub class resolver. | |
UnitTestCase::getConfigFactoryStub | public | function | Returns a stub config factory that behaves according to the passed array. | |
UnitTestCase::getConfigStorageStub | public | function | Returns a stub config storage that returns the supplied configuration. | |
UnitTestCase::getContainerWithCacheTagsInvalidator | protected | function | Sets up a container with a cache tags invalidator. | |
UnitTestCase::getStringTranslationStub | public | function | Returns a stub translation manager that just returns the passed string. | |
UnitTestCase::setUp | protected | function | 367 | |
UnitTestCase::setUpBeforeClass | public static | function |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.