class TaxonomyFieldVidTest
Same name and namespace in other branches
- 11.x core/modules/taxonomy/tests/src/Kernel/Views/TaxonomyFieldVidTest.php \Drupal\Tests\taxonomy\Kernel\Views\TaxonomyFieldVidTest
- 10 core/modules/taxonomy/tests/src/Kernel/Views/TaxonomyFieldVidTest.php \Drupal\Tests\taxonomy\Kernel\Views\TaxonomyFieldVidTest
- 8.9.x core/modules/taxonomy/tests/src/Kernel/Views/TaxonomyFieldVidTest.php \Drupal\Tests\taxonomy\Kernel\Views\TaxonomyFieldVidTest
Tests the taxonomy term VID field handler.
@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\views\Kernel\ViewsKernelTestBase uses \Drupal\views\Tests\ViewResultAssertionTrait extends \Drupal\KernelTests\KernelTestBase
- class \Drupal\Tests\taxonomy\Kernel\Views\TaxonomyFieldVidTest uses \Drupal\Tests\taxonomy\Traits\TaxonomyTestTrait extends \Drupal\Tests\views\Kernel\ViewsKernelTestBase
- class \Drupal\Tests\views\Kernel\ViewsKernelTestBase uses \Drupal\views\Tests\ViewResultAssertionTrait extends \Drupal\KernelTests\KernelTestBase
Expanded class hierarchy of TaxonomyFieldVidTest
File
-
core/
modules/ taxonomy/ tests/ src/ Kernel/ Views/ TaxonomyFieldVidTest.php, line 18
Namespace
Drupal\Tests\taxonomy\Kernel\ViewsView source
class TaxonomyFieldVidTest extends ViewsKernelTestBase {
use TaxonomyTestTrait;
/**
* Modules to enable.
*
* @var array
*/
protected static $modules = [
'taxonomy',
'taxonomy_test_views',
'text',
'filter',
];
/**
* Views used by this test.
*
* @var array
*/
public static $testViews = [
'test_taxonomy_vid_field',
];
/**
* A taxonomy term to use in this test.
*
* @var \Drupal\taxonomy\Entity\Term
*/
protected $term1;
/**
* An admin user.
*
* @var \Drupal\user\Entity\User
*/
protected $adminUser;
/**
* {@inheritdoc}
*/
protected function setUp($import_test_views = TRUE) : void {
parent::setUp($import_test_views);
$this->installEntitySchema('taxonomy_term');
$this->installEntitySchema('user');
$this->installConfig([
'filter',
]);
/** @var \Drupal\taxonomy\Entity\Vocabulary $vocabulary */
$vocabulary = $this->createVocabulary();
$this->term1 = $this->createTerm($vocabulary);
// Create user 1 and set is as the logged in user, so that the logged in
// user has the correct permissions to view the vocabulary name.
$this->adminUser = User::create([
'name' => $this->randomString(),
]);
$this->adminUser
->save();
$this->container
->get('current_user')
->setAccount($this->adminUser);
ViewTestData::createTestViews(static::class, [
'taxonomy_test_views',
]);
}
/**
* Tests the field handling for the Vocabulary ID.
*/
public function testViewsHandlerVidField() {
/** @var \Drupal\Core\Render\RendererInterface $renderer */
$renderer = \Drupal::service('renderer');
$view = Views::getView('test_taxonomy_vid_field');
$this->executeView($view);
$actual = $renderer->executeInRenderContext(new RenderContext(), function () use ($view) {
return $view->field['vid']
->advancedRender($view->result[0]);
});
$vocabulary = Vocabulary::load($this->term1
->bundle());
$expected = $vocabulary->get('name');
$this->assertEquals($expected, $actual);
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.