function SimplenewsSourceTest::testSendMissingSubscriber in Simplenews 8
Test sending when there are no subscribers.
File
- src/
Tests/ SimplenewsSourceTest.php, line 395 - Simplenews source test functions.
Class
- SimplenewsSourceTest
- Test cases for creating and sending newsletters.
Namespace
Drupal\simplenews\TestsCode
function testSendMissingSubscriber() {
$this
->setUpSubscribers(1);
$edit = array(
'title[0][value]' => $this
->randomString(10),
'body[0][value]' => "Mail token: <strong>[simplenews-subscriber:mail]</strong>",
'simplenews_issue' => 'default',
);
$this
->drupalPostForm('node/add/simplenews_issue', $edit, 'Save');
$this
->assertTrue(preg_match('|node/(\\d+)$|', $this
->getUrl(), $matches), 'Node created');
$node = Node::load($matches[1]);
// Add node to spool.
\Drupal::service('simplenews.spool_storage')
->addFromEntity($node);
// Delete the subscriber.
$subscriber = simplenews_subscriber_load_by_mail(reset($this->subscribers));
$subscriber
->delete();
\Drupal::service('simplenews.mailer')
->sendSpool();
// Make sure that no mails have been sent.
$this
->assertEqual(0, count($this
->drupalGetMails()));
$spool_row = \Drupal::database()
->query('SELECT * FROM {simplenews_mail_spool}')
->fetchObject();
$this
->assertEqual(SpoolStorageInterface::STATUS_DONE, $spool_row->status);
}