function TaxonomyIndexTidUiTest::testFilterUI

Tests the filter UI.

File

core/modules/taxonomy/tests/src/Functional/Views/TaxonomyIndexTidUiTest.php, line 103

Class

TaxonomyIndexTidUiTest
Tests the taxonomy index filter handler UI.

Namespace

Drupal\Tests\taxonomy\Functional\Views

Code

public function testFilterUI() {
  $this->drupalGet('admin/structure/views/nojs/handler/test_filter_taxonomy_index_tid/default/filter/tid');
  $result = $this->assertSession()
    ->selectExists('edit-options-value')
    ->findAll('css', 'option');
  // Ensure that the expected hierarchy is available in the UI.
  $counter = 0;
  for ($i = 0; $i < 3; $i++) {
    for ($j = 0; $j <= $i; $j++) {
      $option = $result[$counter++];
      $prefix = $this->terms[$i][$j]->parent->target_id ? '-' : '';
      $tid = $option->getAttribute('value');
      $this->assertEquals($prefix . $this->terms[$i][$j]
        ->getName(), $option->getText());
      $this->assertEquals($this->terms[$i][$j]
        ->id(), $tid);
    }
  }
  // Ensure the autocomplete input element appears when using the 'textfield'
  // type.
  $view = View::load('test_filter_taxonomy_index_tid');
  $display =& $view->getDisplay('default');
  $display['display_options']['filters']['tid']['type'] = 'textfield';
  $view->save();
  $this->drupalGet('admin/structure/views/nojs/handler/test_filter_taxonomy_index_tid/default/filter/tid');
  $this->assertSession()
    ->fieldExists('edit-options-value');
  // Tests \Drupal\taxonomy\Plugin\views\filter\TaxonomyIndexTid::calculateDependencies().
  $expected = [
    'config' => [
      'taxonomy.vocabulary.tags',
    ],
    'content' => [
      'taxonomy_term:tags:' . Term::load(2)->uuid(),
    ],
    'module' => [
      'node',
      'taxonomy',
      'user',
    ],
  ];
  $this->assertSame($expected, $view->calculateDependencies()
    ->getDependencies());
}

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