/**
  * @dataProvider getNotificationWithNotifierParameters
  */
 public function testGetConfigurationWithNotifierParameters(Notification $notification)
 {
     $entityManager = $this->getMockBuilder('\\Doctrine\\ORM\\EntityManager')->disableOriginalConstructor()->getMock();
     $defaultConfiguration = array();
     $emailNotifier = new EmailNotifier($entityManager, $defaultConfiguration);
     $this->assertEquals($notification->getFromDecoded(), $emailNotifier->getConfiguration($notification));
 }
 public function testBuildGcmMessage()
 {
     $toData = array("deviceToken" => "abcd1234");
     $contentData = array("message" => "test");
     $pushAndroidNotification = new Notification();
     $pushAndroidNotification->setTo(json_encode($toData))->setContent(json_encode($contentData));
     $gcmMessage = array('message' => $contentData['message'], 'vibrate' => 1, 'sound' => 1);
     $gcmFields = array('delay_while_idle' => true, 'registration_ids' => array($toData['deviceToken']), 'data' => $gcmMessage);
     $this->assertEquals(json_encode($gcmFields), PushAndroidNotifier::buildGcmMessage($pushAndroidNotification));
 }
 /**
  * {@inheritdoc}
  */
 public function sendNotification(Notification $notification)
 {
     $to = json_decode($notification->getTo(), true);
     $content = json_decode($notification->getContent(), true);
     $configuration = $this->getConfiguration($notification);
     $message = \Swift_Message::newInstance()->setSubject(isset($content['subject']) ? $content['subject'] : null)->setFrom(array($configuration['from'] => $configuration['fromName']))->setReplyTo(isset($configuration['replyTo']) ? $configuration['replyTo'] : null)->setTo($to['to'])->setCc(isset($to['cc']) ? $to['cc'] : null)->setBcc(isset($to['bcc']) ? $to['bcc'] : null)->setBody(isset($content['message']) ? $content['message'] : null);
     if ($content['htmlMessage']) {
         $message->addPart($content['htmlMessage'], 'text/html');
     }
     $mailer = $this->getMailer($configuration);
     return $mailer->send($message) > 0;
 }
 /**
  * {@inheritdoc}
  */
 public function getConfiguration(Notification $notification)
 {
     if ($notification->hasNotifierAlias()) {
         try {
             return $this->getDataBaseConfiguration($notification->getNotifierAlias(), $notification->getType());
         } catch (UndefinedNotifierConfigurationException $e) {
             return $this->getFileConfiguration($notification->getNotifierAlias());
         }
     }
     if (null !== $notification->getFrom()) {
         $from = json_decode($notification->getFrom(), true);
         if (null === $from) {
             throw new ConfigurationParseErrorException($notification->getFrom());
         } elseif (count($from) > 0) {
             return $from;
         }
     }
     return $this->getFileConfiguration();
 }
 /**
  * Notify
  *
  * @param Notification $notification
  */
 public function notify(Notification $notification)
 {
     $notifier = $this->getNotifier($notification->getType());
     try {
         $notifier->sendNotification($notification);
         $notification->setStatus(Notification::STATUS_DONE);
     } catch (\Exception $e) {
         $notification->setStatus(Notification::STATUS_ERROR);
         $notification->addLog($e->getMessage());
     }
     $this->getObjectManager()->persist($notification);
     $this->getObjectManager()->flush();
 }
 /**
  * {@inheritdoc}
  */
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     $builder->add('status', 'choice', array('choices' => Notification::getStatusList()))->add('type', 'notifier_choice')->add('notifierAlias')->add('from')->add('to')->add('content', 'textarea')->add('source')->add('log');
 }
 /**
  * {@inheritdoc}
  */
 public function sendNotification(Notification $notification)
 {
     $path = '/statuses/update.json';
     $response = $this->getApiClient()->post($path, $notification->getContentDecoded(), $this->buildHeaders($path, "POST", $notification));
     return null !== $response ? true : false;
 }
 /**
  * @dataProvider getProvidedData
  */
 public function testGetContentDecoded(Notification $emailNotification)
 {
     $this->assertEquals(json_decode($emailNotification->getContent(), true), $emailNotification->getContentDecoded());
 }