/**
  * @dataProvider replaceDataProvider
  * @param       $bodyTemplate
  * @param array $attachments
  */
 public function testReplace($bodyTemplate, array $attachments)
 {
     $email = new Email();
     $emailBody = new EmailBody();
     $replacements = [];
     $contentIds = [];
     foreach ($attachments as $attachmentData) {
         $attachment = new EmailAttachment();
         $emailAttachmentContent = new EmailAttachmentContent();
         $emailAttachmentContent->setContent($attachmentData['content'])->setContentTransferEncoding($attachmentData['transfer_encoding']);
         $attachment->setEmbeddedContentId($attachmentData['content_id'])->setContentType($attachmentData['type'])->setContent($emailAttachmentContent);
         $emailBody->addAttachment($attachment);
         $cid = 'cid:' . $attachmentData['content_id'];
         $contentIds[] = $cid;
         if ($attachmentData['replace']) {
             $replacements[] = sprintf('data:%s;base64,%s', $attachmentData['type'], $attachmentData['content']);
         } else {
             $replacements[] = $cid;
         }
     }
     $emailBody->setBodyContent(vsprintf($bodyTemplate, $contentIds));
     $email->setEmailBody($emailBody);
     $event = new EmailBodyLoaded($email);
     $this->listener->replace($event);
     $this->assertEquals($email, $event->getEmail());
     $this->assertEquals(vsprintf($bodyTemplate, $replacements), $event->getEmail()->getEmailBody()->getBodyContent());
 }
 public function inapplicableEmailsProvider()
 {
     $date = new \DateTime('now', new \DateTimeZone('UTC'));
     $oldEmailDate = new \DateTime('now', new \DateTimeZone('UTC'));
     $oldEmailDate->sub(\DateInterval::createFromDateString('2 day'));
     $applicableSubjectsAndBodies = [['not empty subject', 'This is email body with offer, sale and won words.', $date], [null, 'This email has nothing.', $date], [null, 'This is email body with sale and won words.', $oldEmailDate]];
     $data = array_map(function ($subjectAndBody) {
         list($subject, $bodyContent, $sentAt) = $subjectAndBody;
         $body = new EmailBody();
         $body->setBodyContent($bodyContent);
         $email = new Email();
         $email->setSubject($subject);
         $email->setEmailBody($body);
         $email->setSentAt($sentAt);
         return [$email];
     }, $applicableSubjectsAndBodies);
     return $data;
 }
Esempio n. 3
0
 /**
  * Sets an email body properties
  *
  * @param string $content
  * @param bool   $bodyIsText
  */
 public function setEmailBody($content, $bodyIsText)
 {
     $this->emailBody = new EmailBody();
     $this->emailBody->setBodyContent($content)->setBodyIsText($bodyIsText);
 }
Esempio n. 4
0
 public function testContentGetterAndSetter()
 {
     $entity = new EmailBody();
     $entity->setBodyContent('test');
     $this->assertEquals('test', $entity->getBodyContent());
 }
Esempio n. 5
0
 /**
  * Create EmailBody entity object
  *
  * @param string $content    The body content
  * @param bool   $isHtml     Indicate whether the body content is HTML or TEXT
  * @param bool   $persistent Indicate whether this email body can be removed by the email cache manager or not
  *                           Set false for external email, and true for system email, for example sent by BAP
  *
  * @return EmailBody
  */
 public function body($content, $isHtml, $persistent = false)
 {
     $result = new EmailBody();
     $result->setBodyContent($content)->setBodyIsText(!$isHtml)->setPersistent($persistent);
     return $result;
 }