View source
<?php
namespace Drupal\site_map\Tests;
class SiteMapCategoriesTest extends SiteMapTestBase {
protected function setUp() {
parent::setUp();
$this->tags = $this
->getTags();
$this->vocabulary = $this
->createVocabulary();
$this->field_tags_name = $this
->createTaxonomyTermReferenceField($this->vocabulary);
$vid = $this->vocabulary
->id();
$edit = array(
"show_vocabularies[{$vid}]" => $vid,
);
$this
->drupalPostForm('admin/config/search/sitemap', $edit, t('Save configuration'));
}
public function testCategoryDescription() {
$this
->drupalGet('/sitemap');
$this
->assertText($this->vocabulary->description, 'Category description is included.');
$edit = array(
'show_description' => FALSE,
);
$this
->drupalPostForm('admin/config/search/sitemap', $edit, t('Save configuration'));
$this
->drupalGet('/sitemap');
$this
->assertNoText($this->vocabulary->description, 'Category description is not included.');
}
public function testNodeCountsByCategory() {
$title = $this
->randomString();
$edit = array(
'title[0][value]' => $title,
'menu[enabled]' => TRUE,
'menu[title]' => $title,
$this->field_tags_name => implode(',', $this->tags),
);
$this
->drupalPostForm('node/add/article', $edit, t('Save and publish'));
$this
->drupalGet('/sitemap');
$this
->assertEqual(substr_count($this
->getTextContent(), '(1)'), 3, 'Node counts are included');
$edit = array(
'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 testCategoriesDepth() {
$terms = $this
->createTerms($this->vocabulary);
$tags = array();
foreach ($terms as $term) {
$tags[] = $term
->label();
}
$this
->drupalGet('sitemap');
foreach ($tags as $tag) {
$this
->assertNoLink($tag);
}
$title = $this
->randomString();
$edit = array(
'title[0][value]' => $title,
'menu[enabled]' => TRUE,
'menu[title]' => $title,
$this->field_tags_name => implode(',', $tags),
);
$this
->drupalPostForm('node/add/article', $edit, t('Save and publish'));
$edit = array(
'vocabulary_depth' => -1,
);
$this
->drupalPostForm('admin/config/search/sitemap', $edit, t('Save configuration'));
$this
->drupalGet('sitemap');
foreach ($tags as $tag) {
$this
->assertLink($tag);
}
$edit = array(
'vocabulary_depth' => 0,
);
$this
->drupalPostForm('admin/config/search/sitemap', $edit, t('Save configuration'));
$this
->drupalGet('sitemap');
foreach ($tags as $tag) {
$this
->assertNoLink($tag);
}
$edit = array(
'vocabulary_depth' => 1,
);
$this
->drupalPostForm('admin/config/search/sitemap', $edit, t('Save configuration'));
$this
->drupalGet('sitemap');
$this
->assertLink($tags[0]);
$this
->assertNoLink($tags[1]);
$this
->assertNoLink($tags[2]);
$edit = array(
'vocabulary_depth' => 2,
);
$this
->drupalPostForm('admin/config/search/sitemap', $edit, t('Save configuration'));
$this
->drupalGet('sitemap');
$this
->assertLink($tags[0]);
$this
->assertLink($tags[1]);
$this
->assertNoLink($tags[2]);
$edit = array(
'vocabulary_depth' => 3,
);
$this
->drupalPostForm('admin/config/search/sitemap', $edit, t('Save configuration'));
$this
->drupalGet('sitemap');
foreach ($tags as $tag) {
$this
->assertLink($tag);
}
}
public function testCategoryCountThreshold() {
$terms = $this
->createTerms($this->vocabulary);
$tags = array();
foreach ($terms as $term) {
$tags[] = $term
->label();
}
$this
->drupalGet('sitemap');
foreach ($tags as $tag) {
$this
->assertNoText($tag);
}
$this
->createNode(array(
$tags[0],
$tags[2],
));
$edit = array(
'term_threshold' => -1,
);
$this
->drupalPostForm('admin/config/search/sitemap', $edit, t('Save configuration'));
$this
->drupalGet('sitemap');
$this
->assertLink($tags[0]);
$this
->assertNoLink($tags[1]);
$this
->assertText($tags[1]);
$this
->assertLink($tags[2]);
$edit = array(
'term_threshold' => 0,
);
$this
->drupalPostForm('admin/config/search/sitemap', $edit, t('Save configuration'));
$this
->drupalGet('sitemap');
$this
->assertLink($tags[0]);
$this
->assertNoText($tags[1]);
$this
->assertNoText($tags[2]);
$edit = array(
'term_threshold' => 1,
);
$this
->drupalPostForm('admin/config/search/sitemap', $edit, t('Save configuration'));
$this
->drupalGet('sitemap');
foreach ($tags as $tag) {
$this
->assertNoText($tag);
}
$this
->createNode($tags);
$this
->drupalGet('sitemap');
$this
->assertLink($tags[0]);
$this
->assertNoText($tags[1]);
$this
->assertNoText($tags[2]);
$edit = array(
'term_threshold' => 2,
);
$this
->drupalPostForm('admin/config/search/sitemap', $edit, t('Save configuration'));
$this
->drupalGet('sitemap');
foreach ($tags as $tag) {
$this
->assertNoText($tag);
}
}
protected function createNode($tags = array()) {
$title = $this
->randomString();
$edit = array(
'title[0][value]' => $title,
'menu[title]' => $title,
$this->field_tags_name => implode(',', $tags),
);
$this
->drupalPostForm('node/add/article', $edit, t('Save and publish'));
}
}