public function testTransportFactory() { $emailTransport = Transport::factory('email'); $this->assertTrue($emailTransport instanceof \Notifications\Transport\EmailTransport); $pushMessageTransport = Transport::factory('push_message'); $this->assertTrue($pushMessageTransport instanceof \Notifications\Transport\PushMessageTransport); $smsTransport = Transport::factory('sms'); $this->assertTrue($smsTransport instanceof \Notifications\Transport\SmsTransport); try { $invalidTransport = Transport::factory('invalid'); $this->fail('Transport::factory should throw an InvalidArgumentException if an invalid type is given'); } catch (\InvalidArgumentException $e) { } }
/** * Send the notification * * @param Notification $notification notification entity to be sent * @param array $transportConfig optional overriding of transport config * @return mixed */ public function send(Notification $notification, array $transportConfig = []) { $transport = Transport::factory($notification->transport, $transportConfig); $user = $this->RecipientUsers->get($notification->recipient_user_id); $model = TableRegistry::get('Notifications.NotificationContents'); $content = $model->getByIdentifier($notification->notification_identifier, $notification->locale); return $transport->sendNotification($user, $notification, $content); }