TaxonomyFieldTidTest.php in Drupal 10
File
core/modules/taxonomy/tests/src/Kernel/Views/TaxonomyFieldTidTest.php
View source
<?php
namespace Drupal\Tests\taxonomy\Kernel\Views;
use Drupal\Core\Link;
use Drupal\Core\Render\RenderContext;
use Drupal\Tests\taxonomy\Traits\TaxonomyTestTrait;
use Drupal\Tests\views\Kernel\ViewsKernelTestBase;
use Drupal\views\Tests\ViewTestData;
use Drupal\views\Views;
class TaxonomyFieldTidTest extends ViewsKernelTestBase {
use TaxonomyTestTrait;
protected static $modules = [
'taxonomy',
'taxonomy_test_views',
'text',
'filter',
];
public static $testViews = [
'test_taxonomy_tid_field',
];
protected $term1;
protected function setUp($import_test_views = TRUE) : void {
parent::setUp($import_test_views);
$this
->installEntitySchema('taxonomy_term');
$this
->installConfig([
'filter',
]);
$vocabulary = $this
->createVocabulary();
$this->term1 = $this
->createTerm($vocabulary);
ViewTestData::createTestViews(static::class, [
'taxonomy_test_views',
]);
}
public function testViewsHandlerTidField() {
$renderer = \Drupal::service('renderer');
$view = Views::getView('test_taxonomy_tid_field');
$this
->executeView($view);
$actual = $renderer
->executeInRenderContext(new RenderContext(), function () use ($view) {
return $view->field['name']
->advancedRender($view->result[0]);
});
$expected = Link::fromTextAndUrl($this->term1
->label(), $this->term1
->toUrl());
$this
->assertEquals($expected
->toString(), $actual);
}
}