function SimplenewsSourceTest::testSendMinimalSourceImplementation in Simplenews 8
Tests that sending a minimal implementation of the source interface works.
File
- src/
Tests/ SimplenewsSourceTest.php, line 77 - Simplenews source test functions.
Class
- SimplenewsSourceTest
- Test cases for creating and sending newsletters.
Namespace
Drupal\simplenews\TestsCode
function testSendMinimalSourceImplementation() {
// Create a basic plaintext test source and send it.
$plain_mail = new MailTest('plain');
\Drupal::service('simplenews.mailer')
->sendMail($plain_mail);
$mails = $this
->drupalGetMails();
$mail = $mails[0];
// Assert resulting mail.
$this
->assertEqual('simplenews_node', $mail['id']);
$this
->assertEqual('simplenews', $mail['module']);
$this
->assertEqual('node', $mail['key']);
$this
->assertEqual($plain_mail
->getRecipient(), $mail['to']);
$this
->assertEqual($plain_mail
->getFromAddress(), $mail['from']);
$this
->assertEqual($plain_mail
->getFromFormatted(), $mail['reply-to']);
$this
->assertEqual($plain_mail
->getLanguage(), $mail['langcode']);
$this
->assertTrue($mail['params']['plain']);
$this
->assertFalse(isset($mail['params']['plaintext']));
$this
->assertFalse(isset($mail['params']['attachments']));
$this
->assertEqual($plain_mail
->getSubject(), $mail['subject']);
$this
->assertTrue(strpos($mail['body'], 'the plain body') !== FALSE);
$html_mail = new MailTest('html');
\Drupal::service('simplenews.mailer')
->sendMail($html_mail);
$mails = $this
->drupalGetMails();
$mail = $mails[1];
// Assert resulting mail.
$this
->assertEqual('simplenews_node', $mail['id']);
$this
->assertEqual('simplenews', $mail['module']);
$this
->assertEqual('node', $mail['key']);
$this
->assertEqual($plain_mail
->getRecipient(), $mail['to']);
$this
->assertEqual($plain_mail
->getFromAddress(), $mail['from']);
$this
->assertEqual($plain_mail
->getFromFormatted(), $mail['reply-to']);
$this
->assertEqual($plain_mail
->getLanguage(), $mail['langcode']);
$this
->assertEqual(NULL, $mail['params']['plain']);
$this
->assertTrue(isset($mail['params']['plaintext']));
$this
->assertTrue(strpos($mail['params']['plaintext'], 'the plain body') !== FALSE);
$this
->assertTrue(isset($mail['params']['attachments']));
$this
->assertEqual('example://test.png', $mail['params']['attachments'][0]['uri']);
$this
->assertEqual($plain_mail
->getSubject(), $mail['subject']);
$this
->assertTrue(strpos($mail['body'], 'the body') !== FALSE);
}