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()); }
/** * Add recipients to the specified Email object * * @param Email $obj The Email object recipients is added to * @param string $type The recipient type. Can be to, cc or bcc * @param string $email The email address, for example: john@example.com or "John Smith" <*****@*****.**> */ protected function addRecipients(Email $obj, $type, $email) { if (!empty($email)) { if (is_string($email)) { $obj->addRecipient($this->recipient($type, $email)); } elseif (is_array($email) || $email instanceof \Traversable) { foreach ($email as $e) { $obj->addRecipient($this->recipient($type, $e)); } } } }
public function testUnknownDirectionForCustomEntity() { $getMethodName = "get" . Inflector::classify(self::COLUMN_NAME); $target = $this->getMock('Extend\\Entity\\Test', array($getMethodName)); $target->method($getMethodName)->will($this->returnValue('test' . self::TO_EMAIL)); $email = new Email(); $toEmailAddress = new EmailAddress(); $toEmailAddress->setEmail(self::TO_EMAIL); $recipient = new EmailRecipient(); $recipient->setEmailAddress($toEmailAddress)->setType(EmailRecipient::TO); $email->addRecipient($recipient); $fromEmailAddress = new EmailAddress(); $fromEmailAddress->setEmail(self::FROM_EMAIL); $email->setFromEmailAddress($fromEmailAddress); $this->assertEquals(DirectionProviderInterface::DIRECTION_UNKNOWN, $this->provider->getDirection($email, $target)); }
public function getTestData() { $badEmail = new Email(); $badEmailAddress = new EmailAddress(); $badEmailOwner = new TestEmailOwner(); $badEmailAddress->setOwner($badEmailOwner); $badRecipient = new EmailRecipient(); $badRecipient->setEmailAddress($badEmailAddress); $badEmail->addRecipient($badRecipient); $email = new Email(); $emailAddress = new EmailAddress(); $organization = new TestOrganization(3); $emailOwner = new TestUser(null, null, null, $organization); $emailAddress->setOwner($emailOwner); $recipient = new EmailRecipient(); $recipient->setEmailAddress($emailAddress); $email->addRecipient($recipient); return ['wrong class' => [new \stdClass(), ['integer' => ['organization' => null]]], 'email without correct user organization' => [$badEmail, ['integer' => ['organization' => 0]]], 'correct email' => [$email, ['integer' => ['organization' => [3]]]]]; }
/** * @param Email $email * @param object|null $owner */ protected function addEmailRecipient(Email $email, $owner = null) { $emailAddr = new EmailAddress(); $emailAddr->setOwner($owner); $recipient = new EmailRecipient(); $recipient->setEmailAddress($emailAddr); $email->addRecipient($recipient); }
/** * @param Email $email * @param EmailAddress $addr */ protected function addEmailRecipient(Email $email, EmailAddress $addr) { $recipient = new EmailRecipient(); $recipient->setEmailAddress($addr); $email->addRecipient($recipient); }
/** * @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)); } } }
/** * @SuppressWarnings(PHPMD.ExcessiveMethodLength) */ public function testPersist() { $origin = $this->getMockBuilder('Oro\\Bundle\\EmailBundle\\Entity\\EmailOrigin')->getMock(); $origin->expects($this->any())->method('getId')->will($this->returnValue(1)); $this->batch->addOrigin($origin); $folder = new EmailFolder(); $folder->setName('Exist'); $folder->setFullName('Exist'); $folder->setOrigin($origin); $this->batch->addFolder($folder); $newFolder = new EmailFolder(); $newFolder->setName('New'); $newFolder->setFullName('New'); $newFolder->setOrigin($origin); $this->batch->addFolder($newFolder); $dbFolder = new EmailFolder(); $dbFolder->setName('DbExist'); $dbFolder->setFullName('DbExist'); $dbFolder->setOrigin($origin); $addr = $this->addrManager->newEmailAddress()->setEmail('Exist'); $this->batch->addAddress($addr); $newAddr = $this->addrManager->newEmailAddress()->setEmail('New'); $this->batch->addAddress($newAddr); $dbAddr = $this->addrManager->newEmailAddress()->setEmail('DbExist'); $email1 = new Email(); $email1->setFolder($folder); $email1->setFromEmailAddress($addr); $email1Recip1 = new EmailRecipient(); $email1Recip1->setEmailAddress($addr); $email1Recip2 = new EmailRecipient(); $email1Recip2->setEmailAddress($newAddr); $email1->addRecipient($email1Recip1); $email1->addRecipient($email1Recip2); $this->batch->addEmail($email1); $email2 = new Email(); $email2->setFolder($newFolder); $email2->setFromEmailAddress($newAddr); $email2Recip1 = new EmailRecipient(); $email2Recip1->setEmailAddress($addr); $email2Recip2 = new EmailRecipient(); $email2Recip2->setEmailAddress($newAddr); $email2->addRecipient($email2Recip1); $email2->addRecipient($email2Recip2); $this->batch->addEmail($email2); $em = $this->getMockBuilder('Doctrine\\ORM\\EntityManager')->disableOriginalConstructor()->getMock(); $folderRepo = $this->getMockBuilder('Doctrine\\ORM\\EntityRepository')->disableOriginalConstructor()->getMock(); $addrRepo = $this->getMockBuilder('Doctrine\\ORM\\EntityRepository')->disableOriginalConstructor()->getMock(); $em->expects($this->exactly(2))->method('getRepository')->will($this->returnValueMap(array(array('OroEmailBundle:EmailFolder', $folderRepo), array('Oro\\Bundle\\EmailBundle\\Tests\\Unit\\Entity\\TestFixtures\\TestEmailAddressProxy', $addrRepo)))); $folderRepo->expects($this->exactly(2))->method('findOneBy')->will($this->returnCallback(function ($c) use(&$dbFolder) { return $c['fullName'] === 'Exist' ? $dbFolder : null; })); $addrRepo->expects($this->exactly(2))->method('findOneBy')->will($this->returnCallback(function ($c) use(&$dbAddr) { return $c['email'] === 'Exist' ? $dbAddr : null; })); $em->expects($this->exactly(4))->method('persist')->with($this->logicalOr($this->identicalTo($newFolder), $this->identicalTo($newAddr), $this->identicalTo($email1), $this->identicalTo($email2))); $owner = $this->getMock('Oro\\Bundle\\EmailBundle\\Entity\\EmailOwnerInterface'); $this->ownerProvider->expects($this->any())->method('findEmailOwner')->will($this->returnValue($owner)); $this->batch->persist($em); $this->assertTrue($origin === $email1->getFolder()->getOrigin()); $this->assertTrue($origin === $email2->getFolder()->getOrigin()); $this->assertTrue($dbFolder === $email1->getFolder()); $this->assertTrue($newFolder === $email2->getFolder()); $this->assertTrue($dbAddr === $email1->getFromEmailAddress()); $this->assertNull($email1->getFromEmailAddress()->getOwner()); $this->assertTrue($newAddr === $email2->getFromEmailAddress()); $this->assertTrue($owner === $email2->getFromEmailAddress()->getOwner()); $email1Recipients = $email1->getRecipients(); $this->assertTrue($dbAddr === $email1Recipients[0]->getEmailAddress()); $this->assertNull($email1Recipients[0]->getEmailAddress()->getOwner()); $this->assertTrue($newAddr === $email1Recipients[1]->getEmailAddress()); $this->assertTrue($owner === $email1Recipients[1]->getEmailAddress()->getOwner()); $email2Recipients = $email2->getRecipients(); $this->assertTrue($dbAddr === $email2Recipients[0]->getEmailAddress()); $this->assertNull($email2Recipients[0]->getEmailAddress()->getOwner()); $this->assertTrue($newAddr === $email2Recipients[1]->getEmailAddress()); $this->assertTrue($owner === $email2Recipients[1]->getEmailAddress()->getOwner()); }