public function testSyncOrigins()
 {
     $container = $this->getMock('Symfony\\Component\\DependencyInjection\\ContainerInterface');
     $sync1 = $this->getMockForAbstractClass('Oro\\Bundle\\EmailBundle\\Sync\\AbstractEmailSynchronizer', [], '', false, true, true, ['supports', 'syncOrigins']);
     $sync2 = $this->getMockForAbstractClass('Oro\\Bundle\\EmailBundle\\Sync\\AbstractEmailSynchronizer', [], '', false, true, true, ['supports', 'syncOrigins']);
     $origin1 = new InternalEmailOrigin();
     $origin1->setName('origin1');
     ReflectionUtil::setId($origin1, 1);
     $origin2 = new InternalEmailOrigin();
     $origin2->setName('origin2');
     ReflectionUtil::setId($origin2, 2);
     $origin3 = new InternalEmailOrigin();
     $origin3->setName('origin3');
     ReflectionUtil::setId($origin3, 3);
     $sync1->expects($this->at(0))->method('supports')->with($origin1)->will($this->returnValue(false));
     $sync1->expects($this->at(1))->method('supports')->with($origin2)->will($this->returnValue(true));
     $sync1->expects($this->at(2))->method('supports')->with($origin3)->will($this->returnValue(false));
     $sync1->expects($this->at(3))->method('syncOrigins')->with([2]);
     $sync2->expects($this->at(0))->method('supports')->with($origin1)->will($this->returnValue(false));
     $sync2->expects($this->at(1))->method('supports')->with($origin2)->will($this->returnValue(false));
     $sync2->expects($this->at(2))->method('supports')->with($origin3)->will($this->returnValue(true));
     $sync2->expects($this->at(3))->method('syncOrigins')->with([3]);
     $container->expects($this->any())->method('get')->will($this->returnValueMap([['sync1', ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, $sync1], ['sync2', ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, $sync2]]));
     $manager = new EmailSynchronizationManager($container);
     $manager->addSynchronizer('sync1');
     $manager->addSynchronizer('sync2');
     $manager->syncOrigins([$origin1, $origin2, $origin3]);
 }
 /**
  * {@inheritDoc}
  */
 public function load(ObjectManager $manager)
 {
     $outboxFolder = new EmailFolder();
     $outboxFolder->setType(EmailFolder::SENT)->setName(EmailFolder::SENT)->setFullName(EmailFolder::SENT);
     $origin = new InternalEmailOrigin();
     $origin->setName(InternalEmailOrigin::BAP)->addFolder($outboxFolder);
     $manager->persist($origin);
     $manager->flush();
 }
Esempio n. 3
0
 /**
  * {@inheritdoc}
  */
 public function load(ObjectManager $manager)
 {
     $userManager = $this->container->get('oro_user.manager');
     $organization = $manager->getRepository('OroOrganizationBundle:Organization')->getFirst();
     $role = $manager->getRepository('OroUserBundle:Role')->findOneBy(['role' => 'ROLE_ADMINISTRATOR']);
     $user = $userManager->createUser();
     $user->setUsername('simple_user')->setPlainPassword('simple_password')->setEmail('*****@*****.**')->setOrganization($organization)->addOrganization($organization)->setEnabled(true)->addRole($role);
     $folder = new EmailFolder();
     $folder->setName('sent');
     $folder->setFullName('sent');
     $folder->setType('sent');
     $origin = new InternalEmailOrigin();
     $origin->setName('simple_user_origin_name');
     $origin->setActive(true);
     $origin->addFolder($folder);
     $origin->setOwner($user);
     $origin->setOrganization($organization);
     $user->addEmailOrigin($origin);
     $userManager->updateUser($user);
     $user2 = $userManager->createUser();
     $user2->setUsername('simple_user2')->setPlainPassword('simple_password2')->setFirstName('Elley')->setLastName('Towards')->setEmail('*****@*****.**')->setOrganization($organization)->addOrganization($organization)->setEnabled(true);
     $folder2 = new EmailFolder();
     $folder2->setName('sent');
     $folder2->setFullName('sent');
     $folder2->setType('sent');
     $origin2 = new InternalEmailOrigin();
     $origin2->setName('simple_user_origin_name_2');
     $origin2->setActive(true);
     $origin2->addFolder($folder2);
     $origin2->setOwner($user2);
     $origin2->setOrganization($organization);
     $user2->addEmailOrigin($origin);
     $userManager->updateUser($user2);
     $this->setReference($user->getUsername(), $user);
     $this->setReference($user2->getUsername(), $user2);
 }
 /**
  * @dataProvider supportedMethods
  */
 public function testProcessValidData($method)
 {
     $this->request->setMethod($method);
     $this->model->setFrom('*****@*****.**')->setTo(array('*****@*****.**'))->setSubject('testSubject')->setBody('testBody');
     $this->form->expects($this->once())->method('setData')->with($this->model);
     $this->form->expects($this->once())->method('submit')->with($this->request);
     $this->form->expects($this->once())->method('isValid')->will($this->returnValue(true));
     $message = new \Swift_Message();
     $this->mailer->expects($this->once())->method('createMessage')->will($this->returnValue($message));
     $this->mailer->expects($this->once())->method('send')->will($this->returnValue(1));
     $origin = new InternalEmailOrigin();
     $folder = new EmailFolder();
     $folder->setType(EmailFolder::SENT);
     $origin->addFolder($folder);
     $emailOriginRepo = $this->getMockBuilder('Doctrine\\ORM\\EntityRepository')->disableOriginalConstructor()->getMock();
     $emailOriginRepo->expects($this->once())->method('findOneBy')->with(array('name' => InternalEmailOrigin::BAP))->will($this->returnValue($origin));
     $this->em->expects($this->once())->method('getRepository')->with('OroEmailBundle:InternalEmailOrigin')->will($this->returnValue($emailOriginRepo));
     $this->emailEntityBuilder->expects($this->once())->method('setOrigin')->with($this->identicalTo($origin));
     $email = new EmailEntity();
     $this->emailEntityBuilder->expects($this->once())->method('email')->with('testSubject', '*****@*****.**', array('*****@*****.**'))->will($this->returnValue($email));
     $body = new EmailBody();
     $this->emailEntityBuilder->expects($this->once())->method('body')->with('testBody', false, true)->will($this->returnValue($body));
     $batch = $this->getMock('Oro\\Bundle\\EmailBundle\\Builder\\EmailEntityBatchInterface');
     $this->emailEntityBuilder->expects($this->once())->method('getBatch')->will($this->returnValue($batch));
     $batch->expects($this->once())->method('persist')->with($this->identicalTo($this->em));
     $this->em->expects($this->once())->method('flush');
     $this->assertTrue($this->handler->process($this->model));
     $this->assertNotNull($message);
     $this->assertEquals(array('*****@*****.**' => null), $message->getFrom());
     $this->assertEquals(array('*****@*****.**' => null), $message->getTo());
     $this->assertEquals('testSubject', $message->getSubject());
     $this->assertEquals('testBody', $message->getBody());
     $this->assertTrue($folder === $email->getFolder());
     $this->assertTrue($body === $email->getEmailBody());
 }
Esempio n. 5
0
 protected function getTestOrigin()
 {
     $outboxFolder = new EmailFolder();
     $outboxFolder->setType(FolderType::SENT)->setName(FolderType::SENT)->setFullName(FolderType::SENT);
     $origin = new InternalEmailOrigin();
     $origin->setName('BAP_User_1')->addFolder($outboxFolder)->setOwner($this->getTestUser())->setOrganization($this->getTestOrganization());
     return $origin;
 }
Esempio n. 6
0
 /**
  * @param User                  $emailOwner
  * @param OrganizationInterface $organization
  *
  * @return InternalEmailOrigin
  */
 protected function createUserInternalOrigin(User $emailOwner, OrganizationInterface $organization = null)
 {
     $organization = $organization ? $organization : $emailOwner->getOrganization();
     $originName = InternalEmailOrigin::BAP . '_User_' . $emailOwner->getId();
     $outboxFolder = new EmailFolder();
     $outboxFolder->setType(FolderType::SENT)->setName(FolderType::SENT)->setFullName(FolderType::SENT);
     $origin = new InternalEmailOrigin();
     $origin->setName($originName)->addFolder($outboxFolder)->setOwner($emailOwner)->setOrganization($organization);
     $emailOwner->addEmailOrigin($origin);
     $this->getEntityManager()->persist($origin);
     $this->getEntityManager()->persist($emailOwner);
     return $origin;
 }
Esempio n. 7
0
 /**
  * @param User                  $originOwner
  * @param OrganizationInterface $organization
  * @param string                $originName
  *
  * @return InternalEmailOrigin
  */
 protected function createEmailOrigin(User $originOwner, OrganizationInterface $organization, $originName)
 {
     $origin = new InternalEmailOrigin();
     $origin->setName($originName);
     $origin->setOwner($originOwner);
     $origin->setOrganization($organization);
     $originOwner->addEmailOrigin($origin);
     $this->entityManager->persist($origin);
     return $origin;
 }
 public function testNameGetterAndSetter()
 {
     $entity = new InternalEmailOrigin();
     $entity->setName('test');
     $this->assertEquals('test', $entity->getName());
 }