You are here

public function TaxonomyIndexTidUiTest::testExposedUnpublishedFilterOptions 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::testExposedUnpublishedFilterOptions()
  2. 10 core/modules/taxonomy/tests/src/Functional/Views/TaxonomyIndexTidUiTest.php \Drupal\Tests\taxonomy\Functional\Views\TaxonomyIndexTidUiTest::testExposedUnpublishedFilterOptions()

Tests that an exposed taxonomy filter doesn't show unpublished terms.

File

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

Class

TaxonomyIndexTidUiTest
Tests the taxonomy index filter handler UI.

Namespace

Drupal\Tests\taxonomy\Functional\Views

Code

public function testExposedUnpublishedFilterOptions() {
  $this->terms[1][0]
    ->setUnpublished()
    ->save();

  // Expose the filter.
  $this
    ->drupalPostForm('admin/structure/views/nojs/handler/test_filter_taxonomy_index_tid/default/filter/tid', [], 'Expose filter');
  $edit = [
    'options[expose_button][checkbox][checkbox]' => TRUE,
  ];
  $this
    ->drupalPostForm(NULL, $edit, 'Apply');
  $this
    ->drupalPostForm(NULL, [], 'Save');

  // Make sure the unpublished term is shown to the admin user.
  $this
    ->drupalGet('test-filter-taxonomy-index-tid');
  $this
    ->assertNotEmpty($this
    ->cssSelect('option[value="' . $this->terms[0][0]
    ->id() . '"]'));
  $this
    ->assertNotEmpty($this
    ->cssSelect('option[value="' . $this->terms[1][0]
    ->id() . '"]'));
  $this
    ->drupalLogout();
  $this
    ->drupalGet('test-filter-taxonomy-index-tid');

  // Make sure the unpublished term isn't shown to the anonymous user.
  $this
    ->assertNotEmpty($this
    ->cssSelect('option[value="' . $this->terms[0][0]
    ->id() . '"]'));
  $this
    ->assertEmpty($this
    ->cssSelect('option[value="' . $this->terms[1][0]
    ->id() . '"]'));

  // Tests that the term also isn't shown when not showing hierarchy.
  $this
    ->drupalLogin($this->adminUser);
  $edit = [
    'options[hierarchy]' => FALSE,
  ];
  $this
    ->drupalPostForm('admin/structure/views/nojs/handler-extra/test_filter_taxonomy_index_tid/default/filter/tid', $edit, 'Apply');
  $this
    ->drupalPostForm(NULL, [], 'Save');
  $this
    ->drupalGet('test-filter-taxonomy-index-tid');
  $this
    ->assertNotEmpty($this
    ->cssSelect('option[value="' . $this->terms[0][0]
    ->id() . '"]'));
  $this
    ->assertNotEmpty($this
    ->cssSelect('option[value="' . $this->terms[1][0]
    ->id() . '"]'));
  $this
    ->drupalLogout();
  $this
    ->drupalGet('test-filter-taxonomy-index-tid');

  // Make sure the unpublished term isn't shown to the anonymous user.
  $this
    ->assertNotEmpty($this
    ->cssSelect('option[value="' . $this->terms[0][0]
    ->id() . '"]'));
  $this
    ->assertEmpty($this
    ->cssSelect('option[value="' . $this->terms[1][0]
    ->id() . '"]'));
}