You are here

public function SiteMapCategoriesTest::testCategoryCountThreshold in Site map 8

Tests category count threshold.

This test case will not pass. We need to port the patch from https://www.drupal.org/node/1593570 to drupal 8.

See also

https://www.drupal.org/node/1348022

File

src/Tests/SiteMapCategoriesTest.php, line 175

Class

SiteMapCategoriesTest
Test case class for site map categories tests.

Namespace

Drupal\site_map\Tests

Code

public function testCategoryCountThreshold() {
  $terms = $this
    ->createTerms($this->vocabulary);
  $tags = array();

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

  // Assert that no tags are listed in the site map.
  $this
    ->drupalGet('sitemap');
  foreach ($tags as $tag) {
    $this
      ->assertNoText($tag);
  }

  // Create dummy node, assign it to tag 1 and tag 3. Current structure is:
  // + tag 1 (1)
  // |-- tag 2 (0)
  // |---- tag 3 (1)
  $this
    ->createNode(array(
    $tags[0],
    $tags[2],
  ));

  // Change category count threshold to -1.
  $edit = array(
    'term_threshold' => -1,
  );
  $this
    ->drupalPostForm('admin/config/search/sitemap', $edit, t('Save configuration'));

  // Assert that all tags are listed in the site map.
  $this
    ->drupalGet('sitemap');
  $this
    ->assertLink($tags[0]);
  $this
    ->assertNoLink($tags[1]);
  $this
    ->assertText($tags[1]);
  $this
    ->assertLink($tags[2]);

  // Change category count threshold to 0.
  $edit = array(
    'term_threshold' => 0,
  );
  $this
    ->drupalPostForm('admin/config/search/sitemap', $edit, t('Save configuration'));

  // Assert that all tags are listed in the site map.
  $this
    ->drupalGet('sitemap');
  $this
    ->assertLink($tags[0]);
  $this
    ->assertNoText($tags[1]);
  $this
    ->assertNoText($tags[2]);

  // Change category count threshold to 1.
  $edit = array(
    'term_threshold' => 1,
  );
  $this
    ->drupalPostForm('admin/config/search/sitemap', $edit, t('Save configuration'));

  // Assert that only tag 1 is listed in the site map.
  $this
    ->drupalGet('sitemap');
  foreach ($tags as $tag) {
    $this
      ->assertNoText($tag);
  }

  // Assign node to tag 2. Current structure is:
  // + tag 1 (2)
  // |-- tag 2 (1)
  // |---- tag 3 (2)
  $this
    ->createNode($tags);

  // Assert that all tags are listed in the site map.
  $this
    ->drupalGet('sitemap');
  $this
    ->assertLink($tags[0]);
  $this
    ->assertNoText($tags[1]);
  $this
    ->assertNoText($tags[2]);

  // Change category count threshold to 2.
  $edit = array(
    'term_threshold' => 2,
  );
  $this
    ->drupalPostForm('admin/config/search/sitemap', $edit, t('Save configuration'));

  // Assert that no tags are listed in the site map.
  $this
    ->drupalGet('sitemap');
  foreach ($tags as $tag) {
    $this
      ->assertNoText($tag);
  }
}