public function CommentInterfaceTest::testAutoFilledSubject in Drupal 9
Same name and namespace in other branches
- 8 core/modules/comment/tests/src/Functional/CommentInterfaceTest.php \Drupal\Tests\comment\Functional\CommentInterfaceTest::testAutoFilledSubject()
Tests that the subject is automatically filled if disabled or left blank.
When the subject field is blank or disabled, the first 29 characters of the comment body are used for the subject. If this would break within a word, then the break is put at the previous word boundary instead.
File
- core/
modules/ comment/ tests/ src/ Functional/ CommentInterfaceTest.php, line 239
Class
- CommentInterfaceTest
- Tests comment user interfaces.
Namespace
Drupal\Tests\comment\FunctionalCode
public function testAutoFilledSubject() {
$this
->drupalLogin($this->webUser);
$this
->drupalGet('node/' . $this->node
->id());
// Break when there is a word boundary before 29 characters.
$body_text = 'Lorem ipsum Lorem ipsum Loreming ipsum Lorem ipsum';
$comment1 = $this
->postComment(NULL, $body_text, '', TRUE);
$this
->assertTrue($this
->commentExists($comment1), 'Form comment found.');
$this
->assertEquals('Lorem ipsum Lorem ipsum…', $comment1
->getSubject());
// Break at 29 characters where there's no boundary before that.
$body_text2 = 'LoremipsumloremipsumLoremingipsumLoremipsum';
$comment2 = $this
->postComment(NULL, $body_text2, '', TRUE);
$this
->assertEquals('LoremipsumloremipsumLoreming…', $comment2
->getSubject());
}