You are here

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

Throws

\Drupal\Component\Plugin\Exception\PluginException

\Behat\Mink\Exception\ExpectationException

File

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

Class

SimplesitemapTest
Tests Simple XML Sitemap functional integration.

Namespace

Drupal\Tests\simple_sitemap\Functional

Code

public function testSetEntityInstanceSettings() {
  $this->generator
    ->entityManager()
    ->setBundleSettings('node', 'page')
    ->setEntityInstanceSettings('node', $this->node
    ->id(), [
    'priority' => 0.1,
    'changefreq' => 'never',
  ])
    ->setEntityInstanceSettings('node', $this->node2
    ->id(), [
    'index' => FALSE,
  ]);
  $this->generator
    ->customLinkManager()
    ->remove();
  $this->generator
    ->generateSitemap(QueueWorker::GENERATE_TYPE_BACKEND);

  // Test sitemap result.
  $this
    ->drupalGet($this->defaultSitemapUrl);
  $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.
  $this
    ->assertEquals(1, $this
    ->getOverridesCount('node', $this->node
    ->id()));
  $this->generator
    ->entityManager()
    ->setBundleSettings('node', 'page', [
    'priority' => 0.1,
    'changefreq' => 'never',
  ]);
  $this->generator
    ->generateSitemap(QueueWorker::GENERATE_TYPE_BACKEND);

  // Test sitemap result.
  $this
    ->drupalGet($this->defaultSitemapUrl);
  $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.
  $this
    ->assertEquals(0, $this
    ->getOverridesCount('node', $this->node
    ->id()));

  // Assert that creating a new content type doesn't remove the overrides.
  $this
    ->drupalGet('node/' . $this->node
    ->id() . '/edit');
  $this
    ->submitForm([
    'index_default_node_settings' => 0,
  ], 'Save');
  $this
    ->assertEquals(1, $this
    ->getOverridesCount('node', $this->node
    ->id()));

  // Create a new content type.
  $this
    ->drupalGet('admin/structure/types/add');
  $this
    ->submitForm([
    'name' => 'simple_sitemap_type',
    'type' => 'simple_sitemap_type',
    'index_default_node_settings' => 0,
  ], 'Save content type');

  // The entity override from the other content type should not be affected.
  $this
    ->assertEquals(1, $this
    ->getOverridesCount('node', $this->node
    ->id()));

  // Assert that removing the other content type doesn't remove the overrides.
  $this
    ->drupalGet('admin/structure/types/manage/simple_sitemap_type/delete');
  $this
    ->submitForm([], 'Delete');
  $this
    ->assertEquals(1, $this
    ->getOverridesCount('node', $this->node
    ->id()));
}