/**
  * @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());
 }
Ejemplo n.º 2
0
 public function testEnsureEmailBodyCachedForAlreadyCached()
 {
     $email = new Email();
     $email->setEmailBody(new EmailBody());
     $this->emailBodySynchronizer->expects($this->never())->method('syncOneEmailBody');
     $this->manager->ensureEmailBodyCached($email);
 }
 public function testSyncOneEmailBodyForAlreadyCached()
 {
     $email = new Email();
     $email->setEmailBody(new EmailBody());
     $this->selector->expects($this->never())->method('select');
     $this->synchronizer->syncOneEmailBody($email);
 }
Ejemplo n.º 4
0
 public function testEmailBodyGetterAndSetter()
 {
     $emailBody = $this->getMock('Oro\\Bundle\\EmailBundle\\Entity\\EmailBody');
     $entity = new Email();
     $entity->setEmailBody($emailBody);
     $this->assertTrue($emailBody === $entity->getEmailBody());
 }
Ejemplo n.º 5
0
 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;
 }
Ejemplo n.º 6
0
 /**
  * @param Email  $email
  * @param string $type
  */
 protected function processBodyType(Email $email, $type)
 {
     $body = $email->getEmailBody();
     if ($body) {
         if ($email->getId()) {
             if ($body->getBodyIsText() !== ($type === true)) {
                 throw $this->createInvalidPropertyException('Body Type', $this->emailBodyTypeTransformer->transform($body->getBodyIsText()), $this->emailBodyTypeTransformer->transform($type));
             }
         } else {
             $body->setBodyIsText($type === true);
         }
     } else {
         $email->setEmailBody($this->emailEntityBuilder->body('', $type !== true, true));
     }
 }