You are here

public function XmlSitemapUnitTest::testMinimumLifetime in XML sitemap 8

Same name and namespace in other branches
  1. 2.x tests/src/Functional/XmlSitemapUnitTest.php \Drupal\Tests\xmlsitemap\Functional\XmlSitemapUnitTest::testMinimumLifetime()

Test that the sitemap will not be genereated before the lifetime expires.

File

tests/src/Functional/XmlSitemapUnitTest.php, line 315

Class

XmlSitemapUnitTest
Unit tests for the XML sitemap module.

Namespace

Drupal\Tests\xmlsitemap\Functional

Code

public function testMinimumLifetime() {
  $this
    ->drupalLogin($this->admin_user);
  $this->config
    ->set('minimum_lifetime', 300)
    ->save();
  $this
    ->regenerateSitemap();
  $link = $this
    ->addSitemapLink([
    'loc' => '/lifetime-test',
  ]);
  $this
    ->cronRun();
  $this
    ->drupalGetSitemap();
  $this
    ->assertSession()
    ->statusCodeEquals(200);
  $this
    ->assertSession()
    ->responseNotContains('lifetime-test');
  $this->state
    ->set('xmlsitemap_generated_last', $this->time
    ->getRequestTime() - 400);
  $this
    ->cronRun();
  $this
    ->drupalGetSitemap();
  $this
    ->assertSession()
    ->responseContains('lifetime-test');
  $this->linkStorage
    ->delete($link['type'], $link['id']);
  $this
    ->cronRun();
  $this
    ->drupalGetSitemap();
  $this
    ->assertSession()
    ->responseContains('lifetime-test');
  $this
    ->regenerateSitemap();
  $this
    ->drupalGetSitemap();
  $this
    ->assertSession()
    ->statusCodeEquals(200);
  $this
    ->assertSession()
    ->responseNotContains('lifetime-test');
}