public function testGetScopeEntityAttachments()
 {
     $entity = $this->getMock('\\stdClass');
     $oroAttachments = [];
     $size = 3;
     for ($i = 0; $i < $size; $i++) {
         $oroAttachments[] = $this->getMock('Oro\\Bundle\\AttachmentBundle\\Entity\\Attachment');
     }
     $this->attachmentProvider->expects($this->once())->method('getEntityAttachments')->with($entity)->willReturn($oroAttachments);
     $this->emailAttachmentTransformer->expects($this->exactly($size))->method('oroToModel');
     $result = $this->emailAttachmentProvider->getScopeEntityAttachments($entity);
     $this->assertTrue(is_array($result));
     $this->assertEquals($size, sizeof($result));
 }
 protected function setUp()
 {
     $this->request = new Request();
     $this->entityManager = $this->getMockBuilder('Doctrine\\ORM\\EntityManager')->disableOriginalConstructor()->getMock();
     $this->helper = $this->getMockBuilder('Oro\\Bundle\\EmailBundle\\Builder\\Helper\\EmailModelBuilderHelper')->disableOriginalConstructor()->getMock();
     $this->configManager = $this->getMockBuilder('Oro\\Bundle\\ConfigBundle\\Config\\ConfigManager')->disableOriginalConstructor()->getMock();
     $this->activityListProvider = $this->getMockBuilder('Oro\\Bundle\\EmailBundle\\Provider\\EmailActivityListProvider')->disableOriginalConstructor()->getMock();
     $this->emailAttachmentProvider = $this->getMockBuilder('Oro\\Bundle\\EmailBundle\\Provider\\EmailAttachmentProvider')->disableOriginalConstructor()->getMock();
     $this->emailAttachmentProvider->expects($this->any())->method('getThreadAttachments')->willReturn([]);
     $this->emailAttachmentProvider->expects($this->any())->method('getScopeEntityAttachments')->willReturn([]);
     $this->email = $this->getMockBuilder('Oro\\Bundle\\EmailBundle\\Entity\\Email')->setMethods(['getActivityTargetEntities', 'getFromEmailAddress', 'getId', 'getTo', 'getCc', 'getEmailBody'])->getMock();
     $this->email->expects($this->any())->method('getActivityTargetEntities')->willReturn([]);
     $this->factory = new Factory();
     $this->emailModelBuilder = new EmailModelBuilder($this->helper, $this->request, $this->entityManager, $this->configManager, $this->activityListProvider, $this->emailAttachmentProvider, $this->factory);
 }
 /**
  * @param EmailModel $emailModel
  */
 protected function initAvailableAttachments(EmailModel $emailModel)
 {
     $attachments = [];
     if ($emailModel->getParentEmailId()) {
         $parentEmail = $this->entityManager->getRepository('OroEmailBundle:Email')->find($emailModel->getParentEmailId());
         $threadAttachments = $this->emailAttachmentProvider->getThreadAttachments($parentEmail);
         $threadAttachments = $this->filterAttachmentsByName($threadAttachments);
         $attachments = array_merge($attachments, $threadAttachments);
     }
     if ($emailModel->getEntityClass() && $emailModel->getEntityId()) {
         $scopeEntity = $this->entityManager->getRepository($emailModel->getEntityClass())->find($emailModel->getEntityId());
         if ($scopeEntity) {
             $scopeEntityAttachments = $this->emailAttachmentProvider->getScopeEntityAttachments($scopeEntity);
             $scopeEntityAttachments = $this->filterAttachmentsByName($scopeEntityAttachments);
             $attachments = array_merge($attachments, $scopeEntityAttachments);
         }
     }
     $emailModel->setAttachmentsAvailable($attachments);
 }