function CommentTitleTest::testCommentEmptyTitles
Same name in other branches
- 9 core/modules/comment/tests/src/Functional/CommentTitleTest.php \Drupal\Tests\comment\Functional\CommentTitleTest::testCommentEmptyTitles()
- 10 core/modules/comment/tests/src/Functional/CommentTitleTest.php \Drupal\Tests\comment\Functional\CommentTitleTest::testCommentEmptyTitles()
- 11.x core/modules/comment/tests/src/Functional/CommentTitleTest.php \Drupal\Tests\comment\Functional\CommentTitleTest::testCommentEmptyTitles()
Tests markup for comments with empty titles.
File
-
core/
modules/ comment/ tests/ src/ Functional/ CommentTitleTest.php, line 21
Class
- CommentTitleTest
- Tests to ensure that appropriate and accessible markup is created for comment titles.
Namespace
Drupal\Tests\comment\FunctionalCode
public function testCommentEmptyTitles() {
// Installs module that sets comments to an empty string.
\Drupal::service('module_installer')->install([
'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([
'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);
// The entity fields for name and mail have no meaning if the user is not
// Anonymous.
$this->assertNull($comment->name->value);
$this->assertNull($comment->mail->value);
// Confirm that the comment was created.
$regex = '/<article(.*?)id="comment-' . $comment->id() . '"(.*?)';
$regex .= $comment->comment_body->value . '(.*?)';
$regex .= '/s';
// Verify that the comment is created successfully.
$this->assertPattern($regex);
// Tests that markup is not generated for the comment without header.
$this->assertSession()
->responseNotMatches('|<h3[^>]*></h3>|', 'Comment title H3 element not found when title is an empty string.');
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.