function CommentInterfaceTest::testAutoFilledSubject

Same name in other branches
  1. 8.9.x core/modules/comment/tests/src/Functional/CommentInterfaceTest.php \Drupal\Tests\comment\Functional\CommentInterfaceTest::testAutoFilledSubject()
  2. 10 core/modules/comment/tests/src/Functional/CommentInterfaceTest.php \Drupal\Tests\comment\Functional\CommentInterfaceTest::testAutoFilledSubject()
  3. 11.x 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 234

Class

CommentInterfaceTest
Tests comment user interfaces.

Namespace

Drupal\Tests\comment\Functional

Code

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());
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.