public function TermContextTest::testGetRuntimeContexts in Drupal 10
Same name and namespace in other branches
- 9 core/modules/taxonomy/tests/src/Kernel/ContextProvider/TermContextTest.php \Drupal\Tests\taxonomy\Kernel\ContextProvider\TermContextTest::testGetRuntimeContexts()
@covers ::getRuntimeContexts
File
- core/
modules/ taxonomy/ tests/ src/ Kernel/ ContextProvider/ TermContextTest.php, line 50
Class
- TermContextTest
- @coversDefaultClass \Drupal\taxonomy\ContextProvider\TermRouteContext
Namespace
Drupal\Tests\taxonomy\Kernel\ContextProviderCode
public function testGetRuntimeContexts() {
// Create term.
$vocabulary = $this
->createVocabulary();
$term = $this
->createTerm($vocabulary);
// Create RouteMatch from term entity.
$url = $term
->toUrl();
$route_provider = \Drupal::service('router.route_provider');
$route = $route_provider
->getRouteByName($url
->getRouteName());
$route_match = new RouteMatch($url
->getRouteName(), $route, [
'taxonomy_term' => $term,
]);
// Initiate TermRouteContext with RouteMatch.
$provider = new TermRouteContext($route_match);
$runtime_contexts = $provider
->getRuntimeContexts([]);
$this
->assertArrayHasKey('taxonomy_term', $runtime_contexts);
$this
->assertTrue($runtime_contexts['taxonomy_term']
->hasContextValue());
}