You are here

public function SiteMapContentTest::testCategories in Site map 8

Tests categories.

File

src/Tests/SiteMapContentTest.php, line 167

Class

SiteMapContentTest
Test case class for site map's content tests.

Namespace

Drupal\site_map\Tests

Code

public function testCategories() {
  $tags = $this
    ->getTags();
  $vocabulary = $this
    ->createVocabulary();
  $field_tags_name = $this
    ->createTaxonomyTermReferenceField($vocabulary);

  // Assert that the category is not included in the site map by default.
  $this
    ->drupalGet('/sitemap');
  $elements = $this
    ->cssSelect(".site-map-box h2:contains('" . $vocabulary
    ->label() . "')");
  $this
    ->assertEqual(count($elements), 0, 'Tags category is not included.');

  // Assert that no tags are listed in the site map.
  foreach ($tags as $tag) {
    $this
      ->assertNoLink($tag);
  }

  // Configure module to show categories.
  $vid = $vocabulary
    ->id();
  $edit = array(
    "show_vocabularies[{$vid}]" => $vid,
  );
  $this
    ->drupalPostForm('admin/config/search/sitemap', $edit, t('Save configuration'));

  // Create dummy node.
  $title = $this
    ->randomString();
  $edit = array(
    'title[0][value]' => $title,
    'menu[enabled]' => TRUE,
    'menu[title]' => $title,
    $field_tags_name => implode(',', $tags),
  );
  $this
    ->drupalPostForm('node/add/article', $edit, t('Save and publish'));

  // Assert that the category is included in the site map.
  $this
    ->drupalGet('sitemap');
  $elements = $this
    ->cssSelect(".site-map-box h2:contains('" . $vocabulary
    ->label() . "')");
  $this
    ->assertEqual(count($elements), 1, 'Tags category is included.');

  // Assert that all tags are listed in the site map.
  foreach ($tags as $tag) {
    $this
      ->assertLink($tag);
  }
}