You are here

protected function CommentUserNameTest::setUp in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/comment/src/Tests/Views/CommentUserNameTest.php \Drupal\comment\Tests\Views\CommentUserNameTest::setUp()

Parameters

bool $import_test_views: Should the views specififed 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 ViewKernelTestBase::setUp

File

core/modules/comment/src/Tests/Views/CommentUserNameTest.php, line 39
Contains \Drupal\comment\Tests\Views\CommentUserNameTest.

Class

CommentUserNameTest
Tests comment user name field

Namespace

Drupal\comment\Tests\Views

Code

protected function setUp($import_test_views = TRUE) {
  parent::setUp($import_test_views);
  $this
    ->installEntitySchema('user');
  $this
    ->installEntitySchema('comment');

  // Create the anonymous role.
  $this
    ->installConfig([
    'user',
  ]);

  // Create an anonymous user.
  $storage = \Drupal::entityManager()
    ->getStorage('user');

  // Insert a row for the anonymous user.
  $storage
    ->create(array(
    'uid' => 0,
    'name' => '',
    'status' => 0,
  ))
    ->save();
  $admin_role = Role::create([
    'id' => 'admin',
    'permissions' => [
      'administer comments',
      'access user profiles',
    ],
  ]);
  $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 = User::create([
    'name' => $this
      ->randomMachineName(),
    'roles' => [
      $admin_role
        ->id(),
    ],
  ]);
  $this->adminUser
    ->save();

  // Create some comments.
  $comment = Comment::create([
    'subject' => 'My comment title',
    'uid' => $this->adminUser
      ->id(),
    'name' => $this->adminUser
      ->label(),
    'entity_type' => 'entity_test',
    'comment_type' => 'entity_test',
    'status' => 1,
  ]);
  $comment
    ->save();
  $comment_anonymous = Comment::create([
    'subject' => 'Anonymous comment title',
    'uid' => 0,
    'name' => 'barry',
    'mail' => 'test@example.com',
    'homepage' => 'https://example.com',
    'entity_type' => 'entity_test',
    'comment_type' => 'entity_test',
    'created' => 123456,
    'status' => 1,
  ]);
  $comment_anonymous
    ->save();
}