SitemapTaxonomyTermsTest.php in Sitemap 8.2
File
src/Tests/SitemapTaxonomyTermsTest.php
View source
<?php
namespace Drupal\sitemap\Tests;
use Drupal\sitemap\Plugin\Sitemap\Vocabulary;
class SitemapTaxonomyTermsTest extends SitemapTaxonomyTestBase {
public function testTermThreshold() {
$this->terms = $this
->createTerms($this->vocabulary);
$vocab = $this->vocabulary;
$vid = $vocab
->id();
$names = [];
foreach ($this->terms as $term) {
$names[] = $term
->label();
}
$this
->drupalGet('/sitemap');
foreach ($names as $term_name) {
$this
->assertSession()
->pageTextContains($term_name);
}
$this
->createNodeWithTerms($this->terms);
drupal_flush_all_caches();
$this
->saveSitemapForm([
"plugins[vocabulary:{$vid}][settings][term_count_threshold]" => 1,
]);
$this
->drupalGet('sitemap');
foreach ($names as $term_name) {
$this
->assertSession()
->linkExists($term_name);
}
$this
->saveSitemapForm([
"plugins[vocabulary:{$vid}][settings][term_count_threshold]" => 2,
]);
$terms = $this->terms;
unset($terms[0]);
$this
->createNodeWithTerms($terms);
$this
->drupalGet('sitemap');
$this
->assertSession()
->linkNotExists($this->terms[0]
->label());
$this
->assertSession()
->linkExists($this->terms[1]
->label());
$this
->assertSession()
->linkExists($this->terms[2]
->label());
}
public function testNodeCounts() {
$this->terms = $this
->createTerms($this->vocabulary);
$vocab = $this->vocabulary;
$vid = $vocab
->id();
$this
->createNodeWithTerms($this->terms);
$this
->drupalGet('/sitemap');
$elements = $this
->cssSelect(".sitemap-plugin--vocabulary .count:contains('(1)')");
$this
->assertEquals(count($elements), 0, 'Node counts not included.');
$this
->saveSitemapForm([
"plugins[vocabulary:{$vid}][settings][show_count]" => TRUE,
]);
$this
->drupalGet('sitemap');
$elements = $this
->cssSelect(".sitemap-plugin--vocabulary .count:contains('(1)')");
$this
->assertEquals(count($elements), 3, 'Node counts included.');
}
public function testVocabularyDepth() {
$this->terms = $this
->createNestedTerms($this->vocabulary);
$vid = $this->vocabulary
->id();
$this
->saveSitemapForm([
"plugins[vocabulary:{$vid}][settings][term_count_threshold]" => Vocabulary::THRESHOLD_DISABLED,
]);
$this
->saveSitemapForm([
"plugins[vocabulary:{$vid}][settings][term_depth]" => Vocabulary::DEPTH_MAX,
]);
$this
->drupalGet('/sitemap');
foreach ($this->terms as $term) {
$this
->assertSession()
->pageTextContains($term
->label());
}
$this
->saveSitemapForm([
"plugins[vocabulary:{$vid}][settings][term_depth]" => Vocabulary::DEPTH_DISABLED,
]);
$this
->drupalGet('/sitemap');
foreach ($this->terms as $term) {
$this
->assertSession()
->pageTextNotContains($term
->label());
}
$this
->saveSitemapForm([
"plugins[vocabulary:{$vid}][settings][term_depth]" => 1,
]);
$this
->drupalGet('/sitemap');
$this
->assertSession()
->pageTextContains($this->terms[0]
->label());
$this
->assertSession()
->pageTextNotContains($this->terms[1]
->label());
$this
->assertSession()
->pageTextNotContains($this->terms[2]
->label());
$this
->saveSitemapForm([
"plugins[vocabulary:{$vid}][settings][term_depth]" => 2,
]);
$this
->drupalGet('/sitemap');
$this
->assertSession()
->pageTextContains($this->terms[0]
->label());
$this
->assertSession()
->pageTextContains($this->terms[1]
->label());
$this
->assertSession()
->pageTextNotContains($this->terms[2]
->label());
$this
->saveSitemapForm([
"plugins[vocabulary:{$vid}][settings][term_depth]" => 3,
]);
$this
->drupalGet('/sitemap');
foreach ($this->terms as $term) {
$this
->assertSession()
->pageTextContains($term
->label());
}
$this
->saveSitemapForm([
"plugins[vocabulary:{$vid}][settings][term_count_threshold]" => 1,
]);
$childTerms = $this->terms;
array_shift($childTerms);
$this
->createNodeWithTerms($childTerms);
$this
->drupalGet('/sitemap');
foreach ($this->terms as $term) {
$this
->assertSession()
->pageTextContains($term
->label());
}
$this
->saveSitemapForm([
"plugins[vocabulary:{$vid}][settings][show_count]" => TRUE,
]);
$this
->drupalGet('/sitemap');
$elements = $this
->cssSelect(".sitemap-plugin--vocabulary .count:contains('(1)')");
$this
->assertEquals(count($elements), 2, 'Node counts included.');
}
public function testTermLinks() {
$this->terms = $this
->createTerms($this->vocabulary);
$this
->linkSettingsTest();
}
public function testNestedTermLinks() {
$this->terms = $this
->createNestedTerms($this->vocabulary);
$this
->linkSettingsTest();
$vid = $this->vocabulary
->id();
$this
->saveSitemapForm([
"plugins[vocabulary:{$vid}][settings][term_count_threshold]" => 2,
]);
$childTerms = $this->terms;
array_shift($childTerms);
$this
->createNodeWithTerms($childTerms);
$this
->drupalGet('/sitemap');
$this
->assertSession()
->linkNotExists($this->terms[0]
->label());
foreach ($childTerms as $term) {
$this
->assertSession()
->linkExists($term
->label());
}
$vid = $this->vocabulary
->id();
$this
->saveSitemapForm([
"plugins[vocabulary:{$vid}][settings][always_link]" => TRUE,
]);
$this
->drupalGet('/sitemap');
foreach ($this->terms as $term) {
$this
->assertSession()
->linkExists($term
->label());
}
}
protected function linkSettingsTest() {
$this
->drupalGet('/sitemap');
foreach ($this->terms as $term) {
$this
->assertSession()
->linkNotExists($term
->label());
}
$vid = $this->vocabulary
->id();
$this
->saveSitemapForm([
"plugins[vocabulary:{$vid}][settings][always_link]" => TRUE,
]);
$this
->drupalGet('/sitemap');
foreach ($this->terms as $term) {
$this
->assertSession()
->linkExists($term
->label());
}
$this
->createNodeWithTerms($this->terms);
$this
->drupalGet('/sitemap');
foreach ($this->terms as $term) {
$this
->assertSession()
->linkExists($term
->label());
}
$this
->saveSitemapForm([
"plugins[vocabulary:{$vid}][settings][always_link]" => FALSE,
]);
$this
->drupalGet('/sitemap');
foreach ($this->terms as $term) {
$this
->assertSession()
->linkExists($term
->label());
}
}
}