/** * @param $threadEmails * @param $transformationCalls * * @dataProvider threadEmailsProvider */ public function testGetThreadAttachments($threadEmails, $transformationCalls) { $emailEntity = $this->getMock('Oro\\Bundle\\EmailBundle\\Entity\\Email'); $this->emailThreadProvider->expects($this->once())->method('getThreadEmails')->with($this->em, $emailEntity)->willReturn($threadEmails); $this->emailAttachmentTransformer->expects($this->exactly($transformationCalls))->method('entityToModel'); $result = $this->emailAttachmentProvider->getThreadAttachments($emailEntity); $this->assertTrue(is_array($result)); $this->assertEquals($transformationCalls, sizeof($result)); }
/** * @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); }