You are here

public function CommentTitleTest::testCommentPopulatedTitles in Zircon Profile 8

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

Tests markup for comments with populated titles.

File

core/modules/comment/src/Tests/CommentTitleTest.php, line 49
Contains \Drupal\comment\Tests\CommentTitleTest.

Class

CommentTitleTest
Tests to ensure that appropriate and accessible markup is created for comment titles.

Namespace

Drupal\comment\Tests

Code

public function testCommentPopulatedTitles() {

  // Set comments to have a subject with preview disabled.
  $this
    ->setCommentPreview(DRUPAL_DISABLED);
  $this
    ->setCommentForm(TRUE);
  $this
    ->setCommentSubject(TRUE);

  // Create a node.
  $this
    ->drupalLogin($this->webUser);
  $this->node = $this
    ->drupalCreateNode(array(
    'type' => 'article',
    'promote' => 1,
    'uid' => $this->webUser
      ->id(),
  ));

  // Post comment #1 and verify that title is rendered in h3.
  $subject_text = $this
    ->randomMachineName();
  $comment_text = $this
    ->randomMachineName();
  $comment1 = $this
    ->postComment($this->node, $comment_text, $subject_text, TRUE);

  // Confirm that the comment was created.
  $this
    ->assertTrue($this
    ->commentExists($comment1), 'Comment #1. Comment found.');

  // Tests that markup is created for comment with heading.
  $this
    ->assertPattern('|<h3[^>]*><a[^>]*>' . $subject_text . '</a></h3>|', 'Comment title is rendered in h3 when title populated.');
}