예제 #1
0
 public function testRecipientGetterAndSetter()
 {
     $toRecipient = $this->getMock('Oro\\Bundle\\EmailBundle\\Entity\\EmailRecipient');
     $toRecipient->expects($this->any())->method('getType')->will($this->returnValue('to'));
     $ccRecipient = $this->getMock('Oro\\Bundle\\EmailBundle\\Entity\\EmailRecipient');
     $ccRecipient->expects($this->any())->method('getType')->will($this->returnValue('cc'));
     $bccRecipient = $this->getMock('Oro\\Bundle\\EmailBundle\\Entity\\EmailRecipient');
     $bccRecipient->expects($this->any())->method('getType')->will($this->returnValue('bcc'));
     $entity = new Email();
     $entity->addRecipient($toRecipient);
     $entity->addRecipient($ccRecipient);
     $entity->addRecipient($bccRecipient);
     $recipients = $entity->getRecipients();
     $this->assertInstanceOf('Doctrine\\Common\\Collections\\ArrayCollection', $recipients);
     $this->assertCount(3, $recipients);
     $this->assertTrue($toRecipient === $recipients[0]);
     $this->assertTrue($ccRecipient === $recipients[1]);
     $this->assertTrue($bccRecipient === $recipients[2]);
     /** @var GroupNodeDefinition $recipients */
     $recipients = $entity->getRecipients('to');
     $this->assertInstanceOf('Doctrine\\Common\\Collections\\ArrayCollection', $recipients);
     $this->assertCount(1, $recipients);
     $this->assertTrue($toRecipient === $recipients->first());
     $recipients = $entity->getRecipients('cc');
     $this->assertInstanceOf('Doctrine\\Common\\Collections\\ArrayCollection', $recipients);
     $this->assertCount(1, $recipients);
     $this->assertTrue($ccRecipient === $recipients->first());
     $recipients = $entity->getRecipients('bcc');
     $this->assertInstanceOf('Doctrine\\Common\\Collections\\ArrayCollection', $recipients);
     $this->assertCount(1, $recipients);
     $this->assertTrue($bccRecipient === $recipients->first());
 }
 /**
  * Gets all(FROM, TO, CC, BCC) emails.
  *
  * @param Email $email
  *
  * @return string[]
  */
 protected function getEmails(Email $email)
 {
     $emails = [];
     foreach ($email->getRecipients() as $recipient) {
         $emails[] = $recipient->getEmailAddress()->getEmail();
     }
     $emails[] = $email->getFromEmailAddress()->getEmail();
     return array_unique($emails);
 }
예제 #3
0
 /**
  * @param array $targets
  * @param Email $email
  */
 protected function addRecipientOwners(&$targets, Email $email)
 {
     $recipients = $email->getRecipients();
     foreach ($recipients as $recipient) {
         $owner = $recipient->getEmailAddress()->getOwner();
         if ($owner) {
             $this->addTarget($targets, $owner);
         }
     }
 }
예제 #4
0
 /**
  * @param Email    $email
  * @param string   $type
  * @param string[] $recipients
  */
 protected function processRecipients(Email $email, $type, array $recipients)
 {
     if ($email->getId()) {
         $existingRecipients = $email->getRecipients($type);
         if (!$this->areRecipientsEqual($existingRecipients, $recipients)) {
             throw $this->createInvalidPropertyException(sprintf('"%s" recipients', $type), $this->convertRecipientsToString($existingRecipients), $this->convertRecipientsToString($recipients));
         }
     } else {
         foreach ($recipients as $recipient) {
             $email->addRecipient($this->emailEntityBuilder->recipient($type, $recipient));
         }
     }
 }