public function SimplenewsRecipientHandlerTest::testSubscribersByRole in Simplenews 8.2
Same name and namespace in other branches
- 3.x 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\FunctionalCode
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
->drupalPostForm(NULL, $edit, t('Save'));
// Edit and set the role.
$this
->clickLink(t('Edit'));
$this
->assertText(t('Role'));
$edit = [
'simplenews_issue[handler_settings][role]' => $rid,
];
$this
->drupalPostForm(NULL, $edit, t('Save'));
$this
->clickLink(t('Newsletter'));
$this
->assertText(t('Send newsletter issue to 2 subscribers.'));
$this
->drupalPostForm(NULL, [], t('Send now'));
$this
->checkRecipients($recipients);
}