You are here

public function SimpleSitemapViewsTest::testGarbageCollector in Simple XML sitemap 4.x

Same name and namespace in other branches
  1. 8.3 modules/simple_sitemap_views/tests/src/Functional/SimpleSitemapViewsTest.php \Drupal\Tests\simple_sitemap_views\Functional\SimpleSitemapViewsTest::testGarbageCollector()

Tests the garbage collection process.

File

modules/simple_sitemap_views/tests/src/Functional/SimpleSitemapViewsTest.php, line 123

Class

SimpleSitemapViewsTest
Tests Simple XML Sitemap (Views) functional integration.

Namespace

Drupal\Tests\simple_sitemap_views\Functional

Code

public function testGarbageCollector() {

  // Disable cron generation, since data can be removed
  // from the index during generation.
  $this->generator
    ->saveSetting('cron_generate', FALSE);

  // Record with the wrong set of indexed arguments must be removed.
  $this
    ->addRecordToIndex($this->testView
    ->id(), $this->testView->current_display, [
    'type',
    'title',
    'nid',
  ], [
    'page',
    $this->node
      ->getTitle(),
    $this->node
      ->id(),
  ]);
  $this->cron
    ->run();
  $this
    ->assertIndexSize(0);

  // Record of a non-existent view must be removed.
  $this
    ->addRecordToIndex('simple_sitemap_fake_view', $this->testView->current_display, [
    'type',
    'title',
  ], [
    'page',
    $this->node
      ->getTitle(),
  ]);
  $this->cron
    ->run();
  $this
    ->assertIndexSize(0);

  // Record of a non-existent display must be removed.
  $this
    ->addRecordToIndex($this->testView
    ->id(), 'simple_sitemap_fake_display', [
    'type',
    'title',
  ], [
    'page',
    $this->node
      ->getTitle(),
  ]);
  $this->cron
    ->run();
  $this
    ->assertIndexSize(0);

  // The number of records should not exceed the specified limit.
  for ($i = 0; $i < 3; $i++) {
    $this
      ->addRecordToIndex($this->testView
      ->id(), $this->testView->current_display, [
      'type',
      'title',
    ], [
      'page2',
      "Node{$i}",
    ]);
  }
  $this->cron
    ->run();
  $this
    ->assertIndexSize(2);

  // Records about pages with empty result must be removed during generation.
  $this->generator
    ->generateSitemap('backend');
  $this
    ->assertIndexSize(0);
}