function CommentInterfaceTest::testAutoFilledHtmlSubject

Same name and namespace in other branches
  1. 8.9.x core/modules/comment/tests/src/Functional/CommentInterfaceTest.php \Drupal\Tests\comment\Functional\CommentInterfaceTest::testAutoFilledHtmlSubject()
  2. 10 core/modules/comment/tests/src/Functional/CommentInterfaceTest.php \Drupal\Tests\comment\Functional\CommentInterfaceTest::testAutoFilledHtmlSubject()
  3. 11.x core/modules/comment/tests/src/Functional/CommentInterfaceTest.php \Drupal\Tests\comment\Functional\CommentInterfaceTest::testAutoFilledHtmlSubject()

Tests that automatic subject is correctly created from HTML comment text.

This is the same test as in CommentInterfaceTest::testAutoFilledSubject() with the additional check that HTML is stripped appropriately prior to character-counting.

File

core/modules/comment/tests/src/Functional/CommentInterfaceTest.php, line 257

Class

CommentInterfaceTest
Tests comment user interfaces.

Namespace

Drupal\Tests\comment\Functional

Code

public function testAutoFilledHtmlSubject() {
    // Set up two default (i.e. filtered HTML) input formats, because then we
    // can select one of them. Then create a user that can use these formats,
    // log the user in, and then GET the node page on which to test the
    // comments.
    $filtered_html_format = FilterFormat::create([
        'format' => 'filtered_html',
        'name' => 'Filtered HTML',
    ]);
    $filtered_html_format->save();
    $full_html_format = FilterFormat::create([
        'format' => 'full_html',
        'name' => 'Full HTML',
    ]);
    $full_html_format->save();
    $html_user = $this->drupalCreateUser([
        'access comments',
        'post comments',
        'edit own comments',
        'skip comment approval',
        'access content',
        $filtered_html_format->getPermissionName(),
        $full_html_format->getPermissionName(),
    ]);
    $this->drupalLogin($html_user);
    $this->drupalGet('node/' . $this->node
        ->id());
    // HTML should not be included in the character count.
    $body_text1 = '<span></span><strong> </strong><span> </span><strong></strong>Hello World<br />';
    $edit1 = [
        'comment_body[0][value]' => $body_text1,
        'comment_body[0][format]' => 'filtered_html',
    ];
    $this->submitForm($edit1, 'Save');
    $this->assertEquals('Hello World', Comment::load(1)->getSubject());
    // If there's nothing other than HTML, the subject should be '(No subject)'.
    $body_text2 = '<span></span><strong> </strong><span> </span><strong></strong> <br />';
    $edit2 = [
        'comment_body[0][value]' => $body_text2,
        'comment_body[0][format]' => 'filtered_html',
    ];
    $this->submitForm($edit2, 'Save');
    $this->assertEquals('(No subject)', Comment::load(2)->getSubject());
}

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