You are here

public function SimplenewsSendTest::testHtmlEscaping in Simplenews 3.x

Same name and namespace in other branches
  1. 8.2 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 694

Class

SimplenewsSendTest
Test cases for creating and sending newsletters.

Namespace

Drupal\Tests\simplenews\Functional

Code

public function testHtmlEscaping() {
  $title = '><\'"-&&amp;--*';
  $name = 'Rise & shine';
  $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();
  $newsletter = Newsletter::load($node->simplenews_issue->target_id);
  $newsletter->name = $name;
  $newsletter->subject = '<[simplenews-newsletter:name]> [node:title]';
  $newsletter
    ->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 subject and body.
  // @todo Body is wrong due to
  // https://www.drupal.org/project/drupal/issues/3174760
  // $this->assertStringContainsString($title, $mails[0]['body']);
  $this
    ->assertEquals("<{$name}> {$title}", $mails[0]['subject']);
}