You are here

function SimplenewsSourceTest::testSendMissingNode in Simplenews 8

Test sending when the issue node is missing.

File

src/Tests/SimplenewsSourceTest.php, line 359
Simplenews source test functions.

Class

SimplenewsSourceTest
Test cases for creating and sending newsletters.

Namespace

Drupal\simplenews\Tests

Code

function testSendMissingNode() {
  $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 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
    ->drupalGetMails()));
  $spool_row = \Drupal::database()
    ->query('SELECT * FROM {simplenews_mail_spool}')
    ->fetchObject();
  $this
    ->assertEqual(SpoolStorageInterface::STATUS_DONE, $spool_row->status);
}