public function ContextHandlerTest::providerTestGetMatchingContexts in Drupal 8
Same name and namespace in other branches
- 9 core/tests/Drupal/Tests/Core/Plugin/ContextHandlerTest.php \Drupal\Tests\Core\Plugin\ContextHandlerTest::providerTestGetMatchingContexts()
Provides data for testGetMatchingContexts().
File
- core/
tests/ Drupal/ Tests/ Core/ Plugin/ ContextHandlerTest.php, line 142 - Contains \Drupal\Tests\Core\Plugin\ContextHandlerTest.
Class
- ContextHandlerTest
- @coversDefaultClass \Drupal\Core\Plugin\Context\ContextHandler @group Plugin
Namespace
Drupal\Tests\Core\PluginCode
public function providerTestGetMatchingContexts() {
$requirement_any = new ContextDefinition();
$requirement_specific = new ContextDefinition('string');
$requirement_specific
->setConstraints([
'Blank' => [],
]);
$context_any = $this
->createMock('Drupal\\Core\\Plugin\\Context\\ContextInterface');
$context_any
->expects($this
->atLeastOnce())
->method('getContextDefinition')
->will($this
->returnValue(new ContextDefinition('any')));
$context_constraint_mismatch = $this
->createMock('Drupal\\Core\\Plugin\\Context\\ContextInterface');
$context_constraint_mismatch
->expects($this
->atLeastOnce())
->method('getContextDefinition')
->will($this
->returnValue(new ContextDefinition('foo')));
$context_datatype_mismatch = $this
->createMock('Drupal\\Core\\Plugin\\Context\\ContextInterface');
$context_datatype_mismatch
->expects($this
->atLeastOnce())
->method('getContextDefinition')
->will($this
->returnValue(new ContextDefinition('fuzzy')));
$context_definition_specific = new ContextDefinition('string');
$context_definition_specific
->setConstraints([
'Blank' => [],
]);
$context_specific = $this
->createMock('Drupal\\Core\\Plugin\\Context\\ContextInterface');
$context_specific
->expects($this
->atLeastOnce())
->method('getContextDefinition')
->will($this
->returnValue($context_definition_specific));
$data = [];
// No context will return no valid contexts.
$data[] = [
[],
$requirement_any,
];
// A context with a generic matching requirement is valid.
$data[] = [
[
$context_any,
],
$requirement_any,
];
// A context with a specific matching requirement is valid.
$data[] = [
[
$context_specific,
],
$requirement_specific,
];
// A context with a mismatched constraint is invalid.
$data[] = [
[
$context_constraint_mismatch,
],
$requirement_specific,
[],
];
// A context with a mismatched datatype is invalid.
$data[] = [
[
$context_datatype_mismatch,
],
$requirement_specific,
[],
];
return $data;
}