You are here

public function SmsFrameworkRecipientGatewayEventTest::testGatewayEventSubscriber in SMS Framework 2.x

Same name and namespace in other branches
  1. 8 tests/src/Kernel/SmsFrameworkRecipientGatewayEventTest.php \Drupal\Tests\sms\Kernel\SmsFrameworkRecipientGatewayEventTest::testGatewayEventSubscriber()
  2. 2.1.x tests/src/Kernel/SmsFrameworkRecipientGatewayEventTest.php \Drupal\Tests\sms\Kernel\SmsFrameworkRecipientGatewayEventTest::testGatewayEventSubscriber()

Test gateways are applied from the test event subscriber.

See also

\Drupal\sms_test\EventSubscriber\SmsTestEventSubscriber

File

tests/src/Kernel/SmsFrameworkRecipientGatewayEventTest.php, line 47

Class

SmsFrameworkRecipientGatewayEventTest
Tests SMS Framework provider service.

Namespace

Drupal\Tests\sms\Kernel

Code

public function testGatewayEventSubscriber() {
  $gateway_200 = $this
    ->createMemoryGateway([
    'id' => 'test_gateway_200',
  ]);
  $gateway_200
    ->setSkipQueue(TRUE)
    ->save();
  $gateway_400 = $this
    ->createMemoryGateway([
    'id' => 'test_gateway_400',
  ]);
  $gateway_400
    ->setSkipQueue(TRUE)
    ->save();
  \Drupal::state()
    ->set('sms_test_event_subscriber__test_gateway_200', TRUE);
  \Drupal::state()
    ->set('sms_test_event_subscriber__test_gateway_400', TRUE);
  $sms_message = SmsMessage::create()
    ->setDirection(Direction::OUTGOING)
    ->setMessage($this
    ->randomString())
    ->addRecipients($this
    ->randomPhoneNumbers());
  $sms_messages = $this->smsProvider
    ->queue($sms_message);
  $this
    ->assertEquals(1, count($sms_messages), 'One message dispatched.');
  $this
    ->assertEquals('test_gateway_400', $sms_messages[0]
    ->getGateway()
    ->id());
  $this
    ->assertEquals(0, count($this
    ->getTestMessages($gateway_200)), 'Message not sent through gateway_200');
  $this
    ->assertEquals(1, count($this
    ->getTestMessages($gateway_400)), 'Message sent through gateway_400');
}