View source
<?php
namespace Drupal\sitemap\Tests;
class SitemapTaxonomyTermsTest extends SitemapTaxonomyTestBase {
protected function setUp() {
parent::setUp();
$this->terms = $this
->createTerms($this->vocabulary);
}
public function testTermThreshold() {
$names = [];
foreach ($this->terms as $term) {
$names[] = $term
->label();
}
$this
->drupalGet('sitemap');
foreach ($names as $term_name) {
$this
->assertNoText($term_name);
}
$edit = [
'term_threshold' => -1,
];
$this
->drupalPostForm('admin/config/search/sitemap', $edit, t('Save configuration'));
$this
->drupalGet('sitemap');
foreach ($names as $term_name) {
$this
->assertText($term_name);
$this
->assertNoLink($term_name);
}
$this
->createNodeWithTerms($this->terms);
drupal_flush_all_caches();
$this
->drupalGet('sitemap');
foreach ($names as $term_name) {
$this
->assertLink($term_name);
}
$edit = [
'term_threshold' => 0,
];
$this
->drupalPostForm('admin/config/search/sitemap', $edit, t('Save configuration'));
$this
->drupalGet('sitemap');
foreach ($names as $term_name) {
$this
->assertLink($term_name);
}
$edit = [
'term_threshold' => 1,
];
$this
->drupalPostForm('admin/config/search/sitemap', $edit, t('Save configuration'));
$terms = $this->terms;
unset($terms[0]);
$this
->createNodeWithTerms($terms);
$this
->drupalGet('sitemap');
$this
->assertNoLink($this->terms[0]
->label());
$this
->assertLink($this->terms[1]
->label());
$this
->assertLink($this->terms[2]
->label());
}
public function testNodeCounts() {
$this
->createNodeWithTerms($this->terms);
$this
->drupalGet('/sitemap');
$this
->assertEqual(substr_count($this
->getTextContent(), '(1)'), 3, 'Node counts are included');
$edit = [
'show_count' => FALSE,
];
$this
->drupalPostForm('admin/config/search/sitemap', $edit, t('Save configuration'));
$this
->drupalGet('sitemap');
$this
->assertEqual(substr_count($this
->getTextContent(), '(1)'), 0, 'Node counts are not included');
}
public function testVocabularyDepth() {
$edit = [
'term_threshold' => -1,
];
$this
->drupalPostForm('admin/config/search/sitemap', $edit, t('Save configuration'));
$tags = [];
foreach ($this->terms as $term) {
$tags[] = $term
->label();
}
$edit = [
'vocabulary_depth' => -1,
];
$this
->drupalPostForm('admin/config/search/sitemap', $edit, t('Save configuration'));
$this
->drupalGet('sitemap');
foreach ($tags as $tag) {
$this
->assertText($tag);
}
$edit = [
'vocabulary_depth' => 0,
];
$this
->drupalPostForm('admin/config/search/sitemap', $edit, t('Save configuration'));
$this
->drupalGet('sitemap');
foreach ($tags as $tag) {
$this
->assertNoText($tag);
}
$edit = [
'vocabulary_depth' => 1,
];
$this
->drupalPostForm('admin/config/search/sitemap', $edit, t('Save configuration'));
$this
->drupalGet('sitemap');
$this
->assertText($tags[0]);
$this
->assertNoText($tags[1]);
$this
->assertNoText($tags[2]);
$edit = [
'vocabulary_depth' => 2,
];
$this
->drupalPostForm('admin/config/search/sitemap', $edit, t('Save configuration'));
$this
->drupalGet('sitemap');
$this
->assertText($tags[0]);
$this
->assertText($tags[1]);
$this
->assertNoText($tags[2]);
$edit = [
'vocabulary_depth' => 3,
];
$this
->drupalPostForm('admin/config/search/sitemap', $edit, t('Save configuration'));
$this
->drupalGet('sitemap');
foreach ($tags as $tag) {
$this
->assertText($tag);
}
}
public function testVocabularyShowLinks() {
$edit = [
'term_threshold' => -1,
'vocabulary_depth' => -1,
];
$this
->drupalPostForm('admin/config/search/sitemap', $edit, t('Save configuration'));
$tags = [];
foreach ($this->terms as $term) {
$tags[] = $term
->label();
}
$this
->drupalGet('sitemap');
foreach ($tags as $tag) {
$this
->assertText($tag);
$this
->assertNoLink($tag);
}
$edit = [
'vocabulary_show_links' => TRUE,
];
$this
->drupalPostForm('admin/config/search/sitemap', $edit, t('Save configuration'));
$this
->drupalGet('sitemap');
foreach ($tags as $tag) {
$this
->assertLink($tag);
}
}
}