function SimplenewsSendTest::testHtmlEscaping in Simplenews 8
Test the correct handlling of HTML special characters in plain text mails.
File
- src/
Tests/ SimplenewsSendTest.php, line 652 - Simplenews send test functions.
Class
- SimplenewsSendTest
- Test cases for creating and sending newsletters.
Namespace
Drupal\simplenews\TestsCode
function testHtmlEscaping() {
$title = '><\'"-&&--*';
$node = Node::create(array(
'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')
->addFromEntity($node);
$node
->save();
// 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
->drupalGetMails();
// 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);
}