public function SimplesitemapTest::testSetEntityInstanceSettings 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::testSetEntityInstanceSettings()
- 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().
Throws
\Drupal\Component\Plugin\Exception\PluginException
\Behat\Mink\Exception\ExpectationException
File
- tests/
src/ Functional/ SimplesitemapTest.php, line 383
Class
- SimplesitemapTest
- Tests Simple XML Sitemap functional integration.
Namespace
Drupal\Tests\simple_sitemap\FunctionalCode
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(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
->setBundleSettings('node', 'page', [
'priority' => 0.1,
'changefreq' => 'never',
])
->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()));
}