class TermContextTest
Same name and namespace in other branches
- 11.x core/modules/taxonomy/tests/src/Kernel/ContextProvider/TermContextTest.php \Drupal\Tests\taxonomy\Kernel\ContextProvider\TermContextTest
- 10 core/modules/taxonomy/tests/src/Kernel/ContextProvider/TermContextTest.php \Drupal\Tests\taxonomy\Kernel\ContextProvider\TermContextTest
@coversDefaultClass \Drupal\taxonomy\ContextProvider\TermRouteContext
@group taxonomy
Hierarchy
- class \Drupal\KernelTests\KernelTestBase implements \Drupal\Core\DependencyInjection\ServiceProviderInterface uses \Drupal\KernelTests\AssertLegacyTrait, \Drupal\KernelTests\AssertContentTrait, \Drupal\Tests\RandomGeneratorTrait, \Drupal\Tests\ConfigTestTrait, \Drupal\Tests\ExtensionListTestTrait, \Drupal\Tests\TestRequirementsTrait, \Drupal\Tests\Traits\PhpUnitWarnings, \Drupal\Tests\PhpUnitCompatibilityTrait, \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait extends \PHPUnit\Framework\TestCase
- class \Drupal\Tests\taxonomy\Kernel\ContextProvider\TermContextTest uses \Drupal\Tests\taxonomy\Traits\TaxonomyTestTrait extends \Drupal\KernelTests\KernelTestBase
Expanded class hierarchy of TermContextTest
File
-
core/
modules/ taxonomy/ tests/ src/ Kernel/ ContextProvider/ TermContextTest.php, line 15
Namespace
Drupal\Tests\taxonomy\Kernel\ContextProviderView source
class TermContextTest extends KernelTestBase {
use TaxonomyTestTrait;
/**
* {@inheritdoc}
*/
protected static $modules = [
'filter',
'taxonomy',
'text',
'user',
];
/**
* {@inheritdoc}
*/
protected function setUp() : void {
parent::setUp();
$this->installConfig([
'filter',
]);
$this->installEntitySchema('user');
$this->installEntitySchema('taxonomy_term');
}
/**
* @covers ::getAvailableContexts
*/
public function testGetAvailableContexts() {
$context_repository = $this->container
->get('context.repository');
// Test taxonomy_term.taxonomy_term_route_context:taxonomy_term exists.
$contexts = $context_repository->getAvailableContexts();
$this->assertArrayHasKey('@taxonomy_term.taxonomy_term_route_context:taxonomy_term', $contexts);
$this->assertSame('entity:taxonomy_term', $contexts['@taxonomy_term.taxonomy_term_route_context:taxonomy_term']->getContextDefinition()
->getDataType());
}
/**
* @covers ::getRuntimeContexts
*/
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());
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.