View source
<?php
namespace Drupal\site_map\Tests;
use Drupal\Component\Utility\Unicode;
class SiteMapRssTest extends SiteMapTestBase {
protected function setUp() {
parent::setUp();
$this->vocabulary = $this
->createVocabulary();
$this->field_tags_name = $this
->createTaxonomyTermReferenceField($this->vocabulary);
$vid = $this->vocabulary
->id();
$edit = array(
"show_vocabularies[{$vid}]" => $vid,
);
$this
->drupalPostForm('admin/config/search/sitemap', $edit, t('Save configuration'));
}
public function testRssFeedForFrontPage() {
$this
->drupalGet('/sitemap');
$this
->assertLinkByHref('/rss.xml');
$href = Unicode::strtolower($this
->randomMachineName());
$edit = array(
'rss_front' => $href,
);
$this
->drupalPostForm('admin/config/search/sitemap', $edit, t('Save configuration'));
$this
->drupalGet('/sitemap');
$this
->assertLinkByHref('/' . $href);
}
public function testIncludeRssLinks() {
$terms = $this
->createTerms($this->vocabulary);
$feed = '/taxonomy/term/@term/feed';
$tags = array();
foreach ($terms as $term) {
$tags[] = $term
->label();
}
$title = $this
->randomString();
$edit = array(
'title[0][value]' => $title,
'menu[enabled]' => TRUE,
'menu[title]' => $title,
$this->field_tags_name => implode(',', $tags),
);
$this
->drupalPostForm('node/add/article', $edit, t('Save and publish'));
$this
->drupalGet('/sitemap');
$this
->assertLinkByHref('/rss.xml');
foreach ($terms as $term) {
$this
->assertLinkByHref(format_string($feed, array(
'@term' => $term
->id(),
)));
}
$edit = array(
'show_rss_links' => 0,
);
$this
->drupalPostForm('admin/config/search/sitemap', $edit, t('Save configuration'));
$this
->drupalGet('/sitemap');
$this
->assertNoLinkByHref('/rss.xml');
foreach ($terms as $term) {
$this
->assertNoLinkByHref(format_string($feed, array(
'@term' => $term
->id(),
)));
}
}
public function testRssFeedDepth() {
$terms = $this
->createTerms($this->vocabulary);
$feed = '/taxonomy/term/@term/feed';
$tags = array();
foreach ($terms as $term) {
$tags[] = $term
->label();
}
$this
->drupalGet('sitemap');
foreach ($terms as $term) {
$this
->assertNoLinkByHref(format_string($feed, array(
'@term' => $term
->id(),
)));
}
$title = $this
->randomString();
$edit = array(
'title[0][value]' => $title,
'menu[enabled]' => TRUE,
'menu[title]' => $title,
$this->field_tags_name => implode(',', $tags),
);
$this
->drupalPostForm('node/add/article', $edit, t('Save and publish'));
$edit = array(
'rss_depth' => -1,
);
$this
->drupalPostForm('admin/config/search/sitemap', $edit, t('Save configuration'));
$this
->drupalGet('sitemap');
foreach ($terms as $term) {
$this
->assertLinkByHref(format_string($feed, array(
'@term' => $term
->id(),
)));
}
$edit = array(
'rss_depth' => 0,
);
$this
->drupalPostForm('admin/config/search/sitemap', $edit, t('Save configuration'));
$this
->drupalGet('sitemap');
foreach ($terms as $term) {
$this
->assertNoLinkByHref(format_string($feed, array(
'@term' => $term
->id(),
)));
}
$edit = array(
'rss_depth' => 1,
);
$this
->drupalPostForm('admin/config/search/sitemap', $edit, t('Save configuration'));
$this
->drupalGet('sitemap');
$this
->assertLinkByHref(format_string($feed, array(
'@term' => $terms[0]
->id(),
)));
$this
->assertNoLinkByHref(format_string($feed, array(
'@term' => $terms[1]
->id(),
)));
$this
->assertNoLinkByHref(format_string($feed, array(
'@term' => $terms[2]
->id(),
)));
$edit = array(
'rss_depth' => 2,
);
$this
->drupalPostForm('admin/config/search/sitemap', $edit, t('Save configuration'));
$this
->drupalGet('sitemap');
$this
->assertLinkByHref(format_string($feed, array(
'@term' => $terms[0]
->id(),
)));
$this
->assertLinkByHref(format_string($feed, array(
'@term' => $terms[1]
->id(),
)));
$this
->assertNoLinkByHref(format_string($feed, array(
'@term' => $terms[2]
->id(),
)));
$edit = array(
'rss_depth' => 3,
);
$this
->drupalPostForm('admin/config/search/sitemap', $edit, t('Save configuration'));
$this
->drupalGet('sitemap');
foreach ($terms as $term) {
$this
->assertLinkByHref(format_string($feed, array(
'@term' => $term
->id(),
)));
}
}
}