public function SimplenewsSourceTest::testSendMinimalSourceImplementation in Simplenews 3.x
Same name and namespace in other branches
- 8.2 tests/src/Functional/SimplenewsSourceTest.php \Drupal\Tests\simplenews\Functional\SimplenewsSourceTest::testSendMinimalSourceImplementation()
Tests that sending a minimal implementation of the source interface works.
File
- tests/
src/ Functional/ SimplenewsSourceTest.php, line 75
Class
- SimplenewsSourceTest
- Test cases for creating and sending newsletters.
Namespace
Drupal\Tests\simplenews\FunctionalCode
public 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
->getMails();
$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
->assertStringContainsString('the plain body', $mail['body']);
// Now send an HTML message.
$config = $this
->config('simplenews.settings');
$config
->set('mail.textalt', TRUE);
$config
->save();
$html_mail = new MailTest('html');
\Drupal::service('simplenews.mailer')
->sendMail($html_mail);
$mails = $this
->getMails();
$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
->assertStringContainsString('the plain body', $mail['params']['plaintext']);
$this
->assertTrue(isset($mail['params']['attachments']));
$this
->assertEqual('example://test.png', $mail['params']['attachments'][0]['uri']);
$this
->assertEqual($plain_mail
->getSubject(), $mail['subject']);
$this
->assertStringContainsString('the body', $mail['body']);
}