public function SimplenewsSendTest::testNewsletterTheme in Simplenews 3.x
Same name and namespace in other branches
- 8.2 tests/src/Functional/SimplenewsSendTest.php \Drupal\Tests\simplenews\Functional\SimplenewsSendTest::testNewsletterTheme()
Test the theme suggestions when sending mails.
File
- tests/
src/ Functional/ SimplenewsSendTest.php, line 660
Class
- SimplenewsSendTest
- Test cases for creating and sending newsletters.
Namespace
Drupal\Tests\simplenews\FunctionalCode
public function testNewsletterTheme() {
// Install and enable the test theme.
\Drupal::service('theme_installer')
->install([
'simplenews_newsletter_test_theme',
]);
\Drupal::theme()
->setActiveTheme(\Drupal::service('theme.initialization')
->initTheme('simplenews_newsletter_test_theme'));
$node = Node::create([
'type' => 'simplenews_issue',
'title' => $this
->randomString(10),
'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 if the correct theme was used in mails.
$this
->assertStringContainsString('Simplenews test theme', $mails[0]['body']);
$this
->assertEquals(1, preg_match('/ID: [0-9]/', $mails[0]['body']), 'Mail contains the subscriber ID');
}