public function testSendingMailWorks()
 {
     $message = new ParsedMessage();
     $message->setFrom('*****@*****.**', 'from');
     $message->setReplyTo('*****@*****.**');
     $message->addTo('*****@*****.**', 'to1');
     $message->addTo('*****@*****.**', 'to2');
     $message->addCc('*****@*****.**', 'cc1');
     $message->addCc('*****@*****.**', 'cc2');
     $message->addBcc('*****@*****.**', 'bcc1');
     $message->addBcc('*****@*****.**', 'bcc2');
     $message->setSubject('_subject');
     $message->setMessageText('_text_message');
     $message->setMessageHtml('_html_message');
     $this->mailer->send(Argument::type(\Swift_Message::class))->shouldBeCalled();
     $closureExceuted = false;
     $this->fixture->send($message, function (\Swift_Message $message) use(&$closureExceuted) {
         // from
         $this->assertEquals(['*****@*****.**' => 'from'], $message->getFrom());
         // reply-to
         $this->assertEquals(['*****@*****.**' => null], $message->getReplyTo());
         // to
         $this->assertEquals(['*****@*****.**' => 'to1', '*****@*****.**' => 'to2'], $message->getTo());
         // cc
         $this->assertEquals(['*****@*****.**' => 'cc1', '*****@*****.**' => 'cc2'], $message->getCc());
         // bcc
         $this->assertEquals(['*****@*****.**' => 'bcc1', '*****@*****.**' => 'bcc2'], $message->getBcc());
         $this->assertEquals('_subject', $message->getSubject());
         $this->assertEquals('_text_message', $message->getBody());
         $closureExceuted = true;
     });
     $this->assertTrue($closureExceuted, 'closure was not executed.');
 }
 /**
  * Parse XML Mail Definition string
  *
  * which looks something like this
  * <code>
  *   <email>
  *      <to name="yourname">your@mail.com</email>
  *      <subject locale="de">Your subject</subject>
  *      <messageText locale="de">Your Message</messageText>
  *   </email>
  * </code>
  *
  * @param string $xml
  * @param string $locale
  *
  * @return ParsedMessage
  *
  * @throws \Exception
  */
 public function parseMailDefinition($xml, $locale = null)
 {
     $this->validator->validate($xml, $this->xsdFile);
     $parsed = simplexml_load_string($xml);
     $message = new ParsedMessage();
     $from = $parsed->from;
     if ($from->count() > 0) {
         $message->setFrom((string) $from, (string) $from->attributes()['name']);
     }
     $replyTo = $parsed->replyTo;
     if ($replyTo->count() > 0) {
         $message->setReplyTo((string) $replyTo);
     }
     foreach ($parsed->to as $to) {
         $message->addTo((string) $to, (string) $to->attributes()['name']);
     }
     foreach ($parsed->cc as $cc) {
         $message->addCc((string) $cc, (string) $cc->attributes()['name']);
     }
     foreach ($parsed->bcc as $bcc) {
         $message->addBcc((string) $bcc, (string) $bcc->attributes()['name']);
     }
     $message->setSubject($this->getLocalizedTagContent($parsed->subject, $locale));
     $message->setMessageHtml($this->getLocalizedTagContent($parsed->messageHtml, $locale));
     $message->setMessageText($this->getLocalizedTagContent($parsed->messageText, $locale));
     return $message;
 }
Example #3
0
 /**
  * Add default parameters when they are not provided from the MailDefinition
  *
  * @param ParsedMessage $parsedMessage
  */
 protected function handleDefaults(ParsedMessage $parsedMessage)
 {
     if (!$parsedMessage->getFrom() && $this->defaults['from']['email']) {
         $parsedMessage->setFrom($this->defaults['from']['email'], $this->defaults['from']['name']);
     }
     if (!$parsedMessage->getTo() && $this->defaults['to']['email']) {
         $parsedMessage->addTo($this->defaults['to']['email'], $this->defaults['to']['name']);
     }
     if (!$parsedMessage->getCc() && $this->defaults['cc']['email']) {
         $parsedMessage->addCC($this->defaults['cc']['email'], $this->defaults['cc']['name']);
     }
     if (!$parsedMessage->getBcc() && $this->defaults['bcc']['email']) {
         $parsedMessage->addBcc($this->defaults['bcc']['email'], $this->defaults['bcc']['name']);
     }
     if (!$parsedMessage->getReplyTo() && $this->defaults['replyTo']) {
         $parsedMessage->setReplyTo($this->defaults['replyTo']);
     }
     if (!$parsedMessage->getSubject() && $this->defaults['subject']) {
         $parsedMessage->setSubject($this->defaults['subject']);
     }
 }