CommentTitleTest.php in Drupal 10
File
core/modules/comment/tests/src/Functional/CommentTitleTest.php
View source
<?php
namespace Drupal\Tests\comment\Functional;
class CommentTitleTest extends CommentTestBase {
protected $defaultTheme = 'stark';
public function testCommentEmptyTitles() {
$this
->drupalLogin($this->webUser);
$this->node = $this
->drupalCreateNode([
'type' => 'article',
'promote' => 1,
'uid' => $this->webUser
->id(),
]);
$subject_text = "Test subject";
$comment_text = "Test comment";
$this
->postComment($this->node, $comment_text, $subject_text, TRUE);
$regex_h3 = '|<h3[^>]*>.*?</h3>|';
$this
->assertSession()
->responseMatches($regex_h3);
\Drupal::service('module_installer')
->install([
'comment_empty_title_test',
]);
$this
->setCommentPreview(DRUPAL_DISABLED);
$this
->setCommentForm(TRUE);
$this
->setCommentSubject(TRUE);
$this->node = $this
->drupalCreateNode([
'type' => 'article',
'promote' => 1,
'uid' => $this->webUser
->id(),
]);
$subject_text = $this
->randomMachineName();
$comment_text = $this
->randomMachineName();
$comment = $this
->postComment($this->node, $comment_text, $subject_text, TRUE);
$this
->assertNull($comment->name->value);
$this
->assertNull($comment->mail->value);
$regex = '/<article(.*?)id="comment-' . $comment
->id() . '"(.*?)';
$regex .= $comment->comment_body->value . '(.*?)';
$regex .= '/s';
$this
->assertSession()
->responseMatches($regex);
$this
->assertSession()
->responseNotMatches($regex_h3);
$this
->assertSession()
->pageTextNotContains($subject_text);
}
public function testCommentPopulatedTitles() {
$this
->setCommentPreview(DRUPAL_DISABLED);
$this
->setCommentForm(TRUE);
$this
->setCommentSubject(TRUE);
$this
->drupalLogin($this->webUser);
$this->node = $this
->drupalCreateNode([
'type' => 'article',
'promote' => 1,
'uid' => $this->webUser
->id(),
]);
$subject_text = $this
->randomMachineName();
$comment_text = $this
->randomMachineName();
$comment1 = $this
->postComment($this->node, $comment_text, $subject_text, TRUE);
$this
->assertNull($comment1->name->value);
$this
->assertNull($comment1->mail->value);
$this
->assertTrue($this
->commentExists($comment1), 'Comment #1. Comment found.');
$this
->assertSession()
->responseMatches('|<h3[^>]*><a[^>]*>' . $subject_text . '</a></h3>|');
$comment_permalink = $this
->cssSelect('.permalink');
$comment_permalink = $comment_permalink[0]
->getAttribute('href');
$this
->assertStringContainsString('#comment-' . $comment1
->id(), $comment_permalink, "The comment's title link contains the url fragment.");
$this
->assertEquals($comment1
->permalink()
->toString(), $comment_permalink, "The comment's title has the correct link.");
}
}
Classes
Name |
Description |
CommentTitleTest |
Tests to ensure that appropriate and accessible markup is created for comment
titles. |