You are here

public function SitemapTaxonomyTermsRssTest::testRssFeedDepth in Sitemap 2.0.x

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

Tests RSS feed depth.

File

src/Tests/SitemapTaxonomyTermsRssTest.php, line 64

Class

SitemapTaxonomyTermsRssTest
Tests the display of RSS links based on sitemap settings.

Namespace

Drupal\sitemap\Tests

Code

public function testRssFeedDepth() {

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

  // Create terms.
  $this->terms = $this
    ->createNestedTerms($vocab);

  // Assert that RSS links are not included by default.
  $this
    ->drupalGet('sitemap');
  foreach ($this->terms as $term) {
    $this
      ->assertNoLinkByHref('/taxonomy/term/' . $term
      ->id() . '/feed');
  }

  // Set RSS feed depth to maximum.
  $this
    ->saveSitemapForm([
    "plugins[vocabulary:{$vid}][settings][enable_rss]" => TRUE,
  ]);
  $this
    ->saveSitemapForm([
    "plugins[vocabulary:{$vid}][settings][rss_depth]" => 9,
  ]);

  // Assert that all RSS links are included in the sitemap.
  $this
    ->drupalGet('sitemap');
  foreach ($this->terms as $term) {
    $this
      ->assertLinkByHref('/taxonomy/term/' . $term
      ->id() . '/feed');
  }

  // Change RSS feed depth to 0.
  $this
    ->saveSitemapForm([
    "plugins[vocabulary:{$vid}][settings][rss_depth]" => 0,
  ]);

  // Assert that RSS links are not included in the sitemap.
  $this
    ->drupalGet('sitemap');
  foreach ($this->terms as $term) {
    $this
      ->assertNoLinkByHref('/taxonomy/term/' . $term
      ->id() . '/feed');
  }

  // Change RSS feed depth to 1.
  $this
    ->saveSitemapForm([
    "plugins[vocabulary:{$vid}][settings][rss_depth]" => 1,
  ]);

  // Assert that only RSS feed link for term 1 is included in the sitemap.
  $this
    ->drupalGet('sitemap');
  $this
    ->assertLinkByHref('/taxonomy/term/' . $this->terms[0]
    ->id() . '/feed');
  $this
    ->assertNoLinkByHref('/taxonomy/term/' . $this->terms[1]
    ->id() . '/feed');
  $this
    ->assertNoLinkByHref('/taxonomy/term/' . $this->terms[2]
    ->id() . '/feed');

  // Change RSS feed depth to 2.
  $this
    ->saveSitemapForm([
    "plugins[vocabulary:{$vid}][settings][rss_depth]" => 2,
  ]);

  // Assert that RSS feed link for term 1 and term 2 is included in the site
  // map.
  $this
    ->drupalGet('sitemap');
  $this
    ->assertLinkByHref('/taxonomy/term/' . $this->terms[0]
    ->id() . '/feed');
  $this
    ->assertLinkByHref('/taxonomy/term/' . $this->terms[1]
    ->id() . '/feed');
  $this
    ->assertNoLinkByHref('/taxonomy/term/' . $this->terms[2]
    ->id() . '/feed');

  // Change RSS feed depth to 3.
  $this
    ->saveSitemapForm([
    "plugins[vocabulary:{$vid}][settings][rss_depth]" => 3,
  ]);

  // Assert that all RSS links are included in the sitemap.
  $this
    ->drupalGet('sitemap');
  foreach ($this->terms as $term) {
    $this
      ->assertLinkByHref('/taxonomy/term/' . $term
      ->id() . '/feed');
  }

  // Change disable RSS links.
  $this
    ->saveSitemapForm([
    "plugins[vocabulary:{$vid}][settings][enable_rss]" => FALSE,
  ]);
  $this
    ->saveSitemapForm([
    "plugins[vocabulary:{$vid}][settings][rss_depth]" => 9,
  ]);

  // Assert that RSS links are not included in the sitemap.
  $this
    ->drupalGet('sitemap');
  foreach ($this->terms as $term) {
    $this
      ->assertNoLinkByHref('/taxonomy/term/' . $term
      ->id() . '/feed');
  }
}