/**
  * 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;
 }
    /**
     * @dataProvider localizedSubjectMessageTextProvider()
     *
     * @param $_locale
     * @param $_subject
     * @param $_messageText
     * @param $_messageHtml
     */
    public function testParseXmlLocalizedFields($_locale, $_subject, $_messageText, $_messageHtml)
    {
        $xml = <<<XML
<email>
    <from name="from_name">from@addr.com</from>
    <to name="to_name1">to1@addr.com</to>
    <subject locale="de">_subject_de</subject>
    <subject locale="en">_subject_en</subject>
    <messageText locale="de">_text_message_de</messageText>
    <messageText locale="en">_text_message_en</messageText>
    <messageHtml locale="de"><![CDATA[<p>_html_message_de</p>]]></messageHtml>
    <messageHtml locale="en"><![CDATA[<p>_html_message_en</p>]]></messageHtml>
</email>
XML;
        $this->xsdValidator->validate($xml, 'pathtoxsd.xsd')->shouldBeCalled();
        $parsedMessage = $this->fixture->parseMailDefinition($xml, $_locale);
        $this->assertEquals($_subject, $parsedMessage->getSubject());
        $this->assertEquals($_messageText, $parsedMessage->getMessageText());
        $this->assertEquals($_messageHtml, $parsedMessage->getMessageHtml());
    }
Пример #3
0
 /**
  * @expectedException \Hautzi\SystemMailBundle\SystemMailer\XML\XsdValidationException
  */
 public function testValidationFailsThrowsException()
 {
     $xsd = new XsdValidator();
     $xsd->validate($this->invalidXml, $this->tmpXsdFile);
 }