public function testGetMessageParamsForRemindersSetupCorrectParams()
 {
     $expectedId = 42;
     $expectedSubject = 'testSubject';
     $expectedExpireAt = new \DateTime();
     $expectedFormattedExpireAt = 'formatted date time';
     $expectedUrl = 'www.tests.com';
     $reminder = $this->getMock('Oro\\Bundle\\ReminderBundle\\Entity\\Reminder');
     $reminder->expects($this->once())->method('getId')->will($this->returnValue($expectedId));
     $reminder->expects($this->exactly(2))->method('getExpireAt')->will($this->returnValue($expectedExpireAt));
     $reminder->expects($this->once())->method('getSubject')->will($this->returnValue($expectedSubject));
     $this->dateTimeFormatter->expects($this->at(0))->method('formatDate')->will($this->returnValue(new \DateTime()));
     $this->dateTimeFormatter->expects($this->once())->method('format')->with($expectedExpireAt)->will($this->returnValue($expectedFormattedExpireAt));
     $this->urlProvider->expects($this->once())->method('getUrl')->will($this->returnValue($expectedUrl));
     $expectedIdentifier = 'test_template_identifier';
     $expectedRelatedClassName = 'Tasks';
     $reminder->expects($this->exactly(2))->method('getRelatedEntityClassName')->will($this->returnValue($expectedRelatedClassName));
     $configInterface = $this->getMockForAbstractClass('Oro\\Bundle\\EntityConfigBundle\\Config\\ConfigInterface');
     $configInterface->expects($this->once())->method('get')->will($this->returnValue($expectedIdentifier));
     $this->configProvider->expects($this->once())->method('getConfig')->with($expectedRelatedClassName)->will($this->returnValue($configInterface));
     $params = $this->messageParamsProvider->getMessageParamsForReminders(array($reminder));
     $this->assertCount(1, $params);
     $this->assertEquals($expectedId, $params[0]['id']);
     $this->assertEquals($expectedUrl, $params[0]['url']);
     $this->assertEquals($expectedSubject, $params[0]['subject']);
     $this->assertEquals($expectedFormattedExpireAt, $params[0]['expireAt']);
     $this->assertEquals($expectedIdentifier, $params[0]['templateId']);
 }
Beispiel #2
0
 /**
  * Get requested reminders
  *
  * @return string
  */
 public function getRequestedRemindersData()
 {
     /** @var User|null */
     $user = $this->securityContext->getToken() ? $this->securityContext->getToken()->getUser() : null;
     if (is_object($user) && $user instanceof User) {
         $reminders = $this->entityManager->getRepository('OroReminderBundle:Reminder')->findRequestedReminders($user);
         return $this->messageParamsProvider->getMessageParamsForReminders($reminders);
     }
     return array();
 }
 /**
  * Send group of reminders to recipient
  *
  * @param Reminder[] $reminders
  * @param integer $recipientId
  */
 protected function processRecipientReminders(array $reminders, $recipientId)
 {
     $messageData = array();
     // Collect message data
     foreach ($reminders as $reminder) {
         $messageData[] = $this->messageParamsProvider->getMessageParams($reminder);
     }
     // Send message
     try {
         $this->sendMessage($messageData, $recipientId);
         // Change state
         foreach ($reminders as $reminder) {
             $reminder->setState(Reminder::STATE_REQUESTED);
         }
     } catch (\Exception $exception) {
         foreach ($reminders as $reminder) {
             $reminder->setState(Reminder::STATE_FAIL);
             $reminder->setFailureException($exception);
         }
     }
 }