public function SimplesitemapTest::testSitemapVariants in Simple XML sitemap 8.3
Same name and namespace in other branches
- 4.x 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 568
Class
- SimplesitemapTest
- Tests Simple XML Sitemap functional integration.
Namespace
Drupal\Tests\simple_sitemap\FunctionalCode
public function testSitemapVariants() {
// Test adding a variant.
$this->generator
->getSitemapManager()
->addSitemapVariant('test');
$this->generator
->setBundleSettings('node', 'page')
->generateSitemap(QueueWorker::GENERATE_TYPE_BACKEND);
$variants = $this->generator
->getSitemapManager()
->getSitemapVariants();
$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
->setVariants('test')
->setBundleSettings('node', 'page')
->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());
$this->generator
->getSitemapManager()
->removeSitemapVariants('test');
$variants = $this->generator
->getSitemapManager()
->getSitemapVariants();
$this
->assertArrayNotHasKey('test', $variants);
// Test if sitemap has been removed along with the variant.
$this
->drupalGet('test/sitemap.xml');
$this
->assertSession()
->statusCodeEquals(404);
}