public function SimplesitemapTest::testSetBundleSettings in Simple XML sitemap 8.3
Same name and namespace in other branches
- 8.2 tests/src/Functional/SimplesitemapTest.php \Drupal\Tests\simple_sitemap\Functional\SimplesitemapTest::testSetBundleSettings()
- 4.x tests/src/Functional/SimplesitemapTest.php \Drupal\Tests\simple_sitemap\Functional\SimplesitemapTest::testSetBundleSettings()
Tests setting bundle settings.
@todo Add form tests
Throws
\Drupal\Component\Plugin\Exception\PluginException
\Behat\Mink\Exception\ExpectationException
File
- tests/
src/ Functional/ SimplesitemapTest.php, line 142
Class
- SimplesitemapTest
- Tests Simple XML Sitemap functional integration.
Namespace
Drupal\Tests\simple_sitemap\FunctionalCode
public function testSetBundleSettings() {
$this
->assertFalse($this->generator
->bundleIsIndexed('node', 'page'));
// Index new bundle.
$this->generator
->removeCustomLinks()
->setBundleSettings('node', 'page', [
'index' => TRUE,
'priority' => 0.5,
'changefreq' => 'hourly',
])
->generateSitemap(QueueWorker::GENERATE_TYPE_BACKEND);
$this
->drupalGet($this->defaultSitemapUrl);
$this
->assertSession()
->responseContains('node/' . $this->node
->id());
$this
->assertSession()
->responseContains('0.5');
$this
->assertSession()
->responseContains('hourly');
$this
->assertTrue($this->generator
->bundleIsIndexed('node', 'page'));
// Only change bundle priority.
$this->generator
->setBundleSettings('node', 'page', [
'priority' => 0.9,
])
->generateSitemap(QueueWorker::GENERATE_TYPE_BACKEND);
$this
->drupalGet($this->defaultSitemapUrl);
$this
->assertSession()
->responseContains('node/' . $this->node
->id());
$this
->assertSession()
->responseNotContains('0.5');
$this
->assertSession()
->responseContains('0.9');
// Only change bundle changefreq.
$this->generator
->setBundleSettings('node', 'page', [
'changefreq' => 'daily',
])
->generateSitemap(QueueWorker::GENERATE_TYPE_BACKEND);
$this
->drupalGet($this->defaultSitemapUrl);
$this
->assertSession()
->responseContains('node/' . $this->node
->id());
$this
->assertSession()
->responseNotContains('hourly');
$this
->assertSession()
->responseContains('daily');
// Remove changefreq setting.
$this->generator
->setBundleSettings('node', 'page', [
'changefreq' => '',
])
->generateSitemap(QueueWorker::GENERATE_TYPE_BACKEND);
$this
->drupalGet($this->defaultSitemapUrl);
$this
->assertSession()
->responseContains('node/' . $this->node
->id());
$this
->assertSession()
->responseNotContains('changefreq');
$this
->assertSession()
->responseNotContains('daily');
// Index two bundles.
$this
->drupalCreateContentType([
'type' => 'blog',
]);
$node3 = $this
->createNode([
'title' => 'Node3',
'type' => 'blog',
]);
$this->generator
->setBundleSettings('node', 'page', [
'index' => TRUE,
])
->setBundleSettings('node', 'blog', [
'index' => TRUE,
])
->generateSitemap(QueueWorker::GENERATE_TYPE_BACKEND);
$this
->drupalGet($this->defaultSitemapUrl);
$this
->assertSession()
->responseContains('node/' . $this->node
->id());
$this
->assertSession()
->responseContains('node/' . $node3
->id());
// Set bundle 'index' setting to false.
$this->generator
->setBundleSettings('node', 'page', [
'index' => FALSE,
])
->setBundleSettings('node', 'blog', [
'index' => FALSE,
])
->generateSitemap(QueueWorker::GENERATE_TYPE_BACKEND);
$this
->drupalGet($this->defaultSitemapUrl);
$this
->assertSession()
->responseNotContains('node/' . $this->node
->id());
$this
->assertSession()
->responseNotContains('node/' . $node3
->id());
}