You are here

public function CommentInterfaceTest::testAutoFilledSubject in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/comment/tests/src/Functional/CommentInterfaceTest.php \Drupal\Tests\comment\Functional\CommentInterfaceTest::testAutoFilledSubject()

Test 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 232

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
    ->assertEqual('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
    ->assertEqual('LoremipsumloremipsumLoreming…', $comment2
    ->getSubject());
}