You are here

public function CommentTest::testComments 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::testComments()

Test adding comments to a node.

File

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

Class

CommentTest
Tests for the manage display tab in Display Suite.

Namespace

Drupal\Tests\ds\Functional

Code

public function testComments() {

  // Create a node.
  $settings = [
    'type' => 'article',
    'promote' => 1,
  ];
  $node = $this
    ->drupalCreateNode($settings);
  $this
    ->dsSelectLayout([], [], 'admin/structure/comment/manage/comment/display');
  $fields = [
    'fields[comment_title][region]' => 'left',
    'fields[comment_body][region]' => 'left',
  ];
  $this
    ->dsConfigureUi($fields, 'admin/structure/comment/manage/comment/display');

  // Post comment.
  $comment1 = $this
    ->postComment($node, $this
    ->randomMachineName(), $this
    ->randomMachineName());
  $this
    ->assertSession()
    ->responseContains($comment1->comment_body->value);

  // Post comment.
  $comment2 = $this
    ->postComment($node, $this
    ->randomMachineName(), $this
    ->randomMachineName());
  $this
    ->assertSession()
    ->responseContains($comment2->comment_body->value);

  // Verify there are no double ID's.
  // For some reason, this test fails on the test bot, but is fine local.

  //$xpath = $this->xpath('//a[@id="comment-1"]');

  //$this->assertEquals(1, count($xpath),'1 ID found named comment-1');

  // Test that hidden fields aren't exposed in the config.
  $this
    ->dsSelectLayout();
  $fields = [
    'fields[comment][region]' => 'hidden',
  ];
  $this
    ->dsConfigureUi($fields);
  $display = EntityViewDisplay::load('node.article.default');
  $content = $display
    ->get('content');
  $hidden = $display
    ->get('hidden');
  $this
    ->assertArrayNotHasKey('comment', $content, 'Comment is not part of the content region');
  $this
    ->assertArrayHasKey('comment', $hidden, 'Comment is part of the hidden region');
}