You are here

protected function SitemapWarmerTest::setUp 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::setUp()

Overrides BrowserTestBase::setUp

File

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

Class

SitemapWarmerTest
Tests for the sitemap warmer.

Namespace

Drupal\Tests\warmer_cdn\Functional

Code

protected function setUp() {
  parent::setUp();
  $this->adminUser = $this
    ->drupalCreateUser([
    'administer site configuration',
  ]);
  $this
    ->drupalLogin($this->adminUser);
  $content_type = $this
    ->randomMachineName();
  $this
    ->drupalCreateContentType([
    'type' => $content_type,
  ]);
  $this->nodes = array_reduce(range(1, 5), function ($carry, $index) use ($content_type) {
    $node = $this
      ->drupalCreateNode([
      'title' => $this
        ->getRandomGenerator()
        ->sentences(5),
      'type' => $content_type,
      'status' => $index === 2 ? NodeInterface::NOT_PUBLISHED : NodeInterface::PUBLISHED,
    ]);

    // Create alias.
    $alias_storage = \Drupal::service('path.alias_storage');
    assert($alias_storage instanceof AliasStorage);
    $alias = '/' . $this
      ->getRandomGenerator()
      ->word(8);
    $alias_storage
      ->save('/node/' . $node
      ->id(), $alias);
    $carry[$alias] = $node;
    return $carry;
  }, []);
  $this->sitemap = $this
    ->generateSitemaps($this->nodes);
}