You are here

public function CommentTest::testCommentUser in Display Suite 8.4

Same name and namespace in other branches
  1. 8.3 tests/src/Functional/CommentTest.php \Drupal\Tests\ds\Functional\CommentTest::testCommentUser()

Test User custom display on a comment on a node.

File

tests/src/Functional/CommentTest.php, line 128

Class

CommentTest
Tests for the manage display tab in Display Suite.

Namespace

Drupal\Tests\ds\Functional

Code

public function testCommentUser() {

  // Create a node.
  $settings = [
    'type' => 'article',
    'promote' => 1,
  ];
  $node = $this
    ->drupalCreateNode($settings);

  // User compact display settings.
  $this
    ->dsSelectLayout([], [], 'admin/config/people/accounts/display');
  $fields = [
    'fields[username][region]' => 'left',
    'fields[member_for][region]' => 'left',
  ];
  $this
    ->dsConfigureUi($fields, 'admin/config/people/accounts/display');

  // Comment display settings.
  $this
    ->dsSelectLayout([], [], 'admin/structure/comment/manage/comment/display');
  $fields = [
    'fields[comment_title][region]' => 'left',
    'fields[comment_user][region]' => 'left',
    'fields[comment_body][region]' => 'left',
  ];
  $this
    ->dsConfigureUi($fields, 'admin/structure/comment/manage/comment/display');

  // Post comment.
  $comment = $this
    ->postComment($node, $this
    ->randomMachineName(), $this
    ->randomMachineName());
  $this
    ->assertSession()
    ->responseContains($comment->comment_body->value);
  $this
    ->assertSession()
    ->responseContains('Member for');
  $xpath = $this
    ->xpath('//div[@class="field field--name-comment-user field--type-ds field--label-hidden field__item"]/div/div/div[@class="field field--name-username field--type-ds field--label-hidden field__item"]');
  $this
    ->assertEquals(count($xpath), 1, 'Username');
}