You are here

public function XmlSitemapListBuilderTest::testMoreSitemaps in XML sitemap 2.x

Same name and namespace in other branches
  1. 8 tests/src/Functional/XmlSitemapListBuilderTest.php \Drupal\Tests\xmlsitemap\Functional\XmlSitemapListBuilderTest::testMoreSitemaps()

Test if multiple sitemaps exist and have consistent information.

File

tests/src/Functional/XmlSitemapListBuilderTest.php, line 80

Class

XmlSitemapListBuilderTest
Tests the sitemaps list builder.

Namespace

Drupal\Tests\xmlsitemap\Functional

Code

public function testMoreSitemaps() {
  $this
    ->drupalLogin($this->admin_user);
  $edit = [
    'label' => 'English',
    'context[language]' => 'en',
  ];
  $this
    ->drupalPostForm('admin/config/search/xmlsitemap/add', $edit, t('Save'));
  $context = [
    'language' => 'en',
  ];
  $id = xmlsitemap_sitemap_get_context_hash($context);
  $this
    ->assertSession()
    ->pageTextContains('Saved the English sitemap.');
  $this
    ->assertSession()
    ->pageTextContains($id);
  $edit = [
    'label' => 'French',
    'context[language]' => 'fr',
  ];
  $this
    ->drupalPostForm('admin/config/search/xmlsitemap/add', $edit, 'Save');
  $context = [
    'language' => 'fr',
  ];
  $id = xmlsitemap_sitemap_get_context_hash($context);
  $this
    ->assertSession()
    ->pageTextContains('Saved the French sitemap.');
  $this
    ->assertSession()
    ->pageTextContains($id);
  $this
    ->drupalPostForm('admin/config/search/xmlsitemap/add', $edit, t('Save'));
  $this
    ->assertSession()
    ->pageTextContains('There is another sitemap saved with the same context.');
  $sitemaps = XmlSitemap::loadMultiple();
  foreach ($sitemaps as $sitemap) {
    $label = $sitemap
      ->label();
    $this
      ->drupalPostForm("admin/config/search/xmlsitemap/{$sitemap->id()}/delete", [], t('Delete'));
    $this
      ->assertSession()
      ->responseContains((string) new FormattableMarkup('Sitemap %label has been deleted.', [
      '%label' => $label,
    ]));
  }
  $sitemaps = XmlSitemap::loadMultiple();
  $this
    ->assertEquals(0, count($sitemaps), 'No more sitemaps.');
}