You are here

protected function CommentViewsKernelTestBase::setUp in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/comment/tests/src/Kernel/Views/CommentViewsKernelTestBase.php \Drupal\Tests\comment\Kernel\Views\CommentViewsKernelTestBase::setUp()
  2. 10 core/modules/comment/tests/src/Kernel/Views/CommentViewsKernelTestBase.php \Drupal\Tests\comment\Kernel\Views\CommentViewsKernelTestBase::setUp()

Parameters

bool $import_test_views: Should the views specified on the test class be imported. If you need to setup some additional stuff, like fields, you need to call false and then call createTestViews for your own.

Overrides ViewsKernelTestBase::setUp

1 call to CommentViewsKernelTestBase::setUp()
CommentLinksTest::setUp in core/modules/comment/tests/src/Kernel/Views/CommentLinksTest.php
1 method overrides CommentViewsKernelTestBase::setUp()
CommentLinksTest::setUp in core/modules/comment/tests/src/Kernel/Views/CommentLinksTest.php

File

core/modules/comment/tests/src/Kernel/Views/CommentViewsKernelTestBase.php, line 42

Class

CommentViewsKernelTestBase
Provides a common test base for comment views tests.

Namespace

Drupal\Tests\comment\Kernel\Views

Code

protected function setUp($import_test_views = TRUE) {
  parent::setUp($import_test_views);
  ViewTestData::createTestViews(get_class($this), [
    'comment_test_views',
  ]);
  $this
    ->installEntitySchema('user');
  $this
    ->installEntitySchema('comment');
  $this
    ->installConfig([
    'user',
  ]);
  $entity_type_manager = $this->container
    ->get('entity_type.manager');
  $this->commentStorage = $entity_type_manager
    ->getStorage('comment');
  $this->userStorage = $entity_type_manager
    ->getStorage('user');

  // Insert a row for the anonymous user.
  $this->userStorage
    ->create([
    'uid' => 0,
    'name' => '',
    'status' => 0,
  ])
    ->save();
  $admin_role = Role::create([
    'id' => 'admin',
  ]);
  $admin_role
    ->grantPermission('administer comments');
  $admin_role
    ->save();

  /* @var \Drupal\user\RoleInterface $anonymous_role */
  $anonymous_role = Role::load(Role::ANONYMOUS_ID);
  $anonymous_role
    ->grantPermission('access comments');
  $anonymous_role
    ->save();
  $this->adminUser = $this->userStorage
    ->create([
    'name' => $this
      ->randomMachineName(),
  ]);
  $this->adminUser
    ->addRole('admin');
  $this->adminUser
    ->save();
}