|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Aimeos\MW\Mail\Message; |
|
4
|
|
|
|
|
5
|
|
|
|
|
6
|
|
|
/** |
|
7
|
|
|
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
|
8
|
|
|
* @copyright Metaways Infosystems GmbH, 2013 |
|
9
|
|
|
* @copyright Aimeos (aimeos.org), 2014-2018 |
|
10
|
|
|
*/ |
|
11
|
|
|
class ZendTest extends \PHPUnit\Framework\TestCase |
|
|
|
|
|
|
12
|
|
|
{ |
|
13
|
|
|
private $object; |
|
14
|
|
|
private $mock; |
|
15
|
|
|
|
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* Sets up the fixture, for example, opens a network connection. |
|
19
|
|
|
* This method is called before a test is executed. |
|
20
|
|
|
* |
|
21
|
|
|
* @access protected |
|
22
|
|
|
*/ |
|
23
|
|
|
protected function setUp() |
|
24
|
|
|
{ |
|
25
|
|
|
if( !class_exists( 'Zend_Mail' ) ) { |
|
26
|
|
|
$this->markTestSkipped( 'Zend_Mail is not available' ); |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
$this->mock = $this->getMockBuilder( 'Zend_Mail' )->disableOriginalConstructor()->getMock(); |
|
30
|
|
|
$this->object = new \Aimeos\MW\Mail\Message\Zend( $this->mock ); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* Tears down the fixture, for example, closes a network connection. |
|
36
|
|
|
* This method is called after a test is executed. |
|
37
|
|
|
* |
|
38
|
|
|
* @access protected |
|
39
|
|
|
*/ |
|
40
|
|
|
protected function tearDown() |
|
41
|
|
|
{ |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
|
|
45
|
|
|
public function testAddFrom() |
|
46
|
|
|
{ |
|
47
|
|
|
$this->mock->expects( $this->once() )->method( 'setFrom' ) |
|
48
|
|
|
->with( $this->stringContains( 'a@b' ), $this->stringContains( 'test' ) ); |
|
49
|
|
|
|
|
50
|
|
|
$result = $this->object->addFrom( 'a@b', 'test' ); |
|
51
|
|
|
$this->assertSame( $this->object, $result ); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
|
|
55
|
|
|
public function testAddTo() |
|
56
|
|
|
{ |
|
57
|
|
|
$this->mock->expects( $this->once() )->method( 'addTo' ) |
|
58
|
|
|
->with( $this->stringContains( 'a@b' ), $this->stringContains( 'test' ) ); |
|
59
|
|
|
|
|
60
|
|
|
$result = $this->object->addTo( 'a@b', 'test' ); |
|
61
|
|
|
$this->assertSame( $this->object, $result ); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
|
|
65
|
|
|
public function testAddCc() |
|
66
|
|
|
{ |
|
67
|
|
|
$this->mock->expects( $this->once() )->method( 'addCc' ) |
|
68
|
|
|
->with( $this->stringContains( 'a@b' ), $this->stringContains( 'test' ) ); |
|
69
|
|
|
|
|
70
|
|
|
$result = $this->object->addCc( 'a@b', 'test' ); |
|
71
|
|
|
$this->assertSame( $this->object, $result ); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
|
|
75
|
|
|
public function testAddBcc() |
|
76
|
|
|
{ |
|
77
|
|
|
$this->mock->expects( $this->once() )->method( 'addBcc' ) |
|
78
|
|
|
->with( $this->stringContains( 'a@b' ), $this->stringContains( 'test' ) ); |
|
79
|
|
|
|
|
80
|
|
|
$result = $this->object->addBcc( 'a@b', 'test' ); |
|
81
|
|
|
$this->assertSame( $this->object, $result ); |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
|
|
85
|
|
|
public function testAddReplyTo() |
|
86
|
|
|
{ |
|
87
|
|
|
$this->mock->expects( $this->once() )->method( 'setReplyTo' ) |
|
88
|
|
|
->with( $this->stringContains( 'a@b' ), $this->stringContains( 'test' ) ); |
|
89
|
|
|
|
|
90
|
|
|
$result = $this->object->addReplyTo( 'a@b', 'test' ); |
|
91
|
|
|
$this->assertSame( $this->object, $result ); |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
|
|
95
|
|
|
public function testAddHeader() |
|
96
|
|
|
{ |
|
97
|
|
|
$this->mock->expects( $this->once() )->method( 'addHeader' ) |
|
98
|
|
|
->with( $this->stringContains( 'test' ), $this->stringContains( 'value' ) ); |
|
99
|
|
|
|
|
100
|
|
|
$result = $this->object->addHeader( 'test', 'value' ); |
|
101
|
|
|
$this->assertSame( $this->object, $result ); |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
|
|
105
|
|
|
public function testSetSender() |
|
106
|
|
|
{ |
|
107
|
|
|
$this->mock->expects( $this->once() )->method( 'setFrom' ) |
|
108
|
|
|
->with( $this->stringContains( 'a@b' ), $this->stringContains( 'test' ) ); |
|
109
|
|
|
|
|
110
|
|
|
$result = $this->object->setSender( 'a@b', 'test' ); |
|
111
|
|
|
$this->assertSame( $this->object, $result ); |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
|
|
115
|
|
|
public function testSetSubject() |
|
116
|
|
|
{ |
|
117
|
|
|
$this->mock->expects( $this->once() )->method( 'setSubject' ) |
|
118
|
|
|
->with( $this->stringContains( 'test' ) ); |
|
119
|
|
|
|
|
120
|
|
|
$result = $this->object->setSubject( 'test' ); |
|
121
|
|
|
$this->assertSame( $this->object, $result ); |
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
|
|
|
|
125
|
|
|
public function testSetBody() |
|
126
|
|
|
{ |
|
127
|
|
|
$this->mock->expects( $this->once() )->method( 'setBodyText' ) |
|
128
|
|
|
->with( $this->stringContains( 'test' ) ); |
|
129
|
|
|
|
|
130
|
|
|
$result = $this->object->setBody( 'test' ); |
|
131
|
|
|
$this->assertSame( $this->object, $result ); |
|
132
|
|
|
} |
|
133
|
|
|
|
|
134
|
|
|
|
|
135
|
|
|
public function testSetBodyHtml() |
|
136
|
|
|
{ |
|
137
|
|
|
$result = $this->object->setBodyHtml( 'test' ); |
|
138
|
|
|
$this->object->getObject(); |
|
139
|
|
|
|
|
140
|
|
|
$this->assertSame( $this->object, $result ); |
|
141
|
|
|
} |
|
142
|
|
|
|
|
143
|
|
|
|
|
144
|
|
|
public function testAddAttachment() |
|
145
|
|
|
{ |
|
146
|
|
|
$partMock = $this->getMockBuilder( 'Zend_Mime_Part' )->disableOriginalConstructor()->getMock(); |
|
147
|
|
|
|
|
148
|
|
|
$this->mock->expects( $this->once() )->method( 'createAttachment' ) |
|
149
|
|
|
->with( $this->stringContains( 'test' ), $this->stringContains( 'text/plain' ), |
|
150
|
|
|
$this->stringContains( 'inline' ), $this->stringContains( \Zend_Mime::ENCODING_BASE64 ), |
|
|
|
|
|
|
151
|
|
|
$this->stringContains( 'test.txt' ) ) |
|
152
|
|
|
->will( $this->returnValue( $partMock ) ); |
|
153
|
|
|
|
|
154
|
|
|
$result = $this->object->addAttachment( 'test', 'text/plain', 'test.txt', 'inline' ); |
|
155
|
|
|
$this->assertSame( $this->object, $result ); |
|
156
|
|
|
} |
|
157
|
|
|
|
|
158
|
|
|
|
|
159
|
|
|
public function testEmbedAttachment() |
|
160
|
|
|
{ |
|
161
|
|
|
$this->mock->expects( $this->once() )->method( 'getBodyHtml' ) |
|
162
|
|
|
->will( $this->returnValue( new \stdClass() ) ); |
|
163
|
|
|
|
|
164
|
|
|
$result = $this->object->embedAttachment( 'test', 'text/plain', 'test.txt' ); |
|
165
|
|
|
$this->object->getObject(); |
|
166
|
|
|
|
|
167
|
|
|
$this->assertInternalType( 'string', $result ); |
|
168
|
|
|
} |
|
169
|
|
|
|
|
170
|
|
|
|
|
171
|
|
|
public function testEmbedAttachmentMultiple() |
|
172
|
|
|
{ |
|
173
|
|
|
$object = new \Aimeos\MW\Mail\Message\Zend( new \Zend_Mail() ); |
|
|
|
|
|
|
174
|
|
|
|
|
175
|
|
|
$object->setBody( 'text body' ); |
|
176
|
|
|
$object->embedAttachment( 'test', 'text/plain', 'test.txt' ); |
|
177
|
|
|
$object->embedAttachment( 'test', 'text/plain', 'test.txt' ); |
|
178
|
|
|
|
|
179
|
|
|
$transport = new TestMailTransport(); |
|
180
|
|
|
$object->getObject()->send( $transport ); |
|
181
|
|
|
|
|
182
|
|
|
$exp = '#Content-Disposition: inline; filename="test.txt".*Content-Disposition: inline; filename="1_test.txt"#smu'; |
|
183
|
|
|
$this->assertRegExp( $exp, $transport->message ); |
|
184
|
|
|
} |
|
185
|
|
|
|
|
186
|
|
|
|
|
187
|
|
|
public function testGetObject() |
|
188
|
|
|
{ |
|
189
|
|
|
$this->assertInstanceOf( 'Zend_Mail', $this->object->getObject() ); |
|
190
|
|
|
} |
|
191
|
|
|
|
|
192
|
|
|
|
|
193
|
|
|
public function testGenerateMailAlternative() |
|
194
|
|
|
{ |
|
195
|
|
|
$object = new \Aimeos\MW\Mail\Message\Zend( new \Zend_Mail() ); |
|
196
|
|
|
|
|
197
|
|
|
$object->setBody( 'text body' ); |
|
198
|
|
|
$object->setBodyHtml( 'html body' ); |
|
199
|
|
|
|
|
200
|
|
|
$transport = new TestMailTransport(); |
|
201
|
|
|
$object->getObject()->send( $transport ); |
|
202
|
|
|
|
|
203
|
|
|
$exp = '#Content-Type: multipart/alternative;.*Content-Type: text/plain;.*Content-Type: text/html;#smu'; |
|
204
|
|
|
$this->assertRegExp( $exp, $transport->message ); |
|
205
|
|
|
} |
|
206
|
|
|
|
|
207
|
|
|
|
|
208
|
|
|
public function testGenerateMailRelated() |
|
209
|
|
|
{ |
|
210
|
|
|
$object = new \Aimeos\MW\Mail\Message\Zend( new \Zend_Mail() ); |
|
211
|
|
|
|
|
212
|
|
|
$object->embedAttachment( 'embedded-data', 'text/plain', 'embedded.txt' ); |
|
213
|
|
|
$object->setBodyHtml( 'html body' ); |
|
214
|
|
|
|
|
215
|
|
|
$transport = new TestMailTransport(); |
|
216
|
|
|
$object->getObject()->send( $transport ); |
|
217
|
|
|
|
|
218
|
|
|
$exp = '#Content-Type: multipart/related.*Content-Type: text/html;.*Content-Type: text/plain#smu'; |
|
219
|
|
|
$this->assertRegExp( $exp, $transport->message ); |
|
220
|
|
|
} |
|
221
|
|
|
|
|
222
|
|
|
|
|
223
|
|
|
public function testGenerateMailFull() |
|
224
|
|
|
{ |
|
225
|
|
|
$object = new \Aimeos\MW\Mail\Message\Zend( new \Zend_Mail() ); |
|
226
|
|
|
|
|
227
|
|
|
$object->addAttachment( 'attached-data', 'text/plain', 'attached.txt' ); |
|
228
|
|
|
$object->embedAttachment( 'embedded-data', 'text/plain', 'embedded.txt' ); |
|
229
|
|
|
$object->setBodyHtml( 'html body' ); |
|
230
|
|
|
$object->setBody( 'text body' ); |
|
231
|
|
|
|
|
232
|
|
|
$transport = new TestMailTransport(); |
|
233
|
|
|
$object->getObject()->send( $transport ); |
|
234
|
|
|
|
|
235
|
|
|
$exp = '#Content-Type: multipart/mixed;.*Content-Type: multipart/alternative;.*Content-Type: text/plain;.*Content-Type: multipart/related.*Content-Type: text/html;.*Content-Type: text/plain.*Content-Type: text/plain#smu'; |
|
236
|
|
|
$this->assertRegExp( $exp, $transport->message ); |
|
237
|
|
|
} |
|
238
|
|
|
} |
|
239
|
|
|
|
|
240
|
|
|
|
|
241
|
|
|
|
|
242
|
|
|
if( !class_exists( '\Zend_Mail_Transport_Abstract' ) ) { |
|
243
|
|
|
return; |
|
244
|
|
|
} |
|
245
|
|
|
|
|
246
|
|
|
class TestMailTransport extends \Zend_Mail_Transport_Abstract |
|
|
|
|
|
|
247
|
|
|
{ |
|
248
|
|
|
public $message; |
|
249
|
|
|
|
|
250
|
|
|
protected function _sendMail() |
|
251
|
|
|
{ |
|
252
|
|
|
$this->message = $this->header . "\r\n" . $this->body; |
|
253
|
|
|
} |
|
254
|
|
|
} |
|
255
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths