You are here

public function SimplenewsSourceTest::testSendHidden in Simplenews 3.x

Same name and namespace in other branches
  1. 8.2 tests/src/Functional/SimplenewsSourceTest.php \Drupal\Tests\simplenews\Functional\SimplenewsSourceTest::testSendHidden()

Send a issue with the newsletter set to hidden.

File

tests/src/Functional/SimplenewsSourceTest.php, line 277

Class

SimplenewsSourceTest
Test cases for creating and sending newsletters.

Namespace

Drupal\Tests\simplenews\Functional

Code

public function testSendHidden() {
  $this
    ->setUpSubscribers(5);

  // Set the format to HTML.
  $this
    ->drupalGet('admin/config/services/simplenews');
  $this
    ->clickLink(t('Edit'));
  $edit = [
    'access' => 'hidden',
    // @todo: This shouldn't be necessary.
    'from_address' => $this
      ->randomEmail(),
  ];
  $this
    ->submitForm($edit, 'Save');
  $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);

  // Send mails.
  \Drupal::service('simplenews.mailer')
    ->sendSpool();

  // Make sure that 5 mails have been sent.
  $this
    ->assertEqual(5, count($this
    ->getMails()));

  // Test that tokens are correctly replaced.
  foreach (array_slice($this
    ->getMails(), 0, 3) as $mail) {

    // Verify the unsubscribe link is not displayed for hidden newsletters.
    $this
      ->assertStringNotContainsString((string) t('Unsubscribe from this newsletter'), $mail['body']);
  }
}