You are here

public function SitemapWarmerTest::testBuildIds in Warmer 8

Same name and namespace in other branches
  1. 2.x modules/warmer_cdn/tests/src/Functional/SitemapWarmerTest.php \Drupal\Tests\warmer_cdn\Functional\SitemapWarmerTest::testBuildIds()

Asserts the enqueue form functionality.

File

modules/warmer_cdn/tests/src/Functional/SitemapWarmerTest.php, line 75

Class

SitemapWarmerTest
Tests for the sitemap warmer.

Namespace

Drupal\Tests\warmer_cdn\Functional

Code

public function testBuildIds() {

  // Enable the warming of articles.
  $this
    ->config('warmer.settings')
    ->set('warmers', [
    'sitemap' => [
      'id' => 'sitemap',
      'frequency' => 1,
      'batchSize' => 1,
      'sitemaps' => [
        $this->sitemap
          ->createFileUrl(),
      ],
      'headers' => [],
      'verify' => TRUE,
      'minPriority' => 0.7,
    ],
  ])
    ->save();

  // Use the plugin instance to build the IDs.
  $manager = \Drupal::service('plugin.manager.warmer');
  assert($manager instanceof WarmerPluginManager);
  list($warmer) = $manager
    ->getWarmers([
    'sitemap',
  ]);
  $urls = [];
  $ids = [
    NULL,
  ];
  while ($ids = $warmer
    ->buildIdsBatch(end($ids))) {
    $urls = array_merge($urls, $ids);
  }

  // Assert that the expected URLs are parsed and filtered from the sitemap.
  $this
    ->assertCount(2, $urls);

  // Assert that only one URL is warmed because the other one is 403.
  $this
    ->assertSame(1, $warmer
    ->warmMultiple($urls));
}