[ZF-10089] Zend_Log
[zend.git] / tests / Zend / MimeTest.php
blob72289d861a8dd5760153bf492f8b4a6d62072529
1 <?php
2 /**
3 * Zend Framework
5 * LICENSE
7 * This source file is subject to the new BSD license that is bundled
8 * with this package in the file LICENSE.txt.
9 * It is also available through the world-wide-web at this URL:
10 * http://framework.zend.com/license/new-bsd
11 * If you did not receive a copy of the license and are unable to
12 * obtain it through the world-wide-web, please send an email
13 * to license@zend.com so we can send you a copy immediately.
15 * @category Zend
16 * @package Zend_Mime
17 * @subpackage UnitTests
18 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19 * @license http://framework.zend.com/license/new-bsd New BSD License
20 * @version $Id $
23 /**
24 * Test helper
26 require_once dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . 'TestHelper.php';
28 /** Zend_Mail */
29 require_once 'Zend/Mail.php';
31 /** Zend_Mime */
32 require_once 'Zend/Mime.php';
34 /** PHPUnit test case */
35 require_once 'PHPUnit/Framework/TestCase.php';
37 /** Zend_MailTest */
38 require_once dirname(__FILE__) . '/MailTest.php';
40 /**
41 * @category Zend
42 * @package Zend_Mime
43 * @subpackage UnitTests
44 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
45 * @license http://framework.zend.com/license/new-bsd New BSD License
46 * @group Zend_Mime
48 class Zend_MimeTest extends PHPUnit_Framework_TestCase
50 public function testBoundary()
52 // check boundary for uniqueness
53 $m1 = new Zend_Mime();
54 $m2 = new Zend_Mime();
55 $this->assertNotEquals($m1->boundary(), $m2->boundary());
57 // check instantiating with arbitrary boundary string
58 $myBoundary = 'mySpecificBoundary';
59 $m3 = new Zend_Mime($myBoundary);
60 $this->assertEquals($m3->boundary(), $myBoundary);
64 public function testIsPrintable_notPrintable()
66 $this->assertFalse(Zend_Mime::isPrintable('Test with special chars: �����'));
69 public function testIsPrintable_isPrintable()
71 $this->assertTrue(Zend_Mime::isPrintable('Test without special chars'));
74 public function testQP()
76 $text = "This is a cool Test Text with special chars: ����\n"
77 . "and with multiple lines���� some of the Lines are long, long"
78 . ", long, long, long, long, long, long, long, long, long, long"
79 . ", long, long, long, long, long, long, long, long, long, long"
80 . ", long, long, long, long, long, long, long, long, long, long"
81 . ", long, long, long, long and with ����";
83 $qp = Zend_Mime::encodeQuotedPrintable($text);
84 $this->assertEquals(quoted_printable_decode($qp), $text);
87 public function testBase64()
89 $content = str_repeat("\x88\xAA\xAF\xBF\x29\x88\xAA\xAF\xBF\x29\x88\xAA\xAF", 4);
90 $encoded = Zend_Mime::encodeBase64($content);
91 $this->assertEquals($content, base64_decode($encoded));
94 public function testZf1058WhitespaceAtEndOfBodyCausesInfiniteLoop()
96 $mail = new Zend_Mail();
97 $mail->setSubject('my subject');
98 $mail->setBodyText("my body\r\n\r\n...after two newlines\r\n ");
99 $mail->setFrom('test@email.com');
100 $mail->addTo('test@email.com');
102 // test with generic transport
103 $mock = new Zend_Mail_Transport_Sendmail_Mock();
104 $mail->send($mock);
105 $body = quoted_printable_decode($mock->body);
106 $this->assertContains("my body\r\n\r\n...after two newlines", $body, $body);
110 * @group ZF-1688
111 * @dataProvider dataTestEncodeMailHeaderQuotedPrintable
113 public function testEncodeMailHeaderQuotedPrintable($str, $charset, $result)
115 $this->assertEquals($result, Zend_Mime::encodeQuotedPrintableHeader($str, $charset));
118 public static function dataTestEncodeMailHeaderQuotedPrintable()
120 return array(
121 array("äöü", "UTF-8", "=?UTF-8?Q?=C3=A4=C3=B6=C3=BC?="),
122 array("äöü ", "UTF-8", "=?UTF-8?Q?=C3=A4=C3=B6=C3=BC?="),
123 array("Gimme more €", "UTF-8", "=?UTF-8?Q?Gimme=20more=20=E2=82=AC?="),
124 array("Alle meine Entchen schwimmen in dem See, schwimmen in dem See, Köpfchen in das Wasser, Schwänzchen in die Höh!", "UTF-8", "=?UTF-8?Q?Alle=20meine=20Entchen=20schwimmen=20in=20dem=20See,=20?=
125 =?UTF-8?Q?schwimmen=20in=20dem=20See,=20K=C3=B6pfchen=20in=20das=20?=
126 =?UTF-8?Q?Wasser,=20Schw=C3=A4nzchen=20in=20die=20H=C3=B6h!?="),
127 array("ääääääääääääääääääääääääääääääääää", "UTF-8", "=?UTF-8?Q?=C3=A4=C3=A4=C3=A4=C3=A4=C3=A4=C3=A4=C3=A4=C3=A4=C3=A4=C3=A4=C3=A4=C3=A4=C3=A4=C3=A4=C3=A4=C3=A4=C3=A4=C3=A4=C3=A4=C3=A4=C3=A4=C3=A4=C3=A4=C3=A4=C3=A4=C3=A4=C3=A4=C3=A4=C3=A4=C3=A4=C3=A4=C3=A4=C3=A4=C3=A4?="),
132 * @group ZF-1688
133 * @dataProvider dataTestEncodeMailHeaderBase64
135 public function testEncodeMailHeaderBase64($str, $charset, $result)
137 $this->assertEquals($result, Zend_Mime::encodeBase64Header($str, $charset));
140 public static function dataTestEncodeMailHeaderBase64()
142 return array(
143 array("äöü", "UTF-8", "=?UTF-8?B?w6TDtsO8?="),
144 array("Alle meine Entchen schwimmen in dem See, schwimmen in dem See, Köpfchen in das Wasser, Schwänzchen in die Höh!", "UTF-8", "=?UTF-8?B?QWxsZSBtZWluZSBFbnRjaGVuIHNjaHdpbW1lbiBpbiBkZW0gU2VlLCBzY2h3?=
145 =?UTF-8?B?aW1tZW4gaW4gZGVtIFNlZSwgS8O2cGZjaGVuIGluIGRhcyBXYXNzZXIsIFNj?=
146 =?UTF-8?B?aHfDpG56Y2hlbiBpbiBkaWUgSMO2aCE=?="),
151 * @group ZF-1688
153 public function testLineLengthInQuotedPrintableHeaderEncoding()
155 $subject = "Alle meine Entchen schwimmen in dem See, schwimmen in dem See, Köpfchen in das Wasser, Schwänzchen in die Höh!";
156 $encoded = Zend_Mime::encodeQuotedPrintableHeader($subject, "UTF-8", 100);
157 foreach(explode(Zend_Mime::LINEEND, $encoded) AS $line ) {
158 if(strlen($line) > 100) {
159 $this->fail("Line '".$line."' is ".strlen($line)." chars long, only 100 allowed.");
162 $encoded = Zend_Mime::encodeQuotedPrintableHeader($subject, "UTF-8", 40);
163 foreach(explode(Zend_Mime::LINEEND, $encoded) AS $line ) {
164 if(strlen($line) > 40) {
165 $this->fail("Line '".$line."' is ".strlen($line)." chars long, only 40 allowed.");