1
|
|
|
<?php |
2
|
|
|
namespace AcMailerTest\Service; |
3
|
|
|
|
4
|
|
|
use AcMailer\Service\ConfigMigrationService; |
5
|
|
|
use PHPUnit_Framework_TestCase as TestCase; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Class ConfigMigrationServiceTest |
9
|
|
|
* @author Alejandro Celaya Alastrué |
10
|
|
|
* @link http://www.alejandrocelaya.com |
11
|
|
|
*/ |
12
|
|
|
class ConfigMigrationServiceTest extends TestCase |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* @var ConfigMigrationService |
16
|
|
|
*/ |
17
|
|
|
protected $service; |
18
|
|
|
|
19
|
|
|
public function setUp() |
20
|
|
|
{ |
21
|
|
|
$this->service = new ConfigMigrationService(); |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
public function testParseEmptyConfig() |
25
|
|
|
{ |
26
|
|
|
$oldConfig = []; |
27
|
|
|
$expected = [ |
28
|
|
|
'acmailer_options' => [ |
29
|
|
|
'default' => [ |
30
|
|
|
'message_options' => [ |
31
|
|
|
'body' => [] |
32
|
|
|
], |
33
|
|
|
'smtp_options' => [ |
34
|
|
|
'connection_config' => [] |
35
|
|
|
], |
36
|
|
|
'file_options' => [] |
37
|
|
|
] |
38
|
|
|
] |
39
|
|
|
]; |
40
|
|
|
$this->assertEquals($expected, $this->service->parseConfig($oldConfig)); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
public function testParseCompleteConfig() |
44
|
|
|
{ |
45
|
|
|
$oldConfig = [ |
46
|
|
|
'mail_adapter' => 'Zend\Mail\Transport\Smtp', |
47
|
|
|
|
48
|
|
|
'from' => '[email protected]', |
49
|
|
|
'from_name' => 'Alejandro', |
50
|
|
|
'to' => [], |
51
|
|
|
'cc' => [], |
52
|
|
|
'bcc' => [], |
53
|
|
|
'subject' => 'The subject', |
54
|
|
|
'body' => 'The body', |
55
|
|
|
'body_charset' => 'utf-8', |
56
|
|
|
'template' => [ |
57
|
|
|
'use_template' => false, |
58
|
|
|
'path' => 'ac-mailer/mail-templates/layout', |
59
|
|
|
'params' => [], |
60
|
|
|
'children' => [ |
61
|
|
|
'content' => [ |
62
|
|
|
'path' => 'ac-mailer/mail-templates/mail', |
63
|
|
|
'params' => [], |
64
|
|
|
] |
65
|
|
|
] |
66
|
|
|
], |
67
|
|
|
'attachments' => [ |
68
|
|
|
'files' => [], |
69
|
|
|
'dir' => [ |
70
|
|
|
'iterate' => false, |
71
|
|
|
'path' => 'data/mail/attachments', |
72
|
|
|
'recursive' => false, |
73
|
|
|
], |
74
|
|
|
], |
75
|
|
|
|
76
|
|
|
'server' => 'localhost', |
77
|
|
|
'smtp_user' => 'me', |
78
|
|
|
'smtp_password' => 'foobar', |
79
|
|
|
'ssl' => false, |
80
|
|
|
'connection_class' => 'login', |
81
|
|
|
'port' => 25, |
82
|
|
|
|
83
|
|
|
'file_path' => 'data/mail/output', |
84
|
|
|
'file_callback' => [], |
85
|
|
|
]; |
86
|
|
|
$expected = [ |
87
|
|
|
'acmailer_options' => [ |
88
|
|
|
'default' => [ |
89
|
|
|
'mail_adapter' => 'Zend\Mail\Transport\Smtp', |
90
|
|
|
'message_options' => [ |
91
|
|
|
'from' => '[email protected]', |
92
|
|
|
'from_name' => 'Alejandro', |
93
|
|
|
'to' => [], |
94
|
|
|
'cc' => [], |
95
|
|
|
'bcc' => [], |
96
|
|
|
'subject' => 'The subject', |
97
|
|
|
'body' => [ |
98
|
|
|
'content' => 'The body', |
99
|
|
|
'charset' => 'utf-8', |
100
|
|
|
'use_template' => false, |
101
|
|
|
'template' => [ |
102
|
|
|
'path' => 'ac-mailer/mail-templates/layout', |
103
|
|
|
'params' => [], |
104
|
|
|
'children' => [ |
105
|
|
|
'content' => [ |
106
|
|
|
'path' => 'ac-mailer/mail-templates/mail', |
107
|
|
|
'params' => [], |
108
|
|
|
] |
109
|
|
|
], |
110
|
|
|
'default_layout' => [] |
111
|
|
|
], |
112
|
|
|
], |
113
|
|
|
'attachments' => [ |
114
|
|
|
'files' => [], |
115
|
|
|
'dir' => [ |
116
|
|
|
'iterate' => false, |
117
|
|
|
'path' => 'data/mail/attachments', |
118
|
|
|
'recursive' => false, |
119
|
|
|
], |
120
|
|
|
], |
121
|
|
|
], |
122
|
|
|
'smtp_options' => [ |
123
|
|
|
'host' => 'localhost', |
124
|
|
|
'port' => 25, |
125
|
|
|
'connection_class' => 'login', |
126
|
|
|
'connection_config' => [ |
127
|
|
|
'username' => 'me', |
128
|
|
|
'password' => 'foobar', |
129
|
|
|
'ssl' => false, |
130
|
|
|
] |
131
|
|
|
], |
132
|
|
|
'file_options' => [ |
133
|
|
|
'path' => 'data/mail/output', |
134
|
|
|
'callback' => [], |
135
|
|
|
] |
136
|
|
|
] |
137
|
|
|
] |
138
|
|
|
]; |
139
|
|
|
$this->assertEquals($expected, $this->service->parseConfig($oldConfig)); |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
public function testParseConfigWithAdapterService() |
143
|
|
|
{ |
144
|
|
|
$oldConfig = [ |
145
|
|
|
'mail_adapter' => 'Zend\Mail\Transport\Smtp', |
146
|
|
|
'mail_adapter_service' => 'this_has_preference' |
147
|
|
|
]; |
148
|
|
|
$expected = [ |
149
|
|
|
'acmailer_options' => [ |
150
|
|
|
'default' => [ |
151
|
|
|
'mail_adapter' => 'this_has_preference', |
152
|
|
|
'message_options' => [ |
153
|
|
|
'body' => [] |
154
|
|
|
], |
155
|
|
|
'smtp_options' => [ |
156
|
|
|
'connection_config' => [] |
157
|
|
|
], |
158
|
|
|
'file_options' => [] |
159
|
|
|
] |
160
|
|
|
] |
161
|
|
|
]; |
162
|
|
|
$this->assertEquals($expected, $this->service->parseConfig($oldConfig)); |
163
|
|
|
} |
164
|
|
|
} |
165
|
|
|
|