You are here

public function SitemapTaxonomyTermsTest::testTermThreshold in Sitemap 8.2

Same name and namespace in other branches
  1. 8 src/Tests/SitemapTaxonomyTermsTest.php \Drupal\sitemap\Tests\SitemapTaxonomyTermsTest::testTermThreshold()
  2. 2.0.x src/Tests/SitemapTaxonomyTermsTest.php \Drupal\sitemap\Tests\SitemapTaxonomyTermsTest::testTermThreshold()

Tests the term_threshold setting.

File

src/Tests/SitemapTaxonomyTermsTest.php, line 17

Class

SitemapTaxonomyTermsTest
Tests the display of taxonomies based on sitemap settings.

Namespace

Drupal\sitemap\Tests

Code

public function testTermThreshold() {

  // Create terms.
  $this->terms = $this
    ->createTerms($this->vocabulary);

  // The vocabulary is already configured to display in parent ::setUp().
  $vocab = $this->vocabulary;
  $vid = $vocab
    ->id();

  // Get term names from terms.
  $names = [];
  foreach ($this->terms as $term) {
    $names[] = $term
      ->label();
  }

  // Confirm that terms without content are displayed by default.
  $this
    ->drupalGet('/sitemap');
  foreach ($names as $term_name) {
    $this
      ->assertSession()
      ->pageTextContains($term_name);
  }

  // Create test node with terms.
  $this
    ->createNodeWithTerms($this->terms);

  // @TODO: Figure out proper cache tags.
  drupal_flush_all_caches();

  // Require at least one node for taxonomy terms to show up.
  $this
    ->saveSitemapForm([
    "plugins[vocabulary:{$vid}][settings][term_count_threshold]" => 1,
  ]);

  // Assert that terms with content are displayed on the sitemap as links.
  $this
    ->drupalGet('sitemap');
  foreach ($names as $term_name) {
    $this
      ->assertSession()
      ->linkExists($term_name);
  }

  // Require at least two nodes for taxonomy terms to show up.
  $this
    ->saveSitemapForm([
    "plugins[vocabulary:{$vid}][settings][term_count_threshold]" => 2,
  ]);
  $terms = $this->terms;
  unset($terms[0]);

  // Create a second test node with only two terms.
  $this
    ->createNodeWithTerms($terms);
  $this
    ->drupalGet('sitemap');
  $this
    ->assertSession()
    ->linkNotExists($this->terms[0]
    ->label());
  $this
    ->assertSession()
    ->linkExists($this->terms[1]
    ->label());
  $this
    ->assertSession()
    ->linkExists($this->terms[2]
    ->label());

  // TODO: Check for empty <li>s as well.
}