-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMimeTest.php
More file actions
executable file
·170 lines (152 loc) · 6.51 KB
/
MimeTest.php
File metadata and controls
executable file
·170 lines (152 loc) · 6.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Mime
* @subpackage UnitTests
* @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id $
*/
/** Zend_Mail */
require_once 'Zend/Mail.php';
/** Zend_Mime */
require_once 'Zend/Mime.php';
/**
* @category Zend
* @package Zend_Mime
* @subpackage UnitTests
* @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @group Zend_Mime
*/
class Zend_MimeTest extends PHPUnit_Framework_TestCase
{
public function testBoundary()
{
// check boundary for uniqueness
$m1 = new Zend_Mime();
$m2 = new Zend_Mime();
$this->assertNotEquals($m1->boundary(), $m2->boundary());
// check instantiating with arbitrary boundary string
$myBoundary = 'mySpecificBoundary';
$m3 = new Zend_Mime($myBoundary);
$this->assertEquals($m3->boundary(), $myBoundary);
}
public function testIsPrintable_notPrintable()
{
$this->assertFalse(Zend_Mime::isPrintable('Test with special chars: �����'));
}
public function testIsPrintable_isPrintable()
{
$this->assertTrue(Zend_Mime::isPrintable('Test without special chars'));
}
public function testQP()
{
$text = "This is a cool Test Text with special chars: ����\n"
. "and with multiple lines���� some of the Lines are long, long"
. ", long, long, long, long, long, long, long, long, long, long"
. ", long, long, long, long, long, long, long, long, long, long"
. ", long, long, long, long, long, long, long, long, long, long"
. ", long, long, long, long and with ����";
$qp = Zend_Mime::encodeQuotedPrintable($text);
$this->assertEquals(quoted_printable_decode($qp), $text);
}
/**
* @group ZF-10074
*/
public function testEncodeQuotedPrintableWhenTextHasZeroAtTheEnd()
{
$raw = str_repeat('x',72) . '0';
$quoted = Zend_Mime::encodeQuotedPrintable($raw, 72);
$expected = quoted_printable_decode($quoted);
$this->assertEquals($expected, $raw);
}
public function testBase64()
{
$content = str_repeat("\x88\xAA\xAF\xBF\x29\x88\xAA\xAF\xBF\x29\x88\xAA\xAF", 4);
$encoded = Zend_Mime::encodeBase64($content);
$this->assertEquals($content, base64_decode($encoded));
}
public function testZf1058WhitespaceAtEndOfBodyCausesInfiniteLoop()
{
$mail = new Zend_Mail();
$mail->setSubject('my subject');
$mail->setBodyText("my body\r\n\r\n...after two newlines\r\n ");
$mail->setFrom('test@email.com');
$mail->addTo('test@email.com');
// test with generic transport
require_once 'Mail/MailTest.php';
$mock = new Zend_Mail_Transport_Sendmail_Mock();
$mail->send($mock);
$body = quoted_printable_decode($mock->body);
$this->assertContains("my body\r\n\r\n...after two newlines", $body, $body);
}
/**
* @group ZF-1688
* @dataProvider dataTestEncodeMailHeaderQuotedPrintable
*/
public function testEncodeMailHeaderQuotedPrintable($str, $charset, $result)
{
$this->assertEquals($result, Zend_Mime::encodeQuotedPrintableHeader($str, $charset));
}
public static function dataTestEncodeMailHeaderQuotedPrintable()
{
return array(
array("äöü", "UTF-8", "=?UTF-8?Q?=C3=A4=C3=B6=C3=BC?="),
array("äöü ", "UTF-8", "=?UTF-8?Q?=C3=A4=C3=B6=C3=BC?="),
array("Gimme more €", "UTF-8", "=?UTF-8?Q?Gimme=20more=20=E2=82=AC?="),
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=2C=20?=
=?UTF-8?Q?schwimmen=20in=20dem=20See=2C=20K=C3=B6pfchen=20in=20das=20?=
=?UTF-8?Q?Wasser=2C=20Schw=C3=A4nzchen=20in=20die=20H=C3=B6h!?="),
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?="),
);
}
/**
* @group ZF-1688
* @dataProvider dataTestEncodeMailHeaderBase64
*/
public function testEncodeMailHeaderBase64($str, $charset, $result)
{
$this->assertEquals($result, Zend_Mime::encodeBase64Header($str, $charset));
}
public static function dataTestEncodeMailHeaderBase64()
{
return array(
array("äöü", "UTF-8", "=?UTF-8?B?w6TDtsO8?="),
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?=
=?UTF-8?B?aW1tZW4gaW4gZGVtIFNlZSwgS8O2cGZjaGVuIGluIGRhcyBXYXNzZXIsIFNj?=
=?UTF-8?B?aHfDpG56Y2hlbiBpbiBkaWUgSMO2aCE=?="),
);
}
/**
* @group ZF-1688
*/
public function testLineLengthInQuotedPrintableHeaderEncoding()
{
$subject = "Alle meine Entchen schwimmen in dem See, schwimmen in dem See, Köpfchen in das Wasser, Schwänzchen in die Höh!";
$encoded = Zend_Mime::encodeQuotedPrintableHeader($subject, "UTF-8", 100);
foreach(explode(Zend_Mime::LINEEND, $encoded) AS $line ) {
if(strlen($line) > 100) {
$this->fail("Line '".$line."' is ".strlen($line)." chars long, only 100 allowed.");
}
}
$encoded = Zend_Mime::encodeQuotedPrintableHeader($subject, "UTF-8", 40);
foreach(explode(Zend_Mime::LINEEND, $encoded) AS $line ) {
if(strlen($line) > 40) {
$this->fail("Line '".$line."' is ".strlen($line)." chars long, only 40 allowed.");
}
}
}
}