Esempio n. 1
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());
 }