Esempio n. 1
0
    public function testAddHtml()
    {
        $mail = new Horde_Mime_Mail(array('Subject' => 'My Subject', 'To' => '*****@*****.**', 'From' => '*****@*****.**', 'charset' => 'iso-8859-1'));
        $mail->setBody("This is\nthe plain text body.");
        $dummy = new Horde_Mail_Transport_Mock();
        $mail->send($dummy);
        $sent = str_replace("\r\n", "\n", $dummy->sentMessages[0]);
        $this->assertStringMatchesFormat('Subject: My Subject
To: recipient@example.com
From: sender@example.com
Message-ID: <*****@*****.**>
User-Agent: Horde Application Framework %d
Date: %s, %d %s %d %d:%d:%d %s%d
Content-Type: text/plain; charset=iso-8859-1; format=flowed; DelSp=Yes
MIME-Version: 1.0', $sent['header_text']);
        $this->assertEquals("This is\nthe plain text body.\n", $sent['body']);
        $this->assertEquals(array('*****@*****.**'), $sent['recipients']);
        $mail = new Horde_Mime_Mail(array('Subject' => 'My Subject', 'To' => '*****@*****.**', 'From' => '*****@*****.**'));
        $mail->setHTMLBody("<h1>Header Title</h1>\n<p>This is<br />the html text body.</p>", 'iso-8859-1', false);
        $dummy = new Horde_Mail_Transport_Mock();
        $mail->send($dummy);
        $sent = str_replace("\r\n", "\n", $dummy->sentMessages[0]);
        $this->assertStringMatchesFormat('Subject: My Subject
To: recipient@example.com
From: sender@example.com
Message-ID: <*****@*****.**>
User-Agent: Horde Application Framework %d
Date: %s, %d %s %d %d:%d:%d %s%d
Content-Type: text/html; charset=iso-8859-1
MIME-Version: 1.0', $sent['header_text']);
        $this->assertEquals("<h1>Header Title</h1>\n<p>This is<br />the html text body.</p>", $sent['body']);
        $this->assertEquals(array('*****@*****.**'), $sent['recipients']);
        $mail = new Horde_Mime_Mail(array('Subject' => 'My Subject', 'To' => '*****@*****.**', 'From' => '*****@*****.**', 'charset' => 'iso-8859-1'));
        $mail->setHTMLBody("<h1>Header Title</h1>\n<p>This is<br />the html text body.</p>");
        $dummy = new Horde_Mail_Transport_Mock();
        $mail->send($dummy);
        $sent = str_replace("\r\n", "\n", $dummy->sentMessages[0]);
        $this->assertStringMatchesFormat('Subject: My Subject
To: recipient@example.com
From: sender@example.com
Message-ID: <*****@*****.**>
User-Agent: Horde Application Framework %d
Date: %s, %d %s %d %d:%d:%d %s%d
Content-Type: multipart/alternative; boundary="=_%s"
MIME-Version: 1.0', $sent['header_text']);
        $this->assertStringMatchesFormat("This message is in MIME format.\n\n--=_%s\nContent-Type: text/plain; charset=iso-8859-1; format=flowed; DelSp=Yes\nContent-Description: Plaintext Version of Message\n\nHEADER TITLE\n\nThis is\nthe html text body.\n\n--=_%s\nContent-Type: text/html; charset=iso-8859-1\nContent-Description: HTML Version of Message\n\n<h1>Header Title</h1>\n<p>This is<br />the html text body.</p>\n--=_%s--\n", $sent['body']);
        $this->assertEquals(array('*****@*****.**'), $sent['recipients']);
    }