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)); }
/** * @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); }