You are here

public function XmlSitemapFunctionalTest::testStatusReport in XML sitemap 8

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

Test Status Report.

Test that configuration problems are reported properly in the status report.

File

tests/src/Functional/XmlSitemapFunctionalTest.php, line 82

Class

XmlSitemapFunctionalTest
Tests the generation of sitemaps.

Namespace

Drupal\Tests\xmlsitemap\Functional

Code

public function testStatusReport() {
  $cron_warning_threshold = $this
    ->config('system.cron')
    ->get('threshold.requirements_warning');

  // Test the rebuild flag.
  $this
    ->drupalLogin($this->admin_user);
  $this->state
    ->set('xmlsitemap_generated_last', $this->time
    ->getRequestTime());
  $this->state
    ->set('xmlsitemap_rebuild_needed', TRUE);
  $this
    ->assertXMLSitemapProblems('The XML sitemap data is out of sync and needs to be completely rebuilt.');
  $this
    ->clickLink('completely rebuilt');
  $this
    ->assertSession()
    ->statusCodeEquals(200);
  $this->state
    ->set('xmlsitemap_rebuild_needed', FALSE);
  $this
    ->assertNoXMLSitemapProblems();

  // Test the regenerate flag (and cron has run recently).
  $this->state
    ->set('xmlsitemap_regenerate_needed', TRUE);
  $this->state
    ->set('xmlsitemap_generated_last', $this->time
    ->getRequestTime() - $cron_warning_threshold - 600);
  $this->state
    ->set('system.cron_last', $this->time
    ->getRequestTime() - $cron_warning_threshold + 600);
  $this
    ->assertNoXMLSitemapProblems();

  // Test the regenerate flag (and cron hasn't run in a while).
  $this->state
    ->set('xmlsitemap_regenerate_needed', TRUE);
  $this->state
    ->set('system.cron_last', 0);
  $this->state
    ->set('install_time', 0);
  $this->state
    ->set('xmlsitemap_generated_last', $this->time
    ->getRequestTime() - $cron_warning_threshold - 600);
  $this
    ->assertXMLSitemapProblems('The XML cached files are out of date and need to be regenerated. You can run cron manually to regenerate the sitemap files.');
  $this
    ->clickLink('run cron manually');
  $this
    ->assertSession()
    ->statusCodeEquals(200);
  $this
    ->assertNoXMLSitemapProblems();
}