public function SitemapTaxonomyTermsTest::testVocabularyDepth in Sitemap 8
Same name and namespace in other branches
- 8.2 src/Tests/SitemapTaxonomyTermsTest.php \Drupal\sitemap\Tests\SitemapTaxonomyTermsTest::testVocabularyDepth()
- 2.0.x src/Tests/SitemapTaxonomyTermsTest.php \Drupal\sitemap\Tests\SitemapTaxonomyTermsTest::testVocabularyDepth()
Tests vocabulary depth settings.
File
- src/
Tests/ SitemapTaxonomyTermsTest.php, line 119
Class
- SitemapTaxonomyTermsTest
- Tests the display of taxonomies based on sitemap settings.
Namespace
Drupal\sitemap\TestsCode
public function testVocabularyDepth() {
// Set to 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'));
// Get tags from terms.
$tags = [];
foreach ($this->terms as $term) {
$tags[] = $term
->label();
}
// Change vocabulary depth to -1.
$edit = [
'vocabulary_depth' => -1,
];
$this
->drupalPostForm('admin/config/search/sitemap', $edit, t('Save configuration'));
// Assert that all tags are listed in the sitemap.
$this
->drupalGet('sitemap');
foreach ($tags as $tag) {
$this
->assertText($tag);
}
// Change vocabulary depth to 0.
$edit = [
'vocabulary_depth' => 0,
];
$this
->drupalPostForm('admin/config/search/sitemap', $edit, t('Save configuration'));
// Assert that no tags are listed in the sitemap.
$this
->drupalGet('sitemap');
foreach ($tags as $tag) {
$this
->assertNoText($tag);
}
// Change vocabulary depth to 1.
$edit = [
'vocabulary_depth' => 1,
];
$this
->drupalPostForm('admin/config/search/sitemap', $edit, t('Save configuration'));
// Assert that only tag 1 is listed in the sitemap.
$this
->drupalGet('sitemap');
$this
->assertText($tags[0]);
$this
->assertNoText($tags[1]);
$this
->assertNoText($tags[2]);
// Change vocabulary depth to 2.
$edit = [
'vocabulary_depth' => 2,
];
$this
->drupalPostForm('admin/config/search/sitemap', $edit, t('Save configuration'));
// Assert that tag 1 and tag 2 are listed in the sitemap.
$this
->drupalGet('sitemap');
$this
->assertText($tags[0]);
$this
->assertText($tags[1]);
$this
->assertNoText($tags[2]);
// Change vocabulary depth to 3.
$edit = [
'vocabulary_depth' => 3,
];
$this
->drupalPostForm('admin/config/search/sitemap', $edit, t('Save configuration'));
// Assert that all tags are listed in the sitemap.
$this
->drupalGet('sitemap');
foreach ($tags as $tag) {
$this
->assertText($tag);
}
}