function SimplenewsSourceTest::testSendHidden in Simplenews 8
Send a issue with the newsletter set to hidden.
File
- src/Tests/ SimplenewsSourceTest.php, line 268 
- Simplenews source test functions.
Class
- SimplenewsSourceTest
- Test cases for creating and sending newsletters.
Namespace
Drupal\simplenews\TestsCode
function testSendHidden() {
  $this
    ->setUpSubscribers(5);
  // Set the format to HTML.
  $this
    ->drupalGet('admin/config/services/simplenews');
  $this
    ->clickLink(t('Edit'));
  $edit = array(
    'opt_inout' => 'hidden',
    // @todo: This shouldn't be necessary.
    'from_address' => $this
      ->randomEmail(),
  );
  $this
    ->drupalPostForm(NULL, $edit, t('Save'));
  $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);
  // Send mails.
  \Drupal::service('simplenews.mailer')
    ->sendSpool();
  // Make sure that 5 mails have been sent.
  $this
    ->assertEqual(5, count($this
    ->drupalGetMails()));
  // Test that tokens are correctly replaced.
  foreach (array_slice($this
    ->drupalGetMails(), 0, 3) as $mail) {
    // Verify the unsubscribe link is not displayed for hidden newsletters.
    $this
      ->assertFalse(strpos($mail['body'], (string) t('Unsubscribe from this newsletter')));
  }
}