You are here

public function SimplenewsRecipientHandlerTest::testNewUsers in Simplenews 8.2

Same name and namespace in other branches
  1. 3.x tests/src/Functional/SimplenewsRecipientHandlerTest.php \Drupal\Tests\simplenews\Functional\SimplenewsRecipientHandlerTest::testNewUsers()

Tests the "new users" recipient handler.

File

tests/src/Functional/SimplenewsRecipientHandlerTest.php, line 65

Class

SimplenewsRecipientHandlerTest
Test cases for creating and sending newsletters.

Namespace

Drupal\Tests\simplenews\Functional

Code

public function testNewUsers() {

  // Mark users 4&5 as logged in, so that the recipients are users 1-3.
  $users = $this
    ->createUsers();
  foreach (array_slice($users, -2) as $user) {
    $user
      ->setLastAccessTime(time())
      ->save();
  }
  $this
    ->drupalGet('node/add/simplenews_issue');
  $edit = [
    'title[0][value]' => $this
      ->randomString(10),
    'simplenews_issue[target_id]' => 'default',
    'simplenews_issue[handler]' => 'simplenews_new_users',
  ];
  $this
    ->drupalPostForm(NULL, $edit, t('Save'));
  $this
    ->clickLink(t('Newsletter'));
  $this
    ->assertText(t('Send newsletter issue to 3 subscribers.'));
  $this
    ->drupalPostForm(NULL, [], t('Send now'));
  $this
    ->checkRecipients(array_slice($users, 0, 3));
}