You are here

public function SimplesitemapTest::testSetBundleSettings 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::testSetBundleSettings()
  2. 8.2 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 146

Class

SimplesitemapTest
Tests Simple XML Sitemap functional integration.

Namespace

Drupal\Tests\simple_sitemap\Functional

Code

public function testSetBundleSettings() {
  $this
    ->assertFalse($this->generator
    ->entityManager()
    ->bundleIsIndexed('node', 'page'));

  // Index new bundle.
  $this->generator
    ->customLinkManager()
    ->remove();
  $this->generator
    ->entityManager()
    ->setBundleSettings('node', 'page', [
    'index' => TRUE,
    'priority' => 0.5,
    'changefreq' => 'hourly',
  ]);
  $this->generator
    ->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
    ->entityManager()
    ->bundleIsIndexed('node', 'page'));

  // Only change bundle priority.
  $this->generator
    ->entityManager()
    ->setBundleSettings('node', 'page', [
    'priority' => 0.9,
  ]);
  $this->generator
    ->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
    ->entityManager()
    ->setBundleSettings('node', 'page', [
    'changefreq' => 'daily',
  ]);
  $this->generator
    ->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
    ->entityManager()
    ->setBundleSettings('node', 'page', [
    'changefreq' => '',
  ]);
  $this->generator
    ->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
    ->entityManager()
    ->setBundleSettings('node', 'page', [
    'index' => TRUE,
  ])
    ->setBundleSettings('node', 'blog', [
    'index' => TRUE,
  ]);
  $this->generator
    ->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
    ->entityManager()
    ->setBundleSettings('node', 'page', [
    'index' => FALSE,
  ])
    ->setBundleSettings('node', 'blog', [
    'index' => FALSE,
  ]);
  $this->generator
    ->generateSitemap(QueueWorker::GENERATE_TYPE_BACKEND);
  $this
    ->drupalGet($this->defaultSitemapUrl);
  $this
    ->assertSession()
    ->responseNotContains('node/' . $this->node
    ->id());
  $this
    ->assertSession()
    ->responseNotContains('node/' . $node3
    ->id());
}