You are here

public function SimplenewsRecipientHandlerTest::testSubscribersByRole in Simplenews 3.x

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

Tests the "subscribers by role" recipient handler.

File

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

Class

SimplenewsRecipientHandlerTest
Test cases for creating and sending newsletters.

Namespace

Drupal\Tests\simplenews\Functional

Code

public function testSubscribersByRole() {

  // Grant users 3&4 a role.
  $users = $this
    ->createUsers('subscribe');
  $recipients = array_slice($users, 2, 2);
  $rid = $this
    ->createRole([]);
  foreach ($recipients as $user) {
    $user
      ->addRole($rid);
    $user
      ->save();
  }
  $this
    ->drupalGet('node/add/simplenews_issue');
  $edit = [
    'title[0][value]' => $this
      ->randomString(10),
    'simplenews_issue[target_id]' => 'default',
    'simplenews_issue[handler]' => 'simplenews_subscribers_by_role',
  ];
  $this
    ->submitForm($edit, 'Save');

  // Edit and set the role.
  $this
    ->clickLink(t('Edit'));
  $this
    ->assertText(t('Role'));
  $edit = [
    'simplenews_issue[handler_settings][role]' => $rid,
  ];
  $this
    ->submitForm($edit, 'Save');
  $this
    ->clickLink(t('Newsletter'));
  $this
    ->assertText(t('Send newsletter issue to 2 subscribers.'));
  $this
    ->submitForm([], 'Send now');
  $this
    ->checkRecipients($recipients);
}