public function SimplenewsSourceTest::testSendMissingNode in Simplenews 3.x
Same name and namespace in other branches
- 8.2 tests/src/Functional/SimplenewsSourceTest.php \Drupal\Tests\simplenews\Functional\SimplenewsSourceTest::testSendMissingNode()
Test sending when the issue node is missing.
File
- tests/
src/ Functional/ SimplenewsSourceTest.php, line 370
Class
- SimplenewsSourceTest
- Test cases for creating and sending newsletters.
Namespace
Drupal\Tests\simplenews\FunctionalCode
public function testSendMissingNode() {
$this
->setUpSubscribers(1);
$edit = [
'title[0][value]' => $this
->randomString(10),
'body[0][value]' => "Mail token: <strong>[simplenews-subscriber:mail]</strong>",
'simplenews_issue[target_id]' => 'default',
];
$this
->drupalGet('node/add/simplenews_issue');
$this
->submitForm($edit, 'Save');
$this
->assertEqual(1, preg_match('|node/(\\d+)$|', $this
->getUrl(), $matches), 'Node created');
$node = Node::load($matches[1]);
// Add node to spool.
\Drupal::service('simplenews.spool_storage')
->addIssue($node);
// Delete the node manually in the database.
\Drupal::database()
->delete('node')
->condition('nid', $node
->id())
->execute();
\Drupal::database()
->delete('node_revision')
->condition('nid', $node
->id())
->execute();
\Drupal::entityTypeManager()
->getStorage('node')
->resetCache();
\Drupal::service('simplenews.mailer')
->sendSpool();
// Make sure that no mails have been sent.
$this
->assertEqual(0, count($this
->getMails()));
$spool_row = \Drupal::database()
->query('SELECT * FROM {simplenews_mail_spool}')
->fetchObject();
$this
->assertEqual(SpoolStorageInterface::STATUS_SKIPPED, $spool_row->status);
}