You are here

public function SimplesitemapTest::testSimplesitemap in Simple XML sitemap 8

Test Simple sitemap integration.

File

src/Tests/SimplesitemapTest.php, line 45
Contains \Drupal\simplesitemap\Tests\SimplesitemapTest

Class

SimplesitemapTest
Tests Simple XML sitemap integration.

Namespace

Drupal\simplesitemap\Tests

Code

public function testSimplesitemap() {
  $sitemap = new Simplesitemap();
  $sitemap
    ->generate_sitemap();

  // Verify sitemap.xml can be cached.
  $this
    ->drupalGet('sitemap.xml');
  $this
    ->assertEqual($this
    ->drupalGetHeader('X-Drupal-Cache'), 'MISS');
  $this
    ->drupalGet('sitemap.xml');
  $this
    ->assertEqual($this
    ->drupalGetHeader('X-Drupal-Cache'), 'HIT');

  /* @var $node \Drupal\Node\NodeInterface */
  $node = $this
    ->createNode([
    'title' => 'A new page',
  ]);

  // Generate new sitemap.
  $sitemap
    ->generate_sitemap();

  // Verify the cache was flushed and node is in the sitemap.
  $this
    ->drupalGet('sitemap.xml');
  $this
    ->assertEqual($this
    ->drupalGetHeader('X-Drupal-Cache'), 'MISS');
  $this
    ->assertText('node/' . $node
    ->id());
  $this
    ->drupalGet('sitemap.xml');
  $this
    ->assertEqual($this
    ->drupalGetHeader('X-Drupal-Cache'), 'HIT');
  $this
    ->assertText('node/' . $node
    ->id());
}