class FilteredPluginManagerTraitTest
Same name in other branches
- 9 core/tests/Drupal/Tests/Core/Plugin/FilteredPluginManagerTraitTest.php \Drupal\Tests\Core\Plugin\FilteredPluginManagerTraitTest
- 8.9.x core/tests/Drupal/Tests/Core/Plugin/FilteredPluginManagerTraitTest.php \Drupal\Tests\Core\Plugin\FilteredPluginManagerTraitTest
- 10 core/tests/Drupal/Tests/Core/Plugin/FilteredPluginManagerTraitTest.php \Drupal\Tests\Core\Plugin\FilteredPluginManagerTraitTest
@coversDefaultClass \Drupal\Core\Plugin\FilteredPluginManagerTrait @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\FilteredPluginManagerTraitTest extends \Drupal\Tests\UnitTestCase
Expanded class hierarchy of FilteredPluginManagerTraitTest
File
-
core/
tests/ Drupal/ Tests/ Core/ Plugin/ FilteredPluginManagerTraitTest.php, line 19
Namespace
Drupal\Tests\Core\PluginView source
class FilteredPluginManagerTraitTest extends UnitTestCase {
/**
* @covers ::getFilteredDefinitions
* @dataProvider providerTestGetFilteredDefinitions
*/
public function testGetFilteredDefinitions($contexts, $expected) : void {
// Start with two plugins.
$definitions = [];
$definitions['plugin1'] = [
'id' => 'plugin1',
];
$definitions['plugin2'] = [
'id' => 'plugin2',
];
$type = 'the_type';
$consumer = 'the_consumer';
$extra = [
'foo' => 'bar',
];
$context_handler = $this->prophesize(ContextHandlerInterface::class);
// Remove the second plugin when context1 is provided.
$context_handler->filterPluginDefinitionsByContexts([
'context1' => 'fake context',
], $definitions)
->willReturn([
'plugin1' => $definitions['plugin1'],
]);
// Remove the first plugin when no contexts are provided.
$context_handler->filterPluginDefinitionsByContexts([], $definitions)
->willReturn([
'plugin2' => $definitions['plugin2'],
]);
// After context filtering, the alter hook will be invoked.
$module_handler = $this->prophesize(ModuleHandlerInterface::class);
$hooks = [
"plugin_filter_{$type}",
"plugin_filter_{$type}__{$consumer}",
];
$module_handler->alter($hooks, $expected, $extra, $consumer)
->shouldBeCalled();
$theme_manager = $this->prophesize(ThemeManagerInterface::class);
$theme_manager->alter($hooks, $expected, $extra, $consumer)
->shouldBeCalled();
$plugin_manager = new TestFilteredPluginManager($definitions, $module_handler->reveal(), $theme_manager->reveal(), $context_handler->reveal());
$result = $plugin_manager->getFilteredDefinitions($consumer, $contexts, $extra);
$this->assertSame($expected, $result);
}
/**
* Provides test data for ::testGetFilteredDefinitions().
*/
public static function providerTestGetFilteredDefinitions() {
$data = [];
$data['populated context'] = [
[
'context1' => 'fake context',
],
[
'plugin1' => [
'id' => 'plugin1',
],
],
];
$data['empty context'] = [
[],
[
'plugin2' => [
'id' => 'plugin2',
],
],
];
$data['null context'] = [
NULL,
[
'plugin1' => [
'id' => 'plugin1',
],
'plugin2' => [
'id' => 'plugin2',
],
],
];
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. | |
FilteredPluginManagerTraitTest::providerTestGetFilteredDefinitions | public static | function | Provides test data for ::testGetFilteredDefinitions(). | |
FilteredPluginManagerTraitTest::testGetFilteredDefinitions | public | function | @covers ::getFilteredDefinitions @dataProvider providerTestGetFilteredDefinitions |
|
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.