/** * @dataProvider getTestData */ public function testLinkToScope($config, $managerCalls, $attachmentCalls) { $attachments = $this->getMockBuilder('Oro\\Bundle\\EmailBundle\\Entity\\EmailAttachment')->disableOriginalConstructor()->getMock(); $emailBody = $this->getMockBuilder('Oro\\Bundle\\EmailBundle\\Entity\\EmailBody')->disableOriginalConstructor()->getMock(); $email = $this->getMockBuilder('Oro\\Bundle\\EmailBundle\\Entity\\Email')->disableOriginalConstructor()->getMock(); $event = $this->getMockBuilder('Oro\\Bundle\\EmailBundle\\Event\\EmailBodyAdded')->disableOriginalConstructor()->getMock(); $configInterface = $this->getMockBuilder('Oro\\Bundle\\EntityConfigBundle\\Config\\ConfigInterface')->disableOriginalConstructor()->getMock(); $this->securityFacade->expects($this->once())->method('getToken')->willReturn(1); $this->securityFacade->expects($this->once())->method('isGranted')->willReturn(true); $this->activityListProvider->expects($this->once())->method('getTargetEntities')->willReturn([new SomeEntity()]); $configInterface->expects($this->once())->method('get')->will($this->returnValue($config)); $this->configProvider->expects($this->once())->method('getConfig')->will($this->returnValue($configInterface)); $this->emailAttachmentManager->expects($this->exactly($managerCalls))->method('linkEmailAttachmentToTargetEntity'); $emailBody->expects($this->exactly($attachmentCalls))->method('getAttachments')->will($this->returnValue([$attachments])); $email->expects($this->exactly($attachmentCalls))->method('getEmailBody')->will($this->returnValue($emailBody)); $event->expects($this->exactly(1))->method('getEmail')->will($this->returnValue($email)); $this->listener->linkToScope($event); }
protected function setUp() { $this->emailCacheManager = $this->getMockBuilder('Oro\\Bundle\\EmailBundle\\Cache\\EmailCacheManager')->disableOriginalConstructor()->getMock(); $filesystemMap = $this->getMockBuilder('Knp\\Bundle\\GaufretteBundle\\FilesystemMap')->disableOriginalConstructor()->getMock(); $this->filesystem = $this->getMockBuilder('Gaufrette\\Filesystem')->setMethods(['delete', 'write', 'has'])->disableOriginalConstructor()->getMock(); $filesystemMap->expects($this->once())->method('get')->with('attachments')->will($this->returnValue($this->filesystem)); $this->registry = $this->getMockBuilder('Doctrine\\Bundle\\DoctrineBundle\\Registry')->disableOriginalConstructor()->getMock(); $this->configFileValidator = $this->getMockBuilder('Oro\\Bundle\\AttachmentBundle\\Validator\\ConfigFileValidator')->disableOriginalConstructor()->getMock(); $this->kernel = $this->getMock('Symfony\\Component\\HttpKernel\\KernelInterface'); $this->kernel->expects($this->once())->method('getRootDir')->willReturn(''); $this->om = $this->getMockBuilder('Doctrine\\Common\\Persistence\\ObjectManager')->disableOriginalConstructor()->getMock(); $this->registry->expects($this->any())->method('getManager')->will($this->returnValue($this->om)); $this->securityFacade = $this->getMockBuilder('Oro\\Bundle\\SecurityBundle\\SecurityFacade')->setMethods(['getLoggedUser'])->disableOriginalConstructor()->getMock(); $this->securityFacadeLink = $this->getMockBuilder('Oro\\Bundle\\EntityConfigBundle\\DependencyInjection\\Utils\\ServiceLink')->setMethods(['getService'])->disableOriginalConstructor()->getMock(); $this->securityFacadeLink->expects($this->any())->method('getService')->will($this->returnValue($this->securityFacade)); $this->em = $this->getMockBuilder('Doctrine\\ORM\\EntityManager')->disableOriginalConstructor()->getMock(); $this->attachment = $this->getMockBuilder('Oro\\Bundle\\AttachmentBundle\\Entity\\Attachment')->setMethods(['supportTarget'])->disableOriginalConstructor()->getMock(); $this->attachmentConfig = $this->getMockBuilder('Oro\\Bundle\\AttachmentBundle\\EntityConfig\\AttachmentConfig')->disableOriginalConstructor()->getMock(); $this->emailAttachmentManager = $this->getMockBuilder('Oro\\Bundle\\EmailBundle\\Manager\\EmailAttachmentManager')->setMethods(['getAttachmentFullPath', 'buildAttachmentInstance'])->setConstructorArgs([$filesystemMap, $this->em, $this->kernel, $this->securityFacadeLink, $this->configFileValidator, $this->attachmentConfig])->getMock(); $this->emailAttachmentManager->expects($this->any())->method('getAttachmentFullPath')->willReturn(__DIR__ . '/../Fixtures/attachment/test.txt'); }