class FilteredPluginManagerTraitTest in Drupal 10
Same name and namespace in other branches
- 8 core/tests/Drupal/Tests/Core/Plugin/FilteredPluginManagerTraitTest.php \Drupal\Tests\Core\Plugin\FilteredPluginManagerTraitTest
- 9 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, \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait, PhpUnitWarnings
- class \Drupal\Tests\Core\Plugin\FilteredPluginManagerTraitTest
Expanded class hierarchy of FilteredPluginManagerTraitTest
File
- core/
tests/ Drupal/ Tests/ Core/ Plugin/ FilteredPluginManagerTraitTest.php, line 17
Namespace
Drupal\Tests\Core\PluginView source
class FilteredPluginManagerTraitTest extends UnitTestCase {
/**
* @covers ::getFilteredDefinitions
* @dataProvider providerTestGetFilteredDefinitions
*/
public function testGetFilteredDefinitions($contexts, $expected) {
// 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 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
Name![]() |
Modifiers | Type | Description | Overrides |
---|---|---|---|---|
FilteredPluginManagerTraitTest:: |
public | function | Provides test data for ::testGetFilteredDefinitions(). | |
FilteredPluginManagerTraitTest:: |
public | function | @covers ::getFilteredDefinitions @dataProvider providerTestGetFilteredDefinitions | |
PhpUnitWarnings:: |
private static | property | Deprecation warnings from PHPUnit to raise with @trigger_error(). | |
PhpUnitWarnings:: |
public | function | Converts PHPUnit deprecation warnings to E_USER_DEPRECATED. | |
UnitTestCase:: |
protected | property | The random generator. | |
UnitTestCase:: |
protected | property | The app root. | 1 |
UnitTestCase:: |
protected | function | Returns a stub class resolver. | |
UnitTestCase:: |
public | function | Returns a stub config factory that behaves according to the passed array. | |
UnitTestCase:: |
public | function | Returns a stub config storage that returns the supplied configuration. | |
UnitTestCase:: |
protected | function | Sets up a container with a cache tags invalidator. | |
UnitTestCase:: |
protected | function | Gets the random generator for the utility methods. | |
UnitTestCase:: |
public | function | Returns a stub translation manager that just returns the passed string. | |
UnitTestCase:: |
public | function | Generates a unique random string containing letters and numbers. | |
UnitTestCase:: |
protected | function | 206 | |
UnitTestCase:: |
public static | function |