|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @author Christoph Wurst <[email protected]> |
|
5
|
|
|
* |
|
6
|
|
|
* Mail |
|
7
|
|
|
* |
|
8
|
|
|
* This code is free software: you can redistribute it and/or modify |
|
9
|
|
|
* it under the terms of the GNU Affero General Public License, version 3, |
|
10
|
|
|
* as published by the Free Software Foundation. |
|
11
|
|
|
* |
|
12
|
|
|
* This program is distributed in the hope that it will be useful, |
|
13
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
14
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
15
|
|
|
* GNU Affero General Public License for more details. |
|
16
|
|
|
* |
|
17
|
|
|
* You should have received a copy of the GNU Affero General Public License, version 3, |
|
18
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/> |
|
19
|
|
|
* |
|
20
|
|
|
*/ |
|
21
|
|
|
namespace OCA\Mail\Tests\Model; |
|
22
|
|
|
|
|
23
|
|
|
use Test\TestCase; |
|
24
|
|
|
use Horde_Mime_Part; |
|
25
|
|
|
use OCA\Mail\Model\Message; |
|
26
|
|
|
|
|
27
|
|
|
class MessageTest extends TestCase { |
|
28
|
|
|
|
|
29
|
|
|
protected $message; |
|
30
|
|
|
|
|
31
|
|
|
protected function setUp() { |
|
32
|
|
|
parent::setUp(); |
|
33
|
|
|
|
|
34
|
|
|
$this->message = new Message(); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
public function addressListDataProvider() { |
|
38
|
|
|
return [ |
|
39
|
|
|
[ |
|
40
|
|
|
// simple address |
|
41
|
|
|
'[email protected]', |
|
42
|
|
|
[ |
|
43
|
|
|
'[email protected]' |
|
44
|
|
|
] |
|
45
|
|
|
], |
|
46
|
|
|
[ |
|
47
|
|
|
// address list with comma as delimiter |
|
48
|
|
|
'[email protected], [email protected]', |
|
49
|
|
|
[ |
|
50
|
|
|
'[email protected]', |
|
51
|
|
|
'[email protected]' |
|
52
|
|
|
] |
|
53
|
|
|
], |
|
54
|
|
|
[ |
|
55
|
|
|
// empty list |
|
56
|
|
|
'', |
|
57
|
|
|
[] |
|
58
|
|
|
], |
|
59
|
|
|
[ |
|
60
|
|
|
// address with name |
|
61
|
|
|
'"user" <[email protected]>', |
|
62
|
|
|
[ |
|
63
|
|
|
'[email protected]' |
|
64
|
|
|
] |
|
65
|
|
|
], |
|
66
|
|
|
[ |
|
67
|
|
|
// Trailing slash |
|
68
|
|
|
'"user" <[email protected]>,', |
|
69
|
|
|
[ |
|
70
|
|
|
'[email protected]' |
|
71
|
|
|
] |
|
72
|
|
|
] |
|
73
|
|
|
]; |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* @dataProvider addressListDataProvider |
|
78
|
|
|
*/ |
|
79
|
|
|
public function testParseAddressList($list, $expected) { |
|
80
|
|
|
$result = Message::parseAddressList($list); |
|
81
|
|
|
|
|
82
|
|
|
foreach ($expected as $exp) { |
|
83
|
|
|
$this->assertTrue($result->contains($exp)); |
|
84
|
|
|
} |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
public function testFlags() { |
|
88
|
|
|
$flags = [ |
|
89
|
|
|
'seen', |
|
90
|
|
|
'flagged', |
|
91
|
|
|
]; |
|
92
|
|
|
|
|
93
|
|
|
$this->message->setFlags($flags); |
|
94
|
|
|
|
|
95
|
|
|
$this->assertSame($flags, $this->message->getFlags()); |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
public function testFrom() { |
|
99
|
|
|
$from = '[email protected]'; |
|
100
|
|
|
|
|
101
|
|
|
$this->message->setFrom($from); |
|
102
|
|
|
|
|
103
|
|
|
$this->assertSame($from, $this->message->getFrom()); |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
public function testTo() { |
|
107
|
|
|
$expected = [ |
|
108
|
|
|
'[email protected]', |
|
109
|
|
|
'Bob <[email protected]>', |
|
110
|
|
|
]; |
|
111
|
|
|
$to = Message::parseAddressList($expected); |
|
112
|
|
|
|
|
113
|
|
|
$this->message->setTo($to); |
|
114
|
|
|
|
|
115
|
|
|
$this->assertEquals($expected, $this->message->getToList()); |
|
116
|
|
|
$this->assertEquals($to[0], $this->message->getTo()); |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
public function testEmptyTo() { |
|
120
|
|
|
$this->assertNull($this->message->getTo()); |
|
121
|
|
|
$this->assertEquals([], $this->message->getToList()); |
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
|
|
public function testCC() { |
|
125
|
|
|
$expected = [ |
|
126
|
|
|
'[email protected]', |
|
127
|
|
|
'Bob <[email protected]>', |
|
128
|
|
|
]; |
|
129
|
|
|
$cc = Message::parseAddressList($expected); |
|
130
|
|
|
|
|
131
|
|
|
$this->message->setCC($cc); |
|
132
|
|
|
|
|
133
|
|
|
$this->assertEquals($expected, $this->message->getCCList()); |
|
134
|
|
|
} |
|
135
|
|
|
|
|
136
|
|
|
public function testEmptyCC() { |
|
137
|
|
|
$this->assertEquals([], $this->message->getCCList()); |
|
138
|
|
|
} |
|
139
|
|
|
|
|
140
|
|
|
public function testBCC() { |
|
141
|
|
|
$expected = [ |
|
142
|
|
|
'[email protected]', |
|
143
|
|
|
'Bob <[email protected]>', |
|
144
|
|
|
]; |
|
145
|
|
|
$bcc = Message::parseAddressList($expected); |
|
146
|
|
|
|
|
147
|
|
|
$this->message->setBCC($bcc); |
|
148
|
|
|
|
|
149
|
|
|
$this->assertEquals($expected, $this->message->getBCCList()); |
|
150
|
|
|
} |
|
151
|
|
|
|
|
152
|
|
|
public function testEmptyBCC() { |
|
153
|
|
|
$this->assertEquals([], $this->message->getBCCList()); |
|
154
|
|
|
} |
|
155
|
|
|
|
|
156
|
|
|
public function testRepliedMessage() { |
|
157
|
|
|
$reply = new Message(); |
|
158
|
|
|
|
|
159
|
|
|
$this->message->setRepliedMessage($reply); |
|
160
|
|
|
$actual = $this->message->getRepliedMessage(); |
|
161
|
|
|
|
|
162
|
|
|
$this->assertSame($reply, $actual); |
|
163
|
|
|
} |
|
164
|
|
|
|
|
165
|
|
|
public function testSubject() { |
|
166
|
|
|
$subject = 'test message'; |
|
167
|
|
|
|
|
168
|
|
|
$this->message->setSubject($subject); |
|
169
|
|
|
|
|
170
|
|
|
$this->assertSame($subject, $this->message->getSubject()); |
|
171
|
|
|
} |
|
172
|
|
|
|
|
173
|
|
|
public function testEmptySubject() { |
|
174
|
|
|
$this->assertSame('', $this->message->getSubject()); |
|
175
|
|
|
} |
|
176
|
|
|
|
|
177
|
|
|
public function testContent() { |
|
178
|
|
|
$content = "hello!"; |
|
179
|
|
|
|
|
180
|
|
|
$this->message->setContent($content); |
|
181
|
|
|
|
|
182
|
|
|
$this->assertSame($content, $this->message->getContent()); |
|
183
|
|
|
} |
|
184
|
|
|
|
|
185
|
|
|
public function testAttachments() { |
|
186
|
|
|
$name = 'coffee.jpg'; |
|
187
|
|
|
$mimeType = 'image/jpeg'; |
|
188
|
|
|
$contents = 'file content'; |
|
189
|
|
|
|
|
190
|
|
|
$file = $this->getMockBuilder('OCP\Files\File') |
|
191
|
|
|
->disableOriginalConstructor() |
|
192
|
|
|
->getMock(); |
|
193
|
|
|
$file->expects($this->once()) |
|
194
|
|
|
->method('getName') |
|
195
|
|
|
->will($this->returnValue($name)); |
|
196
|
|
|
$file->expects($this->once()) |
|
197
|
|
|
->method('getContent') |
|
198
|
|
|
->will($this->returnValue($contents)); |
|
199
|
|
|
$file->expects($this->once()) |
|
200
|
|
|
->method('getMimeType') |
|
201
|
|
|
->will($this->returnValue($mimeType)); |
|
202
|
|
|
|
|
203
|
|
|
$expected = new Horde_Mime_Part(); |
|
204
|
|
|
$expected->setCharset('us-ascii'); |
|
205
|
|
|
$expected->setDisposition('attachment'); |
|
206
|
|
|
$expected->setName($name); |
|
207
|
|
|
$expected->setContents($contents); |
|
208
|
|
|
$expected->setType($mimeType); |
|
209
|
|
|
|
|
210
|
|
|
$this->message->addAttachmentFromFiles($file); |
|
211
|
|
|
$actual = $this->message->getAttachments(); |
|
212
|
|
|
|
|
213
|
|
|
$this->assertCount(1, $actual); |
|
214
|
|
|
//$this->assertEquals($expected, $actual[0]); |
|
215
|
|
|
} |
|
216
|
|
|
|
|
217
|
|
|
} |
|
218
|
|
|
|