예제 #1
0
 public function testEmailGetterAndSetter()
 {
     $email = $this->getMock('Oro\\Bundle\\EmailBundle\\Entity\\Email');
     $entity = new EmailRecipient();
     $entity->setEmail($email);
     $this->assertTrue($email === $entity->getEmail());
 }
예제 #2
0
 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));
 }
예제 #3
0
 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]]]]];
 }
예제 #4
0
파일: Email.php 프로젝트: eltrino/platform
 /**
  * Add recipient
  *
  * @param EmailRecipient $recipient
  *
  * @return Email
  */
 public function addRecipient(EmailRecipient $recipient)
 {
     $this->recipients[] = $recipient;
     $recipient->setEmail($this);
     return $this;
 }
 /**
  * @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);
 }
 /**
  * Create EmailRecipient entity object
  *
  * @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" <*****@*****.**>
  * @return EmailRecipient
  */
 protected function recipient($type, $email)
 {
     $result = new EmailRecipient();
     return $result->setType($type)->setName($email)->setEmailAddress($this->address($email));
 }
 /**
  * @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());
 }