/** * @param object $getOwnerResult * @param object $getUserResult * @param int $getToCalls * * @dataProvider createReplyEmailModelProvider */ public function testCreateReplyAllEmailModel($getOwnerResult, $getUserResult, $getToCalls) { $this->fromEmailAddress = $this->getMock('Oro\\Bundle\\EmailBundle\\Entity\\EmailAddress'); $this->fromCcEmailAddress = $this->getMock('Oro\\Bundle\\EmailBundle\\Entity\\EmailAddress'); $this->fromEmailAddress->expects($this->once())->method('getOwner')->willReturn($getOwnerResult); $this->helper->expects($this->any())->method('getUser')->willReturn($getUserResult); $getUserResult->expects($this->any())->method('getEmails')->willReturn([]); $this->email->expects($this->once())->method('getFromEmailAddress')->willReturn($this->fromEmailAddress); $this->email->expects($this->any())->method('getId'); $emailAddress = $this->getMock('Oro\\Bundle\\EmailBundle\\Entity\\EmailAddress'); $emailAddress->expects($this->exactly($getToCalls))->method('getEmail')->willReturn(null); $emailRecipient = $this->getMock('Oro\\Bundle\\EmailBundle\\Entity\\EmailRecipient'); $emailRecipient->expects($this->exactly($getToCalls))->method('getEmailAddress')->willReturn($emailAddress); $to = new ArrayCollection(); $to->add($emailRecipient); $this->email->expects($this->exactly($getToCalls))->method('getTo')->willReturn($to); $emailCcRecipient = $this->getMock('Oro\\Bundle\\EmailBundle\\Entity\\EmailRecipient'); $emailCcRecipient->expects($this->once())->method('getEmailAddress')->willReturn($this->fromCcEmailAddress); $cc = new ArrayCollection(); $cc->add($emailCcRecipient); $this->email->expects($this->exactly($getToCalls))->method('getCc')->willReturn($cc); $this->helper->expects($this->once())->method('prependWith'); $this->helper->expects($this->once())->method('getEmailBody'); $this->activityListProvider->expects($this->once())->method('getTargetEntities')->willReturn([]); $result = $this->emailModelBuilder->createReplyAllEmailModel($this->email); $this->assertInstanceOf('Oro\\Bundle\\EmailBundle\\Form\\Model\\Email', $result); }
public function testCreateForwardEmailModel() { $this->helper->expects($this->once())->method('prependWith'); $emailBody = $this->getMock('Oro\\Bundle\\EmailBundle\\Entity\\EmailBody'); $emailBody->expects($this->exactly(1))->method('getAttachments')->willReturn([]); $this->email->expects($this->once())->method('getEmailBody')->willReturn($emailBody); $result = $this->emailModelBuilder->createForwardEmailModel($this->email); $this->assertInstanceOf('Oro\\Bundle\\EmailBundle\\Form\\Model\\Email', $result); }
/** * @param FormEvent $event */ public function fillFormByTemplate(FormEvent $event) { /** @var Email|null $data */ $data = $event->getData(); if (null === $data || !is_object($data) || null === $data->getTemplate()) { return; } if (null !== $data->getSubject() && null !== $data->getBody()) { return; } $emailTemplate = $data->getTemplate(); $targetEntity = $this->emailModelBuilderHelper->getTargetEntity($data->getEntityClass(), $data->getEntityId()); list($emailSubject, $emailBody) = $this->emailRenderer->compileMessage($emailTemplate, ['entity' => $targetEntity]); if (null === $data->getSubject()) { $data->setSubject($emailSubject); } if (null === $data->getBody()) { $data->setBody($emailBody); } }
/** * @param EmailModel $emailModel * @param EmailEntity $emailEntity */ protected function applyAttachments(EmailModel $emailModel, EmailEntity $emailEntity) { try { $this->helper->ensureEmailBodyCached($emailEntity); foreach ($emailEntity->getEmailBody()->getAttachments() as $attachment) { $attachmentModel = $this->factory->getEmailAttachment(); $attachmentModel->setId($attachment->getId()); $attachmentModel->setType(EmailAttachment::TYPE_EMAIL_ATTACHMENT); $attachmentModel->setEmailAttachment($attachment); $emailModel->addAttachment($attachmentModel); } } catch (\Exception $e) { // maybe show notice to a user that attachments could not be loaded } }
/** * @param string $prefix * @param string $subject * @param string $result * * @dataProvider prependWithProvider */ public function testPrependWith($prefix, $subject, $result) { $this->assertEquals($result, $this->helper->prependWith($prefix, $subject)); }