You are here

public function SimplenewsSendTest::testHtmlEscaping in Simplenews 8.2

Same name and namespace in other branches
  1. 3.x tests/src/Functional/SimplenewsSendTest.php \Drupal\Tests\simplenews\Functional\SimplenewsSendTest::testHtmlEscaping()

Test the correct handling of HTML special characters in plain text mails.

File

tests/src/Functional/SimplenewsSendTest.php, line 687

Class

SimplenewsSendTest
Test cases for creating and sending newsletters.

Namespace

Drupal\Tests\simplenews\Functional

Code

public function testHtmlEscaping() {
  $title = '><\'"-&&amp;--*';
  $node = Node::create([
    'type' => 'simplenews_issue',
    'title' => $title,
    'uid' => '0',
    'status' => 1,
  ]);
  $node->simplenews_issue->target_id = $this
    ->getRandomNewsletter();
  $node->simplenews_issue->handler = 'simplenews_all';
  $node
    ->save();

  // Send the node.
  \Drupal::service('simplenews.spool_storage')
    ->addIssue($node);

  // Send mails.
  \Drupal::service('simplenews.mailer')
    ->sendSpool();
  \Drupal::service('simplenews.spool_storage')
    ->clear();

  // Update sent status for newsletter admin panel.
  \Drupal::service('simplenews.mailer')
    ->updateSendStatus();
  $mails = $this
    ->getMails();

  // Check that the node title is displayed unaltered in the subject and
  // unaltered except being uppercased due to the HTML conversion in the body.
  $this
    ->assertTrue(strpos($mails[0]['body'], strtoupper($title)) != FALSE);
  $this
    ->assertTrue(strpos($mails[0]['subject'], $title) != FALSE);
}