public function SitemapTaxonomyTermsTest::testTermThreshold in Sitemap 2.0.x
Same name and namespace in other branches
- 8.2 src/Tests/SitemapTaxonomyTermsTest.php \Drupal\sitemap\Tests\SitemapTaxonomyTermsTest::testTermThreshold()
- 8 src/Tests/SitemapTaxonomyTermsTest.php \Drupal\sitemap\Tests\SitemapTaxonomyTermsTest::testTermThreshold()
Tests the term_threshold setting.
File
- src/
Tests/ SitemapTaxonomyTermsTest.php, line 17
Class
- SitemapTaxonomyTermsTest
- Tests the display of taxonomies based on sitemap settings.
Namespace
Drupal\sitemap\TestsCode
public function testTermThreshold() {
// Create terms.
$this->terms = $this
->createTerms($this->vocabulary);
// The vocabulary is already configured to display in parent ::setUp().
$vocab = $this->vocabulary;
$vid = $vocab
->id();
// Get term names from terms.
$names = [];
foreach ($this->terms as $term) {
$names[] = $term
->label();
}
// Confirm that terms without content are displayed by default.
$this
->drupalGet('/sitemap');
foreach ($names as $term_name) {
$this
->assertText($term_name);
}
// Create test node with terms.
$this
->createNodeWithTerms($this->terms);
// @TODO: Figure out proper cache tags.
drupal_flush_all_caches();
// Require at least one node for taxonomy terms to show up.
$this
->saveSitemapForm([
"plugins[vocabulary:{$vid}][settings][term_count_threshold]" => 1,
]);
// Assert that terms with content are displayed on the sitemap as links.
$this
->drupalGet('sitemap');
foreach ($names as $term_name) {
$this
->assertLink($term_name);
}
// Require at least two nodes for taxonomy terms to show up.
$this
->saveSitemapForm([
"plugins[vocabulary:{$vid}][settings][term_count_threshold]" => 2,
]);
$terms = $this->terms;
unset($terms[0]);
// Create a second test node with only two terms.
$this
->createNodeWithTerms($terms);
$this
->drupalGet('sitemap');
$this
->assertNoLink($this->terms[0]
->label());
$this
->assertLink($this->terms[1]
->label());
$this
->assertLink($this->terms[2]
->label());
// TODO: Check for empty <li>s as well.
}