You are here

public function SitemapTaxonomyTermsTest::testNodeCounts in Sitemap 2.0.x

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

Tests appearance of node counts.

File

src/Tests/SitemapTaxonomyTermsTest.php, line 72

Class

SitemapTaxonomyTermsTest
Tests the display of taxonomies based on sitemap settings.

Namespace

Drupal\sitemap\Tests

Code

public function testNodeCounts() {
  $this->terms = $this
    ->createTerms($this->vocabulary);

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

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

  // Assert that node counts are not included in the sitemap by default.
  $this
    ->drupalGet('/sitemap');
  $elements = $this
    ->cssSelect(".sitemap-plugin--vocabulary .count:contains('(1)')");
  $this
    ->assertEqual(count($elements), 0, 'Node counts not included.');

  // Configure module to display node counts.
  $this
    ->saveSitemapForm([
    "plugins[vocabulary:{$vid}][settings][show_count]" => TRUE,
  ]);

  // Assert that node counts are included in the sitemap.
  $this
    ->drupalGet('sitemap');
  $elements = $this
    ->cssSelect(".sitemap-plugin--vocabulary .count:contains('(1)')");
  $this
    ->assertEqual(count($elements), 3, 'Node counts included.');

  // TODO: Add another node and check counts.

  //@TODO: Test count display when parent term does not meet threshold.
}