3
3
* Copyright © 2015 Magento. All rights reserved.
4
4
* See COPYING.txt for license details.
5
5
*/
6
- // @codingStandardsIgnoreFile
7
6
8
7
namespace Magento \Customer \Test \Unit \Controller \Adminhtml \Index ;
9
8
@@ -60,7 +59,10 @@ class ValidateTest extends \PHPUnit_Framework_TestCase
60
59
/** @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\Controller\Result\Json */
61
60
protected $ resultJson ;
62
61
63
- public function testExecute ()
62
+ /** @var \Magento\Customer\Controller\Adminhtml\Index\Validate */
63
+ protected $ controller ;
64
+
65
+ public function setUp ()
64
66
{
65
67
$ this ->customer = $ this ->getMockForAbstractClass (
66
68
'Magento\Customer\Api\Data\CustomerInterface ' ,
@@ -71,7 +73,6 @@ public function testExecute()
71
73
true
72
74
);
73
75
$ this ->customer ->expects ($ this ->once ())->method ('getWebsiteId ' )->willReturn (2 );
74
-
75
76
$ this ->customerDataFactory = $ this ->getMock (
76
77
'Magento\Customer\Api\Data\CustomerInterfaceFactory ' ,
77
78
['create ' ],
@@ -80,7 +81,13 @@ public function testExecute()
80
81
false
81
82
);
82
83
$ this ->customerDataFactory ->expects ($ this ->once ())->method ('create ' )->willReturn ($ this ->customer );
83
-
84
+ $ this ->form = $ this ->getMock (
85
+ 'Magento\Customer\Model\Metadata\Form ' ,
86
+ [],
87
+ [],
88
+ '' ,
89
+ false
90
+ );
84
91
$ this ->request = $ this ->getMockForAbstractClass (
85
92
'Magento\Framework\App\RequestInterface ' ,
86
93
[],
@@ -90,35 +97,23 @@ public function testExecute()
90
97
true ,
91
98
['getPost ' ]
92
99
);
93
- $ this ->request ->expects ($ this ->once ())
94
- ->method ('getPost ' )
95
- ->willReturn ([
96
- '_template_ ' => null ,
97
- 'address_index ' => null
98
- ]);
99
- $ this ->response = $ this ->getMockForAbstractClass ('Magento\Framework\App\ResponseInterface ' , [], '' , false );
100
- $ this ->form = $ this ->getMock ('Magento\Customer\Model\Metadata\Form ' , [], [], '' , false );
101
- $ this ->form ->expects ($ this ->once ())->method ('setInvisibleIgnored ' );
102
- $ this ->form ->expects ($ this ->atLeastOnce ())->method ('extractData ' )->willReturn ([]);
103
-
104
- $ error = $ this ->getMock ('Magento\Framework\Message\Error ' , [], [], '' , false );
105
- $ this ->form ->expects ($ this ->once ())->method ('validateData ' )->willReturn ([$ error ]);
106
-
100
+ $ this ->response = $ this ->getMockForAbstractClass (
101
+ 'Magento\Framework\App\ResponseInterface ' ,
102
+ [],
103
+ '' ,
104
+ false
105
+ );
107
106
$ this ->formFactory = $ this ->getMock ('Magento\Customer\Model\Metadata\FormFactory ' , ['create ' ], [], '' , false );
108
107
$ this ->formFactory ->expects ($ this ->atLeastOnce ())->method ('create ' )->willReturn ($ this ->form );
109
-
110
108
$ this ->extensibleDataObjectConverter = $ this ->getMock (
111
109
'Magento\Framework\Api\ExtensibleDataObjectConverter ' ,
112
110
[],
113
111
[],
114
112
'' ,
115
113
false
116
114
);
117
- $ this ->extensibleDataObjectConverter ->expects ($ this ->once ())->method ('toFlatArray ' )->willReturn ([]);
118
-
119
115
$ this ->dataObjectHelper = $ this ->getMock ('Magento\Framework\Api\DataObjectHelper ' , [], [], '' , false );
120
116
$ this ->dataObjectHelper ->expects ($ this ->once ())->method ('populateWithArray ' );
121
-
122
117
$ this ->customerAccountManagement = $ this ->getMockForAbstractClass (
123
118
'Magento\Customer\Api\AccountManagementInterface ' ,
124
119
[],
@@ -127,19 +122,6 @@ public function testExecute()
127
122
true ,
128
123
true
129
124
);
130
-
131
- $ validationResult = $ this ->getMockForAbstractClass (
132
- 'Magento\Customer\Api\Data\ValidationResultsInterface ' ,
133
- [],
134
- '' ,
135
- false ,
136
- true ,
137
- true
138
- );
139
- $ validationResult ->expects ($ this ->once ())->method ('getMessages ' )->willReturn (['Error message ' ]);
140
-
141
- $ this ->customerAccountManagement ->expects ($ this ->once ())->method ('validate ' )->willReturn ($ validationResult );
142
-
143
125
$ this ->resultJson = $ this ->getMock ('Magento\Framework\Controller\Result\Json ' , [], [], '' , false );
144
126
$ this ->resultJson ->expects ($ this ->once ())->method ('setData ' );
145
127
$ this ->resultJsonFactory = $ this ->getMock (
@@ -150,71 +132,43 @@ public function testExecute()
150
132
false
151
133
);
152
134
$ this ->resultJsonFactory ->expects ($ this ->once ())->method ('create ' )->willReturn ($ this ->resultJson );
153
- $ this ->getController ()->execute ();
154
- }
155
135
156
- public function testExecuteWithoutAddresses ()
157
- {
158
- $ this ->customer = $ this ->getMockForAbstractClass (
159
- 'Magento\Customer\Api\Data\CustomerInterface ' ,
160
- [],
161
- '' ,
162
- false ,
163
- true ,
164
- true
136
+ $ objectHelper = new \Magento \Framework \TestFramework \Unit \Helper \ObjectManager ($ this );
137
+ $ this ->controller = $ objectHelper ->getObject (
138
+ 'Magento\Customer\Controller\Adminhtml\Index\Validate ' ,
139
+ [
140
+ 'request ' => $ this ->request ,
141
+ 'response ' => $ this ->response ,
142
+ 'customerDataFactory ' => $ this ->customerDataFactory ,
143
+ 'formFactory ' => $ this ->formFactory ,
144
+ 'extensibleDataObjectConverter ' => $ this ->extensibleDataObjectConverter ,
145
+ 'customerAccountManagement ' => $ this ->customerAccountManagement ,
146
+ 'resultJsonFactory ' => $ this ->resultJsonFactory ,
147
+ 'dataObjectHelper ' => $ this ->dataObjectHelper ,
148
+ ]
165
149
);
166
- $ this -> customer -> expects ( $ this -> once ())-> method ( ' getWebsiteId ' )-> willReturn ( 2 );
150
+ }
167
151
168
- $ this -> customerDataFactory = $ this -> getMock (
169
- ' Magento\Customer\Api\Data\CustomerInterfaceFactory ' ,
170
- [ ' create ' ],
171
- [],
172
- '' ,
173
- false
174
- );
175
- $ this -> customerDataFactory -> expects ( $ this -> once ())-> method ( ' create ' )-> willReturn ( $ this -> customer );
152
+ public function testExecute ()
153
+ {
154
+ $ this -> request -> expects ( $ this -> once ())
155
+ -> method ( ' getPost ' )
156
+ -> willReturn ([
157
+ ' _template_ ' => null ,
158
+ ' address_index ' => null
159
+ ] );
176
160
177
- $ this ->request = $ this ->getMockForAbstractClass (
178
- 'Magento\Framework\App\RequestInterface ' ,
179
- [],
180
- '' ,
181
- false ,
182
- true ,
183
- true ,
184
- ['getPost ' ]
185
- );
186
- $ this ->request ->expects ($ this ->once ())->method ('getPost ' )->willReturn (null );
187
- $ this ->response = $ this ->getMockForAbstractClass ('Magento\Framework\App\ResponseInterface ' , [], '' , false );
188
- $ this ->form = $ this ->getMock ('Magento\Customer\Model\Metadata\Form ' , [], [], '' , false );
189
161
$ this ->form ->expects ($ this ->once ())->method ('setInvisibleIgnored ' );
190
162
$ this ->form ->expects ($ this ->atLeastOnce ())->method ('extractData ' )->willReturn ([]);
191
163
192
164
$ error = $ this ->getMock ('Magento\Framework\Message\Error ' , [], [], '' , false );
193
- $ this ->form ->expects ($ this ->never ())->method ('validateData ' )->willReturn ([$ error ]);
194
-
195
- $ this ->formFactory = $ this ->getMock ('Magento\Customer\Model\Metadata\FormFactory ' , ['create ' ], [], '' , false );
196
- $ this ->formFactory ->expects ($ this ->atLeastOnce ())->method ('create ' )->willReturn ($ this ->form );
165
+ $ this ->form ->expects ($ this ->once ())
166
+ ->method ('validateData ' )
167
+ ->willReturn ([$ error ]);
197
168
198
- $ this ->extensibleDataObjectConverter = $ this ->getMock (
199
- 'Magento\Framework\Api\ExtensibleDataObjectConverter ' ,
200
- [],
201
- [],
202
- '' ,
203
- false
204
- );
205
- $ this ->extensibleDataObjectConverter ->expects ($ this ->once ())->method ('toFlatArray ' )->willReturn ([]);
206
-
207
- $ this ->dataObjectHelper = $ this ->getMock ('Magento\Framework\Api\DataObjectHelper ' , [], [], '' , false );
208
- $ this ->dataObjectHelper ->expects ($ this ->once ())->method ('populateWithArray ' );
209
-
210
- $ this ->customerAccountManagement = $ this ->getMockForAbstractClass (
211
- 'Magento\Customer\Api\AccountManagementInterface ' ,
212
- [],
213
- '' ,
214
- false ,
215
- true ,
216
- true
217
- );
169
+ $ this ->extensibleDataObjectConverter ->expects ($ this ->once ())
170
+ ->method ('toFlatArray ' )
171
+ ->willReturn ([]);
218
172
219
173
$ validationResult = $ this ->getMockForAbstractClass (
220
174
'Magento\Customer\Api\Data\ValidationResultsInterface ' ,
@@ -224,83 +178,73 @@ public function testExecuteWithoutAddresses()
224
178
true ,
225
179
true
226
180
);
227
- $ validationResult ->expects ($ this ->once ())->method ('getMessages ' )->willReturn (['Error message ' ]);
181
+ $ validationResult ->expects ($ this ->once ())
182
+ ->method ('getMessages ' )
183
+ ->willReturn (['Error message ' ]);
228
184
229
- $ this ->customerAccountManagement ->expects ($ this ->once ())->method ('validate ' )->willReturn ($ validationResult );
185
+ $ this ->customerAccountManagement ->expects ($ this ->once ())
186
+ ->method ('validate ' )
187
+ ->willReturn ($ validationResult );
230
188
231
- $ this ->resultJson = $ this ->getMock ('Magento\Framework\Controller\Result\Json ' , [], [], '' , false );
232
- $ this ->resultJson ->expects ($ this ->once ())->method ('setData ' );
233
- $ this ->resultJsonFactory = $ this ->getMock (
234
- 'Magento\Framework\Controller\Result\JsonFactory ' ,
235
- ['create ' ],
236
- [],
237
- '' ,
238
- false
239
- );
240
- $ this ->resultJsonFactory ->expects ($ this ->once ())->method ('create ' )->willReturn ($ this ->resultJson );
241
- $ this ->getController ()->execute ();
189
+ $ this ->controller ->execute ();
242
190
}
243
191
244
- public function testExecuteWithException ()
192
+ public function testExecuteWithoutAddresses ()
245
193
{
246
- $ this ->customer = $ this ->getMockForAbstractClass (
247
- 'Magento\Customer\Api\Data\CustomerInterface ' ,
248
- [],
249
- '' ,
250
- false ,
251
- true ,
252
- true
253
- );
254
- $ this ->customer ->expects ($ this ->once ())->method ('getWebsiteId ' )->willReturn (2 );
194
+ $ this ->request ->expects ($ this ->once ())
195
+ ->method ('getPost ' )
196
+ ->willReturn (null );
197
+ $ this ->form ->expects ($ this ->once ())
198
+ ->method ('setInvisibleIgnored ' );
199
+ $ this ->form ->expects ($ this ->atLeastOnce ())
200
+ ->method ('extractData ' )
201
+ ->willReturn ([]);
255
202
256
- $ this ->customerDataFactory = $ this ->getMock (
257
- 'Magento\Customer\Api\Data\CustomerInterfaceFactory ' ,
258
- ['create ' ],
259
- [],
260
- '' ,
261
- false
262
- );
263
- $ this ->customerDataFactory ->expects ($ this ->once ())->method ('create ' )->willReturn ($ this ->customer );
264
- $ this ->request = $ this ->getMockForAbstractClass (
265
- 'Magento\Framework\App\RequestInterface ' ,
203
+ $ error = $ this ->getMock ('Magento\Framework\Message\Error ' , [], [], '' , false );
204
+ $ this ->form ->expects ($ this ->never ())
205
+ ->method ('validateData ' )
206
+ ->willReturn ([$ error ]);
207
+
208
+ $ this ->extensibleDataObjectConverter ->expects ($ this ->once ())
209
+ ->method ('toFlatArray ' )
210
+ ->willReturn ([]);
211
+
212
+ $ validationResult = $ this ->getMockForAbstractClass (
213
+ 'Magento\Customer\Api\Data\ValidationResultsInterface ' ,
266
214
[],
267
215
'' ,
268
216
false ,
269
217
true ,
270
- true ,
271
- ['getPost ' ]
218
+ true
272
219
);
273
- $ this ->request ->expects ($ this ->once ())->method ('getPost ' )->willReturn (null );
274
- $ this ->response = $ this ->getMockForAbstractClass ('Magento\Framework\App\ResponseInterface ' , [], '' ,false );
275
- $ this ->form = $ this ->getMock ('Magento\Customer\Model\Metadata\Form ' , [], [], '' , false );
276
- $ this ->form ->expects ($ this ->once ())->method ('setInvisibleIgnored ' );
277
- $ this ->form ->expects ($ this ->atLeastOnce ())->method ('extractData ' )->willReturn ([]);
220
+ $ validationResult ->expects ($ this ->once ())
221
+ ->method ('getMessages ' )
222
+ ->willReturn (['Error message ' ]);
278
223
279
- $ this ->form ->expects ($ this ->never ())->method ('validateData ' );
224
+ $ this ->customerAccountManagement ->expects ($ this ->once ())
225
+ ->method ('validate ' )
226
+ ->willReturn ($ validationResult );
280
227
281
- $ this ->formFactory = $ this -> getMock ( ' Magento\Customer\Model\Metadata\FormFactory ' , [ ' create ' ], [], '' , false );
282
- $ this -> formFactory -> expects ( $ this -> atLeastOnce ())-> method ( ' create ' )-> willReturn ( $ this -> form );
228
+ $ this ->controller -> execute ( );
229
+ }
283
230
284
- $ this ->extensibleDataObjectConverter = $ this ->getMock (
285
- 'Magento\Framework\Api\ExtensibleDataObjectConverter ' ,
286
- [],
287
- [],
288
- '' ,
289
- false
290
- );
291
- $ this ->extensibleDataObjectConverter ->expects ($ this ->once ())->method ('toFlatArray ' )->willReturn ([]);
231
+ public function testExecuteWithException ()
232
+ {
233
+ $ this ->request ->expects ($ this ->once ())
234
+ ->method ('getPost ' )
235
+ ->willReturn (null );
236
+ $ this ->form ->expects ($ this ->once ())
237
+ ->method ('setInvisibleIgnored ' );
238
+ $ this ->form ->expects ($ this ->atLeastOnce ())
239
+ ->method ('extractData ' )
240
+ ->willReturn ([]);
292
241
293
- $ this ->dataObjectHelper = $ this ->getMock ( ' Magento\Framework\Api\DataObjectHelper ' , [], [], '' , false );
294
- $ this -> dataObjectHelper -> expects ( $ this -> once ())-> method ('populateWithArray ' );
242
+ $ this ->form -> expects ( $ this ->never ())
243
+ -> method ('validateData ' );
295
244
296
- $ this ->customerAccountManagement = $ this ->getMockForAbstractClass (
297
- 'Magento\Customer\Api\AccountManagementInterface ' ,
298
- [],
299
- '' ,
300
- false ,
301
- true ,
302
- true
303
- );
245
+ $ this ->extensibleDataObjectConverter ->expects ($ this ->once ())
246
+ ->method ('toFlatArray ' )
247
+ ->willReturn ([]);
304
248
305
249
$ validationResult = $ this ->getMockForAbstractClass (
306
250
'Magento\Customer\Api\Data\ValidationResultsInterface ' ,
@@ -311,42 +255,22 @@ public function testExecuteWithException()
311
255
true
312
256
);
313
257
$ error = $ this ->getMock ('Magento\Framework\Message\Error ' , [], [], '' , false );
314
- $ error ->expects ($ this ->once ())->method ('getText ' )->willReturn ('Error text ' );
258
+ $ error ->expects ($ this ->once ())
259
+ ->method ('getText ' )
260
+ ->willReturn ('Error text ' );
315
261
316
262
$ exception = $ this ->getMock ('Magento\Framework\Validator\Exception ' , [], [], '' , false );
317
- $ exception ->expects ($ this ->once ())->method ('getMessages ' )->willReturn ([$ error ]);
318
- $ validationResult ->expects ($ this ->once ())->method ('getMessages ' )->willThrowException ($ exception );
319
-
320
- $ this ->customerAccountManagement ->expects ($ this ->once ())->method ('validate ' )->willReturn ($ validationResult );
321
-
322
- $ this ->resultJson = $ this ->getMock ('Magento\Framework\Controller\Result\Json ' , [], [], '' , false );
323
- $ this ->resultJson ->expects ($ this ->once ())->method ('setData ' );
324
- $ this ->resultJsonFactory = $ this ->getMock (
325
- 'Magento\Framework\Controller\Result\JsonFactory ' ,
326
- ['create ' ],
327
- [],
328
- '' ,
329
- false
330
- );
331
- $ this ->resultJsonFactory ->expects ($ this ->once ())->method ('create ' )->willReturn ($ this ->resultJson );
332
- $ this ->getController ()->execute ();
333
- }
334
-
335
- public function getController ()
336
- {
337
- $ objectHelper = new \Magento \Framework \TestFramework \Unit \Helper \ObjectManager ($ this );
338
- return $ objectHelper ->getObject (
339
- 'Magento\Customer\Controller\Adminhtml\Index\Validate ' ,
340
- [
341
- 'request ' => $ this ->request ,
342
- 'response ' => $ this ->response ,
343
- 'customerDataFactory ' => $ this ->customerDataFactory ,
344
- 'formFactory ' => $ this ->formFactory ,
345
- 'extensibleDataObjectConverter ' => $ this ->extensibleDataObjectConverter ,
346
- 'customerAccountManagement ' => $ this ->customerAccountManagement ,
347
- 'resultJsonFactory ' => $ this ->resultJsonFactory ,
348
- 'dataObjectHelper ' => $ this ->dataObjectHelper ,
349
- ]
350
- );
263
+ $ exception ->expects ($ this ->once ())
264
+ ->method ('getMessages ' )
265
+ ->willReturn ([$ error ]);
266
+ $ validationResult ->expects ($ this ->once ())
267
+ ->method ('getMessages ' )
268
+ ->willThrowException ($ exception );
269
+
270
+ $ this ->customerAccountManagement ->expects ($ this ->once ())
271
+ ->method ('validate ' )
272
+ ->willReturn ($ validationResult );
273
+
274
+ $ this ->controller ->execute ();
351
275
}
352
276
}
0 commit comments