class FilteredPluginManagerTraitTest
Same name and namespace in other branches
- 9 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\PhpunitCompatibilityTrait
- 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 |
||
PhpunitCompatibilityTrait::getMock | Deprecated | public | function | Returns a mock object for the specified class using the available method. | |
PhpunitCompatibilityTrait::setExpectedException | Deprecated | public | function | Compatibility layer for PHPUnit 6 to support PHPUnit 4 code. | |
UnitTestCase::$randomGenerator | protected | property | The random generator. | ||
UnitTestCase::$root | protected | property | The app root. | 1 | |
UnitTestCase::assertArrayEquals | protected | function | Asserts if two arrays are equal by sorting them first. | ||
UnitTestCase::getBlockMockWithMachineName | Deprecated | protected | function | Mocks a block with a block plugin. | 1 |
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 | 340 |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.