You are here

public function SimplesitemapTest::testSetEntityInstanceSettings 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::testSetEntityInstanceSettings()
  2. 4.x tests/src/Functional/SimplesitemapTest.php \Drupal\Tests\simple_sitemap\Functional\SimplesitemapTest::testSetEntityInstanceSettings()

Test overriding of bundle settings for a single entity.

@todo: Use form testing instead of responseContains().

File

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

Class

SimplesitemapTest
Tests Simple XML sitemap functional integration.

Namespace

Drupal\Tests\simple_sitemap\Functional

Code

public function testSetEntityInstanceSettings() {
  $this->generator
    ->setBundleSettings('node', 'page')
    ->removeCustomLinks()
    ->setEntityInstanceSettings('node', $this->node
    ->id(), [
    'priority' => 0.1,
    'changefreq' => 'never',
  ])
    ->setEntityInstanceSettings('node', $this->node2
    ->id(), [
    'index' => FALSE,
  ])
    ->generateSitemap('nobatch');

  // Test sitemap result.
  $this
    ->drupalGet('sitemap.xml');
  $this
    ->assertSession()
    ->responseContains('node/' . $this->node
    ->id());
  $this
    ->assertSession()
    ->responseContains('0.1');
  $this
    ->assertSession()
    ->responseContains('never');
  $this
    ->assertSession()
    ->responseNotContains('node/' . $this->node2
    ->id());
  $this
    ->assertSession()
    ->responseNotContains('0.5');
  $this
    ->drupalLogin($this->privilegedUser);

  // Test UI changes.
  $this
    ->drupalGet('node/' . $this->node
    ->id() . '/edit');
  $this
    ->assertSession()
    ->responseContains('<option value="0.1" selected="selected">0.1</option>');
  $this
    ->assertSession()
    ->responseContains('<option value="never" selected="selected">never</option>');

  // Test database changes.
  $result = $this->database
    ->select('simple_sitemap_entity_overrides', 'o')
    ->fields('o', [
    'inclusion_settings',
  ])
    ->condition('o.entity_type', 'node')
    ->condition('o.entity_id', $this->node
    ->id())
    ->execute()
    ->fetchField();
  $this
    ->assertFalse(empty($result));
  $this->generator
    ->setBundleSettings('node', 'page', [
    'priority' => 0.1,
    'changefreq' => 'never',
  ])
    ->generateSitemap('nobatch');

  // Test sitemap result.
  $this
    ->drupalGet('sitemap.xml');
  $this
    ->assertSession()
    ->responseContains('node/' . $this->node
    ->id());
  $this
    ->assertSession()
    ->responseContains('0.1');
  $this
    ->assertSession()
    ->responseContains('never');
  $this
    ->assertSession()
    ->responseNotContains('node/' . $this->node2
    ->id());
  $this
    ->assertSession()
    ->responseNotContains('0.5');

  // Test UI changes.
  $this
    ->drupalGet('node/' . $this->node
    ->id() . '/edit');
  $this
    ->assertSession()
    ->responseContains('<option value="0.1" selected="selected">0.1 (default)</option>');
  $this
    ->assertSession()
    ->responseContains('<option value="never" selected="selected">never (default)</option>');

  // Test if entity override has been removed from database after its equal to
  // its bundle settings.
  $result = $this->database
    ->select('simple_sitemap_entity_overrides', 'o')
    ->fields('o', [
    'inclusion_settings',
  ])
    ->condition('o.entity_type', 'node')
    ->condition('o.entity_id', $this->node
    ->id())
    ->execute()
    ->fetchField();
  $this
    ->assertTrue(empty($result));
}