/**
  * {@inheritDoc}
  */
 public function load(ObjectManager $manager)
 {
     $fromEmail = new EmailAddressProxy();
     $fromEmail->setEmail(uniqid() . '@gmail.com');
     $email = new Email();
     $email->setSubject(uniqid())->setFromName(uniqid())->setReceivedAt(new \DateTime())->setSentAt(new \DateTime())->setInternalDate(new \DateTime())->setFromEmailAddress($fromEmail)->setMessageId(uniqid());
     $manager->persist($fromEmail);
     $manager->persist($email);
     $manager->flush();
 }
 /**
  * Create Email entity object
  *
  * @param string $subject The email subject
  * @param string $from The FROM email address, for example: john@example.com or "John Smith" <john@example.c4m>
  * @param string|string[]|null $to The TO email address(es).
  *                                 Example of email address see in description of $from parameter
  * @param \DateTime $sentAt The date/time when email sent
  * @param \DateTime $receivedAt The date/time when email received
  * @param \DateTime $internalDate The date/time an email server returned in INTERNALDATE field
  * @param integer $importance The email importance flag. Can be one of *_IMPORTANCE constants of Email class
  * @param string|string[]|null $cc The CC email address(es).
  *                                 Example of email address see in description of $from parameter
  * @param string|string[]|null $bcc The BCC email address(es).
  *                                  Example of email address see in description of $from parameter
  * @return Email
  */
 public function email($subject, $from, $to, $sentAt, $receivedAt, $internalDate, $importance = Email::NORMAL_IMPORTANCE, $cc = null, $bcc = null)
 {
     $result = new Email();
     $result->setSubject($subject)->setFromName($from)->setFromEmailAddress($this->address($from))->setSentAt($sentAt)->setReceivedAt($receivedAt)->setInternalDate($internalDate)->setImportance($importance);
     $this->addRecipients($result, EmailRecipient::TO, $to);
     $this->addRecipients($result, EmailRecipient::CC, $cc);
     $this->addRecipients($result, EmailRecipient::BCC, $bcc);
     $this->batch->addEmail($result);
     return $result;
 }
 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;
 }
Example #4
0
 public function testSubjectGetterAndSetter()
 {
     $entity = new Email();
     $entity->setSubject('test');
     $this->assertEquals('test', $entity->getSubject());
 }
 public function testSync()
 {
     $email = new Email();
     $email->setSubject('Test email');
     $emailBody = new EmailBody();
     $emailUser = new EmailUser();
     $origin = new TestEmailOrigin();
     $folder = new EmailFolder();
     $folder->setOrigin($origin);
     $emailUser->setOrigin($origin);
     $emailUser->addFolder($folder);
     $email->addEmailUser($emailUser);
     $repo = $this->getMockBuilder('Oro\\Bundle\\EmailBundle\\Entity\\Repository\\EmailRepository')->disableOriginalConstructor()->getMock();
     $this->doctrine->expects($this->once())->method('getRepository')->willReturn($repo);
     $runCount = 0;
     $repo->expects($this->exactly(2))->method('getEmailsWithoutBody')->willReturnCallback(function () use(&$runCount, $email) {
         $runCount++;
         return $runCount === 1 ? [$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')->with($this->identicalTo($folder), $this->identicalTo($email), $this->identicalTo($this->em))->will($this->returnValue($emailBody));
     $this->em->expects($this->once())->method('persist')->with($this->identicalTo($email));
     $this->em->expects($this->once())->method('flush');
     $this->em->expects($this->once())->method('clear');
     $this->logger->expects($this->exactly(2))->method('notice');
     $this->logger->expects($this->never())->method('warning');
     $this->synchronizer->sync();
     $this->assertSame($emailBody, $email->getEmailBody());
 }