You are here

protected function SitemapWarmerTest::setUp in Warmer 2.x

Same name and namespace in other branches
  1. 8 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 52

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::entityTypeManager()
      ->getStorage('path_alias');
    assert($alias_storage instanceof PathAliasStorage);
    $alias = '/' . $this
      ->getRandomGenerator()
      ->word(8);
    $alias_storage
      ->create([
      'path' => '/node/' . $node
        ->id(),
      'alias' => $alias,
    ])
      ->save();
    $carry[$alias] = $node;
    return $carry;
  }, []);
  $this->sitemap = $this
    ->generateSitemaps($this->nodes);
}