public function SitemapTaxonomyTermsTest::testTermThreshold in Sitemap 8
Same name and namespace in other branches
- 8.2 src/Tests/SitemapTaxonomyTermsTest.php \Drupal\sitemap\Tests\SitemapTaxonomyTermsTest::testTermThreshold()
- 2.0.x src/Tests/SitemapTaxonomyTermsTest.php \Drupal\sitemap\Tests\SitemapTaxonomyTermsTest::testTermThreshold()
Tests the term_threshold setting.
File
- src/
Tests/ SitemapTaxonomyTermsTest.php, line 26
Class
- SitemapTaxonomyTermsTest
- Tests the display of taxonomies based on sitemap settings.
Namespace
Drupal\sitemap\TestsCode
public function testTermThreshold() {
// Get term names from terms.
$names = [];
foreach ($this->terms as $term) {
$names[] = $term
->label();
}
// Confirm that terms without content are not displayed by default.
$this
->drupalGet('sitemap');
foreach ($names as $term_name) {
$this
->assertNoText($term_name);
}
// Show all taxonomy terms, even if they are not assigned to any nodes.
$edit = [
'term_threshold' => -1,
];
$this
->drupalPostForm('admin/config/search/sitemap', $edit, t('Save configuration'));
// Assert that terms without nodes are now displayed on the sitemap.
$this
->drupalGet('sitemap');
foreach ($names as $term_name) {
$this
->assertText($term_name);
$this
->assertNoLink($term_name);
}
// Create test node with terms.
$this
->createNodeWithTerms($this->terms);
drupal_flush_all_caches();
// Assert that terms with content are displayed on the sitemap as links when
// term_threshold is set to -1.
$this
->drupalGet('sitemap');
foreach ($names as $term_name) {
$this
->assertLink($term_name);
}
// Require at least one node for taxonomy terms to show up.
$edit = [
'term_threshold' => 0,
];
$this
->drupalPostForm('admin/config/search/sitemap', $edit, t('Save configuration'));
// 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.
$edit = [
'term_threshold' => 1,
];
$this
->drupalPostForm('admin/config/search/sitemap', $edit, t('Save configuration'));
$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());
}