You are here

public function SitemapTaxonomyTest::testVocabularyCrud in Sitemap 2.0.x

Same name and namespace in other branches
  1. 8.2 src/Tests/SitemapTaxonomyTest.php \Drupal\sitemap\Tests\SitemapTaxonomyTest::testVocabularyCrud()

Test seamless functionality when created and deleting vocabularies.

File

src/Tests/SitemapTaxonomyTest.php, line 72

Class

SitemapTaxonomyTest
Tests the display of taxonomies based on sitemap settings.

Namespace

Drupal\sitemap\Tests

Code

public function testVocabularyCrud() {

  // Create an additional vocabulary.
  $vocabularyToDelete = $this
    ->createVocabulary();

  // Configure the sitemap to display both vocabularies.
  $vid = $this->vocabulary
    ->id();
  $vid_to_delete = $vocabularyToDelete
    ->id();
  $edit = [
    "plugins[vocabulary:{$vid}][enabled]" => TRUE,
    "plugins[vocabulary:{$vid_to_delete}][enabled]" => TRUE,
  ];
  $this
    ->saveSitemapForm($edit);

  // Ensure that both vocabularies are displayed.
  $this
    ->drupalGet('/sitemap');
  $elements = $this
    ->cssSelect(".sitemap-plugin--vocabulary");
  $this
    ->assertEqual(count($elements), 2, '2 vocabularies are included');
  $elements = $this
    ->cssSelect(".sitemap-item--vocabulary-{$vid}");
  $this
    ->assertEqual(count($elements), 1, "Vocabulary {$vid} is included.");
  $elements = $this
    ->cssSelect(".sitemap-item--vocabulary-{$vid_to_delete}");
  $this
    ->assertEqual(count($elements), 1, "Vocabulary {$vid_to_delete} is included.");

  // Delete the vocabulary.
  $vocabularyToDelete
    ->delete();

  // @todo We shouldn't have to do this if vocab cache tags are in place...
  drupal_flush_all_caches();

  // Visit /sitemap.
  $this
    ->drupalGet('/sitemap');
  $elements = $this
    ->cssSelect(".sitemap-plugin--vocabulary");
  $this
    ->assertEqual(count($elements), 1, '1 vocabulary is included');
  $elements = $this
    ->cssSelect(".sitemap-item--vocabulary-{$vid}");
  $this
    ->assertEqual(count($elements), 1, "Vocabulary {$vid} is included.");
  $elements = $this
    ->cssSelect(".sitemap-item--vocabulary-{$vid_to_delete}");
  $this
    ->assertEqual(count($elements), 0, "Vocabulary {$vid_to_delete} is included.");

  // Visit the sitemap configuration page to ensure no errors there.
  $this
    ->drupalGet('/admin/config/search/sitemap');
}