public function SmsBlastBrowserTest::testSendBlast in SMS Framework 2.x
Same name and namespace in other branches
- 8 modules/sms_blast/tests/src/Functional/SmsBlastBrowserTest.php \Drupal\Tests\sms_blast\Functional\SmsBlastBrowserTest::testSendBlast()
- 2.1.x modules/sms_blast/tests/src/Functional/SmsBlastBrowserTest.php \Drupal\Tests\sms_blast\Functional\SmsBlastBrowserTest::testSendBlast()
Tests sending SMS blast.
File
- modules/
sms_blast/ tests/ src/ Functional/ SmsBlastBrowserTest.php, line 71
Class
- SmsBlastBrowserTest
- Integration tests for the sms_blast module.
Namespace
Drupal\Tests\sms_blast\FunctionalCode
public function testSendBlast() {
// Create users with multiple phone numbers. Only one message should be sent
// to each user.
$phone_numbers = $this
->randomPhoneNumbers();
$entities = [];
for ($i = 0; $i < 6; $i++) {
/** @var \Drupal\user\UserInterface $user */
$user = $this
->createEntityWithPhoneNumber($this->phoneNumberSettings, $phone_numbers);
// Need to activate so when DER does entity validation it is included by
// the UserSelection plugin.
$user
->activate()
->save();
$entities[] = $user;
}
// Verify three of the users randomly.
$numbers = range(0, count($entities) - 1);
shuffle($numbers);
foreach (array_slice($numbers, 0, 3) as $i) {
$this
->verifyPhoneNumber($entities[$i], $phone_numbers[0]);
}
// Reset messages created as a result of creating entities above. Such as
// verification messages.
$this
->resetTestMessages();
$edit['message'] = $this
->randomString();
$this
->drupalPostForm('sms_blast', $edit, t('Send'));
$this
->assertResponse(200);
$this
->assertText('Message sent to 3 users.');
// Get the resulting message that was sent and confirm.
$this
->assertEqual(3, count($this
->getTestMessages($this->gateway)), 'Sent three messages.');
}