You are here

public function CommentTitleTest::testCommentEmptyTitles 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::testCommentEmptyTitles()

Tests markup for comments with empty titles.

File

core/modules/comment/src/Tests/CommentTitleTest.php, line 20
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 testCommentEmptyTitles() {

  // Installs module that sets comments to an empty string.
  \Drupal::service('module_installer')
    ->install(array(
    'comment_empty_title_test',
  ));

  // 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 h3's are not rendered.
  $subject_text = $this
    ->randomMachineName();
  $comment_text = $this
    ->randomMachineName();
  $comment = $this
    ->postComment($this->node, $comment_text, $subject_text, TRUE);

  // Confirm that the comment was created.
  $regex = '/<a id="comment-' . $comment
    ->id() . '"(.*?)';
  $regex .= $comment->comment_body->value . '(.*?)';
  $regex .= '/s';
  $this
    ->assertPattern($regex, 'Comment is created successfully');

  // Tests that markup is not generated for the comment without header.
  $this
    ->assertNoPattern('|<h3[^>]*></h3>|', 'Comment title H3 element not found when title is an empty string.');
}