class TaxonomyFieldTidTest

Same name and namespace in other branches
  1. 11.x core/modules/taxonomy/tests/src/Kernel/Views/TaxonomyFieldTidTest.php \Drupal\Tests\taxonomy\Kernel\Views\TaxonomyFieldTidTest
  2. 10 core/modules/taxonomy/tests/src/Kernel/Views/TaxonomyFieldTidTest.php \Drupal\Tests\taxonomy\Kernel\Views\TaxonomyFieldTidTest
  3. 8.9.x core/modules/taxonomy/tests/src/Kernel/Views/TaxonomyFieldTidTest.php \Drupal\Tests\taxonomy\Kernel\Views\TaxonomyFieldTidTest

Tests the taxonomy term TID field handler.

@group taxonomy

Hierarchy

Expanded class hierarchy of TaxonomyFieldTidTest

File

core/modules/taxonomy/tests/src/Kernel/Views/TaxonomyFieldTidTest.php, line 17

Namespace

Drupal\Tests\taxonomy\Kernel\Views
View source
class TaxonomyFieldTidTest extends ViewsKernelTestBase {
  use TaxonomyTestTrait;
  
  /**
   * {@inheritdoc}
   */
  protected static $modules = [
    'taxonomy',
    'taxonomy_test_views',
    'text',
    'filter',
  ];
  
  /**
   * {@inheritdoc}
   */
  public static $testViews = [
    'test_taxonomy_tid_field',
  ];
  
  /**
   * A taxonomy term to use in this test.
   *
   * @var \Drupal\taxonomy\TermInterface
   */
  protected $term1;
  
  /**
   * {@inheritdoc}
   */
  protected function setUp($import_test_views = TRUE) : void {
    parent::setUp($import_test_views);
    $this->installEntitySchema('taxonomy_term');
    $this->installConfig([
      'filter',
    ]);
    /** @var \Drupal\taxonomy\Entity\Vocabulary $vocabulary */
    $vocabulary = $this->createVocabulary();
    $this->term1 = $this->createTerm($vocabulary);
    ViewTestData::createTestViews(static::class, [
      'taxonomy_test_views',
    ]);
  }
  
  /**
   * Tests the taxonomy field handler.
   */
  public function testViewsHandlerTidField() {
    /** @var \Drupal\Core\Render\RendererInterface $renderer */
    $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);
  }

}

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