Example #1
0
 /**
  * Gets the email address of the given object
  *
  * @param object $object
  * @return string The email address or empty string if the object has no email
  */
 public function getEmail($object)
 {
     $result = $this->emailHolderHelper->getEmail($object);
     if (!$result) {
         $emails = $this->relatedEmailsProvider->getEmails($object);
         $result = reset($emails);
     }
     return $result ?: '';
 }
Example #2
0
 /**
  * @param UserInterface $user
  * @param array         $templateData
  * @param string        $type
  *
  * @return int          The return value is the number of recipients who were accepted for delivery
  */
 protected function sendEmail(UserInterface $user, array $templateData, $type)
 {
     list($subjectRendered, $templateRendered) = $templateData;
     $senderEmail = $this->configManager->get('oro_notification.email_notification_sender_email');
     $senderName = $this->configManager->get('oro_notification.email_notification_sender_name');
     $email = $this->emailHolderHelper->getEmail($user);
     $message = \Swift_Message::newInstance()->setSubject($subjectRendered)->setFrom($senderEmail, $senderName)->setTo($email)->setBody($templateRendered, $type);
     return $this->mailer->send($message);
 }
 public function testGetEmailFromRelatedObject()
 {
     $object = new TestCustomEntity();
     $object->setUser(new TestUser('*****@*****.**'));
     $object->setEmailHolder(new TestEmailHolder('*****@*****.**'));
     $object->setOther(new SomeEntity());
     $config = new Config(new EntityConfigId('extend', get_class($object)));
     $config->set('relation', [['owner' => true, 'field_id' => new FieldConfigId('extend', get_class($object), 'user', 'manyToOne'), 'target_entity' => 'Oro\\Bundle\\EmailBundle\\Tests\\Unit\\Fixtures\\Entity\\TestUser'], ['owner' => true, 'field_id' => new FieldConfigId('extend', get_class($object), 'emailHolder', 'manyToOne'), 'target_entity' => 'Oro\\Bundle\\EmailBundle\\Tests\\Unit\\Fixtures\\Entity\\TestEmailHolder'], ['owner' => true, 'field_id' => new FieldConfigId('extend', get_class($object), 'other', 'manyToOne'), 'target_entity' => 'Oro\\Bundle\\EmailBundle\\Tests\\Unit\\Fixtures\\Entity\\SomeEntity']]);
     $this->extendConfigProvider->expects($this->once())->method('hasConfig')->with(get_class($object))->will($this->returnValue(true));
     $this->extendConfigProvider->expects($this->once())->method('getConfig')->with(get_class($object))->will($this->returnValue($config));
     $this->helper->addTargetEntity('Oro\\Bundle\\EmailBundle\\Tests\\Unit\\Fixtures\\Entity\\TestUser');
     $this->helper->addTargetEntity('Oro\\Bundle\\EmailBundle\\Tests\\Unit\\Fixtures\\Entity\\TestEmailHolder', -10);
     $this->assertEquals('*****@*****.**', $this->helper->getEmail($object));
 }
 /**
  * @param string         $templateName
  * @param array          $templateParams
  * @param \Swift_Message $expectedMessage
  * @param string         $emailType
  */
 protected function assertSendCalled($templateName, array $templateParams, \Swift_Message $expectedMessage, $emailType = 'txt')
 {
     $this->emailTemplate->expects($this->once())->method('getType')->willReturn($emailType);
     $this->objectRepository->expects($this->once())->method('findOneBy')->with(['name' => $templateName])->willReturn($this->emailTemplate);
     $this->renderer->expects($this->once())->method('compileMessage')->with($this->emailTemplate, $templateParams)->willReturn([$expectedMessage->getSubject(), $expectedMessage->getBody()]);
     $to = $expectedMessage->getTo();
     $toKeys = array_keys($to);
     $this->emailHolderHelper->expects($this->once())->method('getEmail')->with($this->isInstanceOf('Oro\\Bundle\\UserBundle\\Entity\\UserInterface'))->willReturn(array_shift($toKeys));
     $this->mailer->expects($this->once())->method('send')->with($this->callback(function (\Swift_Message $actualMessage) use($expectedMessage) {
         $this->assertEquals($expectedMessage->getSubject(), $actualMessage->getSubject());
         $this->assertEquals($expectedMessage->getFrom(), $actualMessage->getFrom());
         $this->assertEquals($expectedMessage->getTo(), $actualMessage->getTo());
         $this->assertEquals($expectedMessage->getBody(), $actualMessage->getBody());
         $this->assertEquals($expectedMessage->getContentType(), $actualMessage->getContentType());
         return true;
     }));
 }
Example #5
0
 /**
  * Gets the email address of the given object
  *
  * @param object $object
  * @return string The email address or empty string if the object has no email
  */
 public function getEmail($object)
 {
     $result = $this->emailHolderHelper->getEmail($object);
     return null !== $result ? $result : '';
 }