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]); }
public function testAddFolder() { $folder = new EmailFolder(); $folder->setType('sent'); $folder->setName('Test'); $folder->setFullName('Test'); $this->batch->addFolder($folder); $this->assertCount(1, ReflectionUtil::getProtectedProperty($this->batch, 'folders')); $this->assertEquals('Test', $this->batch->getFolder('sent', 'TeST')->getFullName()); $this->assertNull($this->batch->getFolder('sent', 'Another')); $folder1 = new EmailFolder(); $folder1->setType('trash'); $folder1->setName('Test'); $folder1->setFullName('Test'); $this->batch->addFolder($folder1); $this->assertCount(2, ReflectionUtil::getProtectedProperty($this->batch, 'folders')); $this->assertEquals('Test', $this->batch->getFolder('trash', 'TeST')->getFullName()); $this->assertNull($this->batch->getFolder('trash', 'Another')); $this->setExpectedException('LogicException'); $folder2 = new EmailFolder(); $folder2->setType('sent'); $folder2->setName('TEST'); $folder2->setFullName('TEST'); $this->batch->addFolder($folder2); }
public function testAddOrigin() { $origin = $this->getMockBuilder('Oro\\Bundle\\EmailBundle\\Entity\\EmailOrigin')->getMock(); $origin->expects($this->any())->method('getId')->will($this->returnValue(1)); $this->batch->addOrigin($origin); $this->assertCount(1, ReflectionUtil::getProtectedProperty($this->batch, 'origins')); $this->assertEquals(1, $this->batch->getOrigin(1)->getId()); $this->assertNull($this->batch->getOrigin(123)); }
public function testIdGetter() { $entity = new EmailAttachmentContent(); ReflectionUtil::setId($entity, 1); $this->assertEquals(1, $entity->getId()); }
public function testGetId() { $imapEmail = new ImapEmail(); ReflectionUtil::setId($imapEmail, 123); $this->assertEquals(123, $imapEmail->getId()); }
public function testIdGetter() { $entity = new TestEmailOrigin(); ReflectionUtil::setId($entity, 1); $this->assertEquals(1, $entity->getId()); }
public function testGetId() { $imapFolder = new ImapEmailFolder(); ReflectionUtil::setId($imapFolder, 123); $this->assertEquals(123, $imapFolder->getId()); }
/** * @dataProvider preciseFullEmailAddressProvider */ public function testPreciseFullEmailAddress($expected, $emailAddress, $ownerClass, $ownerId) { $this->nameFormatter->expects($this->any())->method('format')->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'))); } $srcEmailAddress = $emailAddress; $param = [&$emailAddress, $ownerClass, $ownerId]; ReflectionUtil::callProtectedMethod($this->handler, 'preciseFullEmailAddress', $param); $this->assertEquals($expected, $emailAddress); }
/** * @expectedException \Oro\Bundle\EmailBundle\Exception\EmailBodyNotFoundException * @expectedExceptionMessage Cannot find a body for "test email" email. */ public function testSyncOneEmailBodyNotFound() { $email = new Email(); ReflectionUtil::setId($email, 123); $email->setSubject('test email'); $emailBody = new EmailBody(); $emailUser = new EmailUser(); $origin = new TestEmailOrigin(); $folder = new EmailFolder(); $folder->setOrigin($origin); $emailUser->setOrigin($origin); $emailUser->addFolder($folder); $email->addEmailUser($emailUser); $exception = new EmailBodyNotFoundException($email); $loader = $this->getMock('Oro\\Bundle\\EmailBundle\\Provider\\EmailBodyLoaderInterface'); $this->selector->expects($this->once())->method('select')->with($this->identicalTo($origin))->will($this->returnValue($loader)); $loader->expects($this->once())->method('loadEmailBody')->will($this->throwException($exception)); $this->em->expects($this->never())->method('persist'); $this->em->expects($this->never())->method('flush'); $this->logger->expects($this->once())->method('notice')->with('Load email body failed. Email id: 123. Error: Cannot find a body for "test email" email.', ['exception' => $exception]); $this->logger->expects($this->never())->method('warning'); $this->synchronizer->syncOneEmailBody($email); $this->assertSame($emailBody, $email->getEmailBody()); }
public function testGetId() { $origin = new UserEmailOrigin(); ReflectionUtil::setId($origin, 123); $this->assertEquals(123, $origin->getId()); }
/** * @param string $folderName * @param string $folderFullName * @param int $uidValidity * @param int|null $id * * @return ImapEmailFolder */ protected function createImapFolder($folderName, $folderFullName, $uidValidity, $id = null) { $folder = new EmailFolder(); $folder->setName($folderName)->setFullName($folderFullName); $imapFolder = new ImapEmailFolder(); $imapFolder->setFolder($folder)->setUidValidity($uidValidity); if ($id !== null) { ReflectionUtil::setId($imapFolder, $id); } return $imapFolder; }
public function testCreateEmailAddress() { $owner = $this->getMock('Oro\\Bundle\\EmailBundle\\Entity\\EmailOwnerInterface'); $addrManager = $this->getMockBuilder('Oro\\Bundle\\EmailBundle\\Entity\\Manager\\EmailAddressManager')->disableOriginalConstructor()->getMock(); $addr = $this->getMock('Oro\\Bundle\\EmailBundle\\Entity\\EmailAddress'); $addrManager->expects($this->once())->method('newEmailAddress')->will($this->returnValue($addr)); $addr->expects($this->once())->method('setEmail')->with($this->equalTo('*****@*****.**'))->will($this->returnValue($addr)); $addr->expects($this->once())->method('setOwner')->with($this->identicalTo($owner))->will($this->returnValue($addr)); $manager = new EmailOwnerManager($this->getEmailOwnerProviderStorageMock(), $addrManager); ReflectionUtil::callProtectedMethod($manager, 'createEmailAddress', array('*****@*****.**', $owner)); }