[FOLLOWUP][TASK] Replace @expectedException in ext:core
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Tests / Unit / Mail / MailMessageTest.php
1 <?php
2 namespace TYPO3\CMS\Core\Tests\Unit\Mail;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 /**
18 * Testcase for the TYPO3\CMS\Core\Mail\MailMessage class.
19 */
20 class MailMessageTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
21 {
22 /**
23 * @var \TYPO3\CMS\Core\Mail\MailMessage
24 */
25 protected $subject;
26
27 protected function setUp()
28 {
29 $this->subject = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\Mail\MailMessage::class);
30 }
31
32 /**
33 * @returns array
34 */
35 public function returnPathEmailAddressDataProvider()
36 {
37 return [
38 'string with ascii email address' => [
39 'john.doe@example.com',
40 'john.doe@example.com'
41 ],
42 'string with utf8 email address' => [
43 'john.doe@☺example.com',
44 'john.doe@xn--example-tc7d.com'
45 ]
46 ];
47 }
48
49 /**
50 * @test
51 * @param string $address
52 * @param string $expected
53 * @dataProvider returnPathEmailAddressDataProvider
54 */
55 public function setReturnPathIdnaEncodesAddresses($address, $expected)
56 {
57 $this->subject->setReturnPath($address);
58
59 $this->assertSame($expected, $this->subject->getReturnPath());
60 }
61
62 /**
63 * @returns array
64 */
65 public function senderEmailAddressDataProvider()
66 {
67 return [
68 'string with ascii email address' => [
69 'john.doe@example.com',
70 [
71 'john.doe@example.com' => null,
72 ]
73 ],
74 'string with utf8 email address' => [
75 'john.doe@☺example.com',
76 [
77 'john.doe@xn--example-tc7d.com' => null,
78 ]
79 ]
80 ];
81 }
82
83 /**
84 * @test
85 * @param string $address
86 * @param array $expected
87 * @dataProvider senderEmailAddressDataProvider
88 */
89 public function setSenderIdnaEncodesAddresses($address, $expected)
90 {
91 $this->subject->setSender($address);
92
93 $this->assertSame($expected, $this->subject->getSender());
94 }
95
96 /**
97 * @returns array
98 */
99 public function emailAddressesDataProvider()
100 {
101 return [
102 'string with ascii email address' => [
103 'john.doe@example.com',
104 [
105 'john.doe@example.com' => null
106 ]
107 ],
108 'string with utf8 email address' => [
109 'john.doe@☺example.com',
110 [
111 'john.doe@xn--example-tc7d.com' => null
112 ]
113 ],
114 'array with ascii email addresses' => [
115 [
116 'john.doe@example.com' => 'John Doe',
117 'jane.doe@example.com'
118 ],
119 [
120 'john.doe@example.com' => 'John Doe',
121 'jane.doe@example.com' => null,
122 ],
123 ],
124 'array with utf8 email addresses' => [
125 [
126 'john.doe@☺example.com' => 'John Doe',
127 'jane.doe@äöu.com' => 'Jane Doe',
128 ],
129 [
130 'john.doe@xn--example-tc7d.com' => 'John Doe',
131 'jane.doe@xn--u-zfa8c.com' => 'Jane Doe',
132 ],
133 ],
134 'array with mixed email addresses' => [
135 [
136 'john.doe@☺example.com' => 'John Doe',
137 'jane.doe@example.com' => 'Jane Doe',
138 ],
139 [
140 'john.doe@xn--example-tc7d.com' => 'John Doe',
141 'jane.doe@example.com' => 'Jane Doe',
142 ],
143 ],
144 ];
145 }
146
147 /**
148 * @test
149 * @param string|array $addresses
150 * @param string|array $expected
151 * @dataProvider emailAddressesDataProvider
152 */
153 public function setFromIdnaEncodesAddresses($addresses, $expected)
154 {
155 $this->subject->setFrom($addresses);
156
157 $this->assertSame($expected, $this->subject->getFrom());
158 }
159
160 /**
161 * @test
162 * @param string|array $addresses
163 * @param string|array $expected
164 * @dataProvider emailAddressesDataProvider
165 */
166 public function setReplyToIdnaEncodesAddresses($addresses, $expected)
167 {
168 $this->subject->setReplyTo($addresses);
169
170 $this->assertSame($expected, $this->subject->getReplyTo());
171 }
172
173 /**
174 * @test
175 * @param string|array $addresses
176 * @param string|array $expected
177 * @dataProvider emailAddressesDataProvider
178 */
179 public function setToIdnaEncodesAddresses($addresses, $expected)
180 {
181 $this->subject->setTo($addresses);
182
183 $this->assertSame($expected, $this->subject->getTo());
184 }
185
186 /**
187 * @test
188 * @param string|array $addresses
189 * @param string|array $expected
190 * @dataProvider emailAddressesDataProvider
191 */
192 public function setCcIdnaEncodesAddresses($addresses, $expected)
193 {
194 $this->subject->setCc($addresses);
195
196 $this->assertSame($expected, $this->subject->getCc());
197 }
198
199 /**
200 * @test
201 * @param string|array $addresses
202 * @param string|array $expected
203 * @dataProvider emailAddressesDataProvider
204 */
205 public function setBccIdnaEncodesAddresses($addresses, $expected)
206 {
207 $this->subject->setBcc($addresses);
208
209 $this->assertSame($expected, $this->subject->getBcc());
210 }
211
212 /**
213 * @test
214 * @param string|array $addresses
215 * @param string|array $expected
216 * @dataProvider emailAddressesDataProvider
217 */
218 public function setReadReceiptToIdnaEncodesAddresses($addresses, $expected)
219 {
220 $this->subject->setReadReceiptTo($addresses);
221
222 $this->assertSame($expected, $this->subject->getReadReceiptTo());
223 }
224 }