You are here

public function SimplesitemapTest::testSetBundleSettings in Simple XML sitemap 8.2

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

Tests setting bundle settings.

@todo Add form tests

File

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

Class

SimplesitemapTest
Tests Simple XML sitemap functional integration.

Namespace

Drupal\Tests\simple_sitemap\Functional

Code

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('nobatch');
  $this
    ->drupalGet('sitemap.xml');
  $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('nobatch');
  $this
    ->drupalGet('sitemap.xml');
  $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('nobatch');
  $this
    ->drupalGet('sitemap.xml');
  $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('nobatch');
  $this
    ->drupalGet('sitemap.xml');
  $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('nobatch');
  $this
    ->drupalGet('sitemap.xml');
  $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('nobatch');
  $this
    ->drupalGet('sitemap.xml');
  $this
    ->assertSession()
    ->responseNotContains('node/' . $this->node
    ->id());
  $this
    ->assertSession()
    ->responseNotContains('node/' . $node3
    ->id());
}