You are here

public function SitemapTaxonomyTermsRssTest::testRssFeedDepth in Sitemap 8

Same name and namespace in other branches
  1. 8.2 src/Tests/SitemapTaxonomyTermsRssTest.php \Drupal\sitemap\Tests\SitemapTaxonomyTermsRssTest::testRssFeedDepth()
  2. 2.0.x 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() {
  $terms = $this->terms;

  // Set RSS feed depth to -1.
  $edit = [
    'rss_taxonomy' => -1,
  ];
  $this
    ->drupalPostForm('admin/config/search/sitemap', $edit, t('Save configuration'));

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

  // Change RSS feed depth to 0.
  $edit = [
    'rss_taxonomy' => 0,
  ];
  $this
    ->drupalPostForm('admin/config/search/sitemap', $edit, t('Save configuration'));

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

  // Change RSS feed depth to 1.
  $edit = [
    'rss_taxonomy' => 1,
  ];
  $this
    ->drupalPostForm('admin/config/search/sitemap', $edit, t('Save configuration'));

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

  // Change RSS feed depth to 2.
  $edit = [
    'rss_taxonomy' => 2,
  ];
  $this
    ->drupalPostForm('admin/config/search/sitemap', $edit, t('Save configuration'));

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

  // Change RSS feed depth to 3.
  $edit = [
    'rss_taxonomy' => 3,
  ];
  $this
    ->drupalPostForm('admin/config/search/sitemap', $edit, t('Save configuration'));

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