You are here

protected function BlogTestBase::setUp in Blog 3.x

Same name and namespace in other branches
  1. 8.2 tests/src/Functional/BlogTestBase.php \Drupal\Tests\blog\Functional\BlogTestBase::setUp()

Overrides BrowserTestBase::setUp

3 calls to BlogTestBase::setUp()
BasicBlogTest::setUp in tests/src/Functional/BasicBlogTest.php
BreadcrumbTest::setUp in tests/src/Functional/BreadcrumbTest.php
MyBlogLinkTest::setUp in tests/src/Functional/MyBlogLinkTest.php
3 methods override BlogTestBase::setUp()
BasicBlogTest::setUp in tests/src/Functional/BasicBlogTest.php
BreadcrumbTest::setUp in tests/src/Functional/BreadcrumbTest.php
MyBlogLinkTest::setUp in tests/src/Functional/MyBlogLinkTest.php

File

tests/src/Functional/BlogTestBase.php, line 39

Class

BlogTestBase
Test base class for blog module.

Namespace

Drupal\Tests\blog\Functional

Code

protected function setUp() : void {
  parent::setUp();

  // Add article node type.
  $this
    ->createContentType([
    'type' => 'article',
  ]);

  // Create blogger1 user.
  $this->blogger1 = $this
    ->drupalCreateUser([
    'create article content',
    'create blog_post content',
  ]);

  // Create blogger2 user.
  $this->blogger2 = $this
    ->drupalCreateUser([
    'create article content',
    'create blog_post content',
  ]);

  // Create blogger user with no blog posts.
  $this->bloggerNoEntries = $this
    ->drupalCreateUser([
    'create blog_post content',
  ]);

  // Generate blog posts and articles.
  $this->blogNodes1 = [];
  $this->blogNodes2 = [];
  $this->articleNodes1 = [];
  $this->articleNodes2 = [];
  for ($i = 0; $i < 10; $i++) {
    $node = $this
      ->createNode([
      'type' => 'blog_post',
      'title' => $this
        ->randomMachineName(32),
      'uid' => $i % 2 ? $this->blogger1
        ->id() : $this->blogger2
        ->id(),
    ]);
    if ($i % 2) {
      $this->blogNodes1[$node
        ->id()] = $node;
    }
    else {
      $this->blogNodes2[$node
        ->id()] = $node;
    }
  }
  for ($i = 0; $i < 10; $i++) {
    $node = $this
      ->createNode([
      'type' => 'article',
      'title' => $this
        ->randomMachineName(32),
      'uid' => $i % 2 ? $this->blogger1
        ->id() : $this->blogger2
        ->id(),
    ]);
    if ($i % 2) {
      $this->articleNodes1[$node
        ->id()] = $node;
    }
    else {
      $this->articleNodes2[$node
        ->id()] = $node;
    }
  }
}