function TermContextTest::testGetRuntimeContexts

Same name in other branches
  1. 9 core/modules/taxonomy/tests/src/Kernel/ContextProvider/TermContextTest.php \Drupal\Tests\taxonomy\Kernel\ContextProvider\TermContextTest::testGetRuntimeContexts()
  2. 10 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 52

Class

TermContextTest
@coversDefaultClass \Drupal\taxonomy\ContextProvider\TermRouteContext

Namespace

Drupal\Tests\taxonomy\Kernel\ContextProvider

Code

public function testGetRuntimeContexts() : void {
    // 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());
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.