You are here

public function CommentInterfaceTest::testAutoFilledHtmlSubject in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 core/modules/comment/src/Tests/CommentInterfaceTest.php \Drupal\comment\Tests\CommentInterfaceTest::testAutoFilledHtmlSubject()

Test 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/src/Tests/CommentInterfaceTest.php, line 248
Contains \Drupal\comment\Tests\CommentInterfaceTest.

Class

CommentInterfaceTest
Tests comment user interfaces.

Namespace

Drupal\comment\Tests

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(array(
    'format' => 'filtered_html',
    'name' => 'Filtered HTML',
  ));
  $filtered_html_format
    ->save();
  $full_html_format = FilterFormat::create(array(
    'format' => 'full_html',
    'name' => 'Full HTML',
  ));
  $full_html_format
    ->save();
  $html_user = $this
    ->drupalCreateUser(array(
    '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 = array(
    'comment_body[0][value]' => $body_text1,
    'comment_body[0][format]' => 'filtered_html',
  );
  $this
    ->drupalPostForm(NULL, $edit1, t('Save'));
  $this
    ->assertEqual('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 = array(
    'comment_body[0][value]' => $body_text2,
    'comment_body[0][format]' => 'filtered_html',
  );
  $this
    ->drupalPostForm(NULL, $edit2, t('Save'));
  $this
    ->assertEqual('(No subject)', Comment::load(2)
    ->getSubject());
}