@@ -14,9 +14,44 @@ final class CustomFromTest extends TestCase
14
14
{
15
15
const CONTAINS = 'custom_from_compose_contains ' ;
16
16
const DISABLE = 'custom_from_preference_disable ' ;
17
+ const IDENTITY = 'custom_from_compose_identity ' ;
17
18
const RULES = 'custom_from_header_rules ' ;
18
19
const SUBJECT = 'custom_from_compose_subject ' ;
19
20
21
+ public static function identity_select_should_select_matched_identity_provider (): array
22
+ {
23
+ return array (
24
+ array ('1 ' , 0 ),
25
+ array ('2 ' , 1 ),
26
+ array ('3 ' , null )
27
+ );
28
+ }
29
+
30
+ #[DataProvider('identity_select_should_select_matched_identity_provider ' )]
31
+ public function test_identity_select_should_select_matched_identity ($ identity , $ expected ): void
32
+ {
33
+ $ rcmail = rcmail::mock ();
34
+ $ rcmail ->mock_config (array ());
35
+ $ rcmail ->mock_user (array (), array ());
36
+
37
+ $ plugin = self ::create_plugin ();
38
+
39
+ rcube_utils::mock_input_value ('_id ' , '42 ' );
40
+
41
+ self ::set_state ($ plugin , '42 ' , $ identity , null );
42
+
43
+ $ params = $ plugin ->identity_select (array ('identities ' => array (
44
+ array ('identity_id ' => '1 ' ),
45
+ array ('identity_id ' => '2 ' )
46
+ )));
47
+
48
+ if ($ expected !== null ) {
49
+ $ this ->assertSame ($ params ['selected ' ], $ expected );
50
+ } else {
51
+ $ this ->assertSame (isset ($ params ['selected ' ]), false );
52
+ }
53
+ }
54
+
20
55
public static function storage_init_should_fetch_headers_provider (): array
21
56
{
22
57
return array (
@@ -69,90 +104,142 @@ public static function message_compose_should_set_state_provider(): array
69
104
array (
'to ' =>
'[email protected] ' ),
70
105
array (self ::RULES => 'to=e ' ),
71
106
array (),
72
- array ('email ' => null , 'id ' => '1 ' )
107
+ '1 ' ,
108
+ null
73
109
),
74
110
// Subject rule "exact" shouldn't match suffix
75
111
array (
76
112
array (
'to ' =>
'[email protected] ' ),
77
113
array (self ::RULES => 'to=e ' ),
78
114
array (),
79
115
null ,
116
+ null ,
80
117
),
81
118
// Subject rule "prefix" should match address exactly
82
119
array (
83
120
array (
'to ' =>
'[email protected] ' ),
84
121
array (),
85
122
array (),
86
- array ('email ' => null , 'id ' => '1 ' )
123
+ '1 ' ,
124
+ null
87
125
),
88
126
// Subject rule "prefix" should match address by prefix
89
127
array (
90
128
array (
'to ' =>
'[email protected] ' ),
91
129
array (),
92
130
array (),
93
- array (
'email ' =>
'[email protected] ' ,
'id ' =>
'1 ' )
131
+ '1 ' ,
132
+
94
133
),
95
134
// Subject rule "prefix" should not match different user
96
135
array (
97
136
array (
'to ' =>
'[email protected] ' ),
98
137
array (),
99
138
array (),
100
139
null ,
140
+ null ,
101
141
),
102
142
// Subject rule "domain" on custom header should match address by domain
103
143
array (
104
144
array (
'to ' =>
'[email protected] ' ,
'x-custom ' =>
'[email protected] ' ),
105
145
array (self ::RULES => 'x-custom=d ' ),
106
146
array (),
107
- array (
'email ' =>
'[email protected] ' ,
'id ' =>
'3 ' )
147
+ '3 ' ,
148
+
108
149
),
109
150
// Subject rule "domain" should not match different domain
110
151
array (
111
152
array (
'to ' =>
'[email protected] ' ),
112
153
array (self ::RULES => 'to=d ' ),
113
154
array (),
114
155
null ,
156
+ null ,
115
157
),
116
158
// Subject rule "other" should match anything
117
159
array (
118
160
array (
'to ' =>
'[email protected] ' ),
119
161
array (self ::RULES => 'to=o ' ),
120
162
array (),
121
- array (
'email ' =>
'[email protected] ' ,
'id ' =>
'2 ' )
163
+ '2 ' ,
164
+
122
165
),
123
166
// Subject rule is overridden by user prefrences
124
167
array (
125
168
array (
'to ' =>
'[email protected] ' ),
126
169
array (self ::RULES => 'to=e ' ),
127
170
array (self ::SUBJECT => 'domain ' ),
128
- array (
'email ' =>
'[email protected] ' ,
'id ' =>
'3 ' )
171
+ '3 ' ,
172
+
129
173
),
130
174
// Contains constraint in configuration options matches address
131
175
array (
132
176
array (
'to ' =>
'[email protected] ' ),
133
177
array (self ::CONTAINS => 'match ' ),
134
178
array (self ::SUBJECT => 'domain ' ),
135
- array (
'email ' =>
'[email protected] ' ,
'id ' =>
'1 ' )
179
+ '1 ' ,
180
+
136
181
),
137
182
// Contains constraint in configuration options rejects no match
138
183
array (
139
184
array (
'to ' =>
'[email protected] ' ),
140
185
array (self ::CONTAINS => 'match ' ),
141
186
array (self ::SUBJECT => 'domain ' ),
187
+ null ,
142
188
null
143
189
),
144
190
// Contains constraint in user preferences rejects no match
145
191
array (
146
192
array (
'to ' =>
'[email protected] ' ),
147
193
array (self ::CONTAINS => 'other ' ),
148
194
array (self ::CONTAINS => 'match ' , self ::SUBJECT => 'always ' ),
195
+ null ,
196
+ null
197
+ ),
198
+ // Identity behavior "default" returns matched identity with no sender on exact match
199
+ array (
200
+ array (
'to ' =>
'[email protected] ' ),
201
+ array (),
202
+ array (self ::SUBJECT => 'always ' ),
203
+ '3 ' ,
204
+ null
205
+ ),
206
+ // Identity behavior "default" returns matched identity and sender with identity name on domain match
207
+ array (
208
+ array (
'to ' =>
'[email protected] ' ),
209
+ array (),
210
+ array (self ::SUBJECT => 'domain ' ),
211
+ '3 ' ,
212
+
213
+ ),
214
+ // Identity behavior "loose" returns matched identity and sender with identity name on prefix match
215
+ array (
216
+ array (
'to ' =>
'SomeName <[email protected] > ' ),
217
+ array (),
218
+ array (self ::IDENTITY => 'loose ' , self ::SUBJECT => 'prefix ' ),
219
+ '3 ' ,
220
+
221
+ ),
222
+ // Identity behavior "exact" returns matched identity with no sender on exact match
223
+ array (
224
+ array (
'to ' =>
'[email protected] ' ),
225
+ array (self ::IDENTITY => 'exact ' ),
226
+ array (self ::SUBJECT => 'always ' ),
227
+ '3 ' ,
149
228
null
150
229
),
230
+ // Identity behavior "exact" returns no identity and sender with recipient name on prefix match
231
+ array (
232
+ array (
'to ' =>
'SomeName <[email protected] > ' ),
233
+ array (),
234
+ array (self ::IDENTITY => 'exact ' , self ::SUBJECT => 'prefix ' ),
235
+ null ,
236
+
237
+ )
151
238
);
152
239
}
153
240
154
241
#[DataProvider('message_compose_should_set_state_provider ' )]
155
- public function test_message_compose_should_set_state ($ message , $ config_values , $ user_prefs , $ expected ): void
242
+ public function test_message_compose_should_set_state ($ message , $ config_values , $ user_prefs , $ expected_identity , $ expected_sender ): void
156
243
{
157
244
$ identity1 =
array (
'identity_id ' =>
'1 ' ,
'email ' =>
'[email protected] ' ,
'name ' =>
'Alice ' ,
'standard ' =>
'0 ' );
158
245
$ identity2 =
array (
'identity_id ' =>
'2 ' ,
'email ' =>
'[email protected] ' ,
'name ' =>
'Bob ' ,
'standard ' =>
'1 ' );
@@ -168,7 +255,9 @@ public function test_message_compose_should_set_state($message, $config_values,
168
255
$ plugin = self ::create_plugin ();
169
256
$ plugin ->message_compose (array ('id ' => $ compose_id , 'param ' => array ('uid ' => $ message_id )));
170
257
171
- $ this ->assertSame ($ _SESSION ["custom_from_ $ compose_id " ], $ expected );
258
+ $ state = self ::get_state ($ plugin , $ compose_id );
259
+
260
+ $ this ->assertSame ($ state , array ($ expected_identity , $ expected_sender ));
172
261
}
173
262
174
263
private static function create_plugin ()
@@ -178,4 +267,20 @@ private static function create_plugin()
178
267
179
268
return $ plugin ;
180
269
}
270
+
271
+ private static function get_state ($ plugin , $ compose_id )
272
+ {
273
+ $ class = new ReflectionClass ($ plugin );
274
+ $ method = $ class ->getMethod ('get_state ' );
275
+
276
+ return $ method ->invokeArgs (null , array ($ compose_id ));
277
+ }
278
+
279
+ private static function set_state ($ plugin , $ compose_id , $ identity , $ sender )
280
+ {
281
+ $ class = new ReflectionClass ($ plugin );
282
+ $ method = $ class ->getMethod ('set_state ' );
283
+
284
+ return $ method ->invokeArgs (null , array ($ compose_id , $ identity , $ sender ));
285
+ }
181
286
}
0 commit comments