class FilteredPluginManagerTraitTest
Same name in other branches
- 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
- 11.x 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\Traits\PhpUnitWarnings, \Drupal\Tests\PhpUnitCompatibilityTrait, \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait
- 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 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
Title Sort descending | Deprecated | Modifiers | Object type | Summary | Overrides |
---|---|---|---|---|---|
FilteredPluginManagerTraitTest::providerTestGetFilteredDefinitions | public | function | Provides test data for ::testGetFilteredDefinitions(). | ||
FilteredPluginManagerTraitTest::testGetFilteredDefinitions | public | function | @covers ::getFilteredDefinitions @dataProvider providerTestGetFilteredDefinitions |
||
PhpUnitWarnings::$deprecationWarnings | private static | property | Deprecation warnings from PHPUnit to raise with @trigger_error(). | ||
PhpUnitWarnings::addWarning | public | function | Converts PHPUnit deprecation warnings to E_USER_DEPRECATED. | ||
UnitTestCase::$randomGenerator | protected | property | The random generator. | ||
UnitTestCase::$root | protected | property | The app root. | 1 | |
UnitTestCase::assertArrayEquals | Deprecated | protected | function | Asserts if two arrays are equal by sorting them first. | |
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::getRandomGenerator | protected | function | Gets the random generator for the utility methods. | ||
UnitTestCase::getStringTranslationStub | public | function | Returns a stub translation manager that just returns the passed string. | ||
UnitTestCase::randomMachineName | public | function | Generates a unique random string containing letters and numbers. | ||
UnitTestCase::setUp | protected | function | 338 | ||
UnitTestCase::setUpBeforeClass | public static | function |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.