You are here

public function SimplenewsSubscribeTest::testFormatting in Simplenews 3.x

Tests formatting and escaping of subscription mails.

File

tests/src/Functional/SimplenewsSubscribeTest.php, line 710

Class

SimplenewsSubscribeTest
Un/subscription of anonymous and authenticated users.

Namespace

Drupal\Tests\simplenews\Functional

Code

public function testFormatting() {
  $this
    ->config('simplenews.settings')
    ->set('subscription.confirm_combined_subject', 'Please <join> us & enjoy')
    ->set('subscription.confirm_combined_body', "Hello & welcome,\n\nclick to join us <[simplenews-subscriber:combined-url]>")
    ->save();
  $newsletter_id = $this
    ->getRandomNewsletter();
  $newsletter = Newsletter::load($newsletter_id);
  $newsletter->name = 'Rise & <shine>';
  $newsletter
    ->save();
  $mail = $this
    ->randomEmail(8);
  $this
    ->subscribe([], $mail);
  $captured_emails = $this->container
    ->get('state')
    ->get('system.test_mail_collector') ?: [];
  $email = end($captured_emails);
  $this
    ->assertEquals('Please <join> us & enjoy', $email['subject']);
  $this
    ->assertStringContainsString("Hello & welcome,\n\nclick to join us\n<http", $email['body']);
}