You are here

public function SimplesitemapTest::testSitemapVariants in Simple XML sitemap 4.x

Same name and namespace in other branches
  1. 8.3 tests/src/Functional/SimplesitemapTest.php \Drupal\Tests\simple_sitemap\Functional\SimplesitemapTest::testSitemapVariants()

Test adding and removing sitemap variants.

Throws

\Behat\Mink\Exception\ExpectationException

\Drupal\Component\Plugin\Exception\PluginException

File

tests/src/Functional/SimplesitemapTest.php, line 563

Class

SimplesitemapTest
Tests Simple XML Sitemap functional integration.

Namespace

Drupal\Tests\simple_sitemap\Functional

Code

public function testSitemapVariants() {

  // Test adding a variant.
  SimpleSitemap::create([
    'id' => 'test',
    'type' => 'default_hreflang',
  ])
    ->save();
  $this->generator
    ->entityManager()
    ->setBundleSettings('node', 'page');
  $this->generator
    ->generateSitemap(QueueWorker::GENERATE_TYPE_BACKEND);
  $variants = SimpleSitemap::loadMultiple();
  $this
    ->assertArrayHasKey('test', $variants);
  $this
    ->drupalGet($this->defaultSitemapUrl);
  $this
    ->assertSession()
    ->responseContains('node/' . $this->node
    ->id());

  // Test if generation affected the default variant only.
  $this
    ->drupalGet('test/sitemap.xml');
  $this
    ->assertSession()
    ->responseNotContains('node/' . $this->node
    ->id());
  $this->generator
    ->entityManager()
    ->setBundleSettings('node', 'page');
  $this->generator
    ->setVariants('test')
    ->generateSitemap(QueueWorker::GENERATE_TYPE_BACKEND);

  // Test if bundle settings have been set for correct variant.
  $this
    ->drupalGet($this->defaultSitemapUrl);
  $this
    ->assertSession()
    ->responseContains('node/' . $this->node
    ->id());
  SimpleSitemap::load('test')
    ->delete();
  $variants = SimpleSitemap::loadMultiple();
  $this
    ->assertArrayNotHasKey('test', $variants);

  // Test if sitemap has been removed along with the variant.
  $this
    ->drupalGet('test/sitemap.xml');
  $this
    ->assertSession()
    ->statusCodeEquals(404);
}