public function testEnsureEmailBodyCached() { $email = new Email(); $this->emailBodySynchronizer->expects($this->once())->method('syncOneEmailBody'); $this->em->expects($this->once())->method('flush'); $this->manager->ensureEmailBodyCached($email); }
/** * @param EmailEntity $emailEntity * @param $templatePath * * @return null|string */ public function getEmailBody(EmailEntity $emailEntity, $templatePath) { try { $this->emailCacheManager->ensureEmailBodyCached($emailEntity); } catch (LoadEmailBodyException $e) { return null; } return $this->templating->render($templatePath, ['email' => $emailEntity]); }
/** * @param User $user * @param $maxEmailsDisplay * * @return array */ public function getEmails(User $user, Organization $organization, $maxEmailsDisplay) { $emails = $this->em->getRepository('OroEmailBundle:Email')->getNewEmails($user, $organization, $maxEmailsDisplay); $emailsData = []; /** @var $email Email */ foreach ($emails as $element) { $isSeen = $element['seen']; $email = $element[0]; $bodyContent = ''; try { $this->emailCacheManager->ensureEmailBodyCached($email); $bodyContent = $this->htmlTagHelper->shorten($this->htmlTagHelper->stripTags($this->htmlTagHelper->purify($email->getEmailBody()->getBodyContent()))); } catch (LoadEmailBodyException $e) { // no content } $emailsData[] = ['route' => $this->router->generate('oro_email_email_reply', ['id' => $email->getId()]), 'id' => $email->getId(), 'seen' => $isSeen, 'subject' => $email->getSubject(), 'bodyContent' => $bodyContent, 'fromName' => $email->getFromName(), 'linkFromName' => $this->getFromNameLink($email)]; } return $emailsData; }
/** * @expectedException \Oro\Bundle\EmailBundle\Exception\EmailBodyNotFoundException * @expectedExceptionMessage Cannot find a body for "test email" email. */ public function testEnsureEmailBodyCachedNotFound() { $email = new Email(); ReflectionUtil::setId($email, 123); $email->setSubject('test email'); $emailBody = new EmailBody(); $emailUser = new EmailUser(); $origin = new TestEmailOrigin(); $folder = new EmailFolder(); $folder->setOrigin($origin); $emailUser->setFolder($folder); $email->addEmailUser($emailUser); $exception = new EmailBodyNotFoundException($email); $loader = $this->getMock('Oro\\Bundle\\EmailBundle\\Provider\\EmailBodyLoaderInterface'); $this->selector->expects($this->once())->method('select')->with($this->identicalTo($origin))->will($this->returnValue($loader)); $loader->expects($this->once())->method('loadEmailBody')->will($this->throwException($exception)); $this->em->expects($this->never())->method('persist'); $this->em->expects($this->never())->method('flush'); $this->logger->expects($this->once())->method('notice')->with('Load email body failed. Email id: 123. Error: Cannot find a body for "test email" email.', ['exception' => $exception]); $this->logger->expects($this->never())->method('warning'); $this->manager->ensureEmailBodyCached($email); $this->assertSame($emailBody, $email->getEmailBody()); }