public function testGetDirection()
 {
     $fromEmail = '*****@*****.**';
     $toEmail = '*****@*****.**';
     $sender = new TestEmailHolder($fromEmail);
     $reciver = new TestEmailHolder($toEmail);
     $email = new Email();
     $emailAddress = new EmailAddress();
     $emailAddress->setEmail($fromEmail);
     $email->setFromEmailAddress($emailAddress);
     $this->assertEquals(DirectionProviderInterface::DIRECTION_INCOMING, $this->provider->getDirection($email, $reciver));
     $this->assertEquals(DirectionProviderInterface::DIRECTION_OUTGOING, $this->provider->getDirection($email, $sender));
 }
 /**
  * @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);
 }
 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]]]]];
 }
 protected function setUp()
 {
     $this->form = $this->getMockBuilder('Symfony\\Component\\Form\\Form')->disableOriginalConstructor()->getMock();
     $this->request = new Request();
     $this->em = $this->getMockBuilder('Doctrine\\ORM\\EntityManager')->disableOriginalConstructor()->getMock();
     $this->translator = $this->getMockBuilder('Symfony\\Component\\Translation\\Translator')->disableOriginalConstructor()->getMock();
     $this->securityContext = $this->getMock('Symfony\\Component\\Security\\Core\\SecurityContextInterface');
     $this->emailAddressManager = $this->getMockBuilder('Oro\\Bundle\\EmailBundle\\Entity\\Manager\\EmailAddressManager')->disableOriginalConstructor()->getMock();
     $this->emailEntityBuilder = $this->getMockBuilder('Oro\\Bundle\\EmailBundle\\Builder\\EmailEntityBuilder')->disableOriginalConstructor()->getMock();
     $this->mailer = $this->getMockBuilder('\\Swift_Mailer')->disableOriginalConstructor()->getMock();
     $this->logger = $this->getMock('Psr\\Log\\LoggerInterface');
     $this->nameFormatter = $this->getMockBuilder('Oro\\Bundle\\LocaleBundle\\Formatter\\NameFormatter')->disableOriginalConstructor()->getMock();
     $emailAddressRepository = $this->getMockBuilder('Doctrine\\ORM\\EntityRepository')->disableOriginalConstructor()->getMock();
     $emailAddressRepository->expects($this->any())->method('findOneBy')->will($this->returnCallback(function ($args) {
         $emailAddress = new EmailAddress();
         $emailAddress->setEmail($args['email']);
         $emailAddress->setOwner(new TestUser($args['email'], 'FirstName', 'LastName'));
         return $emailAddress;
     }));
     $this->emailAddressManager->expects($this->any())->method('getEmailAddressRepository')->with($this->identicalTo($this->em))->will($this->returnValue($emailAddressRepository));
     $this->model = new Email();
     $this->handler = new EmailHandler($this->form, $this->request, $this->em, $this->translator, $this->securityContext, $this->emailAddressManager, $this->emailEntityBuilder, $this->mailer, $this->logger, $this->nameFormatter);
 }
 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 testUpdatedAtGetterAndSetter()
 {
     $date = new \DateTime('now', new \DateTimeZone('UTC'));
     $entity = new EmailAddress(null, $date);
     $this->assertEquals($date, $entity->getUpdated());
 }
 /**
  * @dataProvider preciseFullEmailAddressProvider
  */
 public function testPreciseFullEmailAddressWithProvider($expected, $emailAddress, $ownerClass, $ownerId)
 {
     $emailAddressRepository = $this->getMockBuilder('Doctrine\\ORM\\EntityRepository')->disableOriginalConstructor()->getMock();
     $emailAddressRepository->expects($this->any())->method('findOneBy')->will($this->returnCallback(function ($args) {
         $emailAddress = new EmailAddress();
         $emailAddress->setEmail($args['email']);
         $emailAddress->setOwner(new TestUser($args['email'], 'FirstName', 'LastName'));
         return $emailAddress;
     }));
     $this->emailAddressManager->expects($this->any())->method('getEmailAddressRepository')->with($this->identicalTo($this->entityManager))->will($this->returnValue($emailAddressRepository));
     $this->entityNameResolver->expects($this->any())->method('getName')->with($this->isInstanceOf('Oro\\Bundle\\EmailBundle\\Tests\\Unit\\Fixtures\\Entity\\TestUser'))->will($this->returnCallback(function ($obj) {
         return $obj->getFirstName() . ' ' . $obj->getLastName();
     }));
     if ($ownerId) {
         $this->entityRoutingHelper->expects($this->once())->method('getEntity')->with($ownerClass, $ownerId)->will($this->returnValue(new TestUser($emailAddress, 'OwnerFirstName', 'OwnerLastName')));
     }
     $this->helper->preciseFullEmailAddress($emailAddress, $ownerClass, $ownerId);
     $this->assertEquals($expected, $emailAddress);
 }