SmsTestEventSubscriber.php in SMS Framework 8
File
tests/modules/sms_test/src/EventSubscriber/SmsTestEventSubscriber.php
View source
<?php
namespace Drupal\sms_test\EventSubscriber;
use Symfony\Component\EventDispatcher\Event;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Drupal\sms\Entity\SmsGateway;
use Drupal\sms\Event\SmsEvents;
use Drupal\sms\Event\RecipientGatewayEvent;
class SmsTestEventSubscriber implements EventSubscriberInterface {
public function testAddGateway200(RecipientGatewayEvent $event) {
if (\Drupal::state()
->get('sms_test_event_subscriber__test_gateway_200', FALSE)) {
$gateway = SmsGateway::load('test_gateway_200');
$event
->addGateway($gateway, 200);
}
}
public function testAddGateway400(RecipientGatewayEvent $event) {
if (\Drupal::state()
->get('sms_test_event_subscriber__test_gateway_400', FALSE)) {
$gateway = SmsGateway::load('test_gateway_400');
$event
->addGateway($gateway, 400);
}
}
public function testExecutionOrder(Event $event, $eventName) {
$execution_order = \Drupal::state()
->get('sms_test_event_subscriber__execution_order', []);
$execution_order[] = $eventName;
\Drupal::state()
->set('sms_test_event_subscriber__execution_order', $execution_order);
}
public static function getSubscribedEvents() {
$events[SmsEvents::MESSAGE_GATEWAY][] = [
'testAddGateway200',
];
$events[SmsEvents::MESSAGE_GATEWAY][] = [
'testAddGateway400',
];
$events[SmsEvents::MESSAGE_PRE_PROCESS][] = [
'testExecutionOrder',
];
$events[SmsEvents::MESSAGE_POST_PROCESS][] = [
'testExecutionOrder',
];
$events[SmsEvents::MESSAGE_QUEUE_PRE_PROCESS][] = [
'testExecutionOrder',
];
$events[SmsEvents::MESSAGE_QUEUE_POST_PROCESS][] = [
'testExecutionOrder',
];
$events[SmsEvents::MESSAGE_INCOMING_PRE_PROCESS][] = [
'testExecutionOrder',
];
$events[SmsEvents::MESSAGE_INCOMING_POST_PROCESS][] = [
'testExecutionOrder',
];
$events[SmsEvents::MESSAGE_OUTGOING_PRE_PROCESS][] = [
'testExecutionOrder',
];
$events[SmsEvents::MESSAGE_OUTGOING_POST_PROCESS][] = [
'testExecutionOrder',
];
return $events;
}
}