You are here

public function TaxonomyIndexTidUiTest::testFilterUI in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/taxonomy/tests/src/Functional/Views/TaxonomyIndexTidUiTest.php \Drupal\Tests\taxonomy\Functional\Views\TaxonomyIndexTidUiTest::testFilterUI()
  2. 10 core/modules/taxonomy/tests/src/Functional/Views/TaxonomyIndexTidUiTest.php \Drupal\Tests\taxonomy\Functional\Views\TaxonomyIndexTidUiTest::testFilterUI()

Tests the filter UI.

File

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

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
    ->xpath('//select[@id="edit-options-value"]/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
        ->assertEqual($prefix . $this->terms[$i][$j]
        ->getName(), $option
        ->getText());
      $this
        ->assertEqual($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
    ->assertFieldById('edit-options-value', NULL);

  // 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
    ->assertIdentical($expected, $view
    ->calculateDependencies()
    ->getDependencies());
}