@@ -60,7 +60,7 @@ class ValidateTest extends \PHPUnit_Framework_TestCase
60
60
/** @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\Controller\Result\Json */
61
61
protected $ resultJson ;
62
62
63
- public function testExecute ()
63
+ public function setUp ()
64
64
{
65
65
$ this ->customer = $ this ->getMockForAbstractClass (
66
66
'Magento\Customer\Api\Data\CustomerInterface ' ,
@@ -70,22 +70,22 @@ public function testExecute()
70
70
true ,
71
71
true
72
72
);
73
- $ this ->customer ->expects ($ this ->once ())
74
- ->method ('getWebsiteId ' )
75
- ->willReturn (2 );
76
-
73
+ $ this ->customer ->expects ($ this ->once ())->method ('getWebsiteId ' )->willReturn (2 );
77
74
$ this ->customerDataFactory = $ this ->getMock (
78
75
'Magento\Customer\Api\Data\CustomerInterfaceFactory ' ,
79
76
['create ' ],
80
77
[],
81
78
'' ,
82
79
false
83
80
);
84
- $ this ->customerDataFactory
85
- ->expects ($ this ->once ())
86
- ->method ('create ' )
87
- ->willReturn ($ this ->customer );
88
-
81
+ $ this ->customerDataFactory ->expects ($ this ->once ())->method ('create ' )->willReturn ($ this ->customer );
82
+ $ this ->form = $ this ->getMock (
83
+ 'Magento\Customer\Model\Metadata\Form ' ,
84
+ [],
85
+ [],
86
+ '' ,
87
+ false
88
+ );
89
89
$ this ->request = $ this ->getMockForAbstractClass (
90
90
'Magento\Framework\App\RequestInterface ' ,
91
91
[],
@@ -95,57 +95,23 @@ public function testExecute()
95
95
true ,
96
96
['getPost ' ]
97
97
);
98
- $ this ->request ->expects ($ this ->once ())
99
- ->method ('getPost ' )
100
- ->willReturn ([
101
- '_template_ ' => null ,
102
- 'address_index ' => null
103
- ]);
104
98
$ this ->response = $ this ->getMockForAbstractClass (
105
99
'Magento\Framework\App\ResponseInterface ' ,
106
100
[],
107
101
'' ,
108
102
false
109
103
);
110
- $ this ->form = $ this ->getMock (
111
- 'Magento\Customer\Model\Metadata\Form ' ,
112
- [],
113
- [],
114
- '' ,
115
- false
116
- );
117
- $ this ->form ->expects ($ this ->once ())
118
- ->method ('setInvisibleIgnored ' );
119
- $ this ->form ->expects ($ this ->atLeastOnce ())
120
- ->method ('extractData ' )
121
- ->willReturn ([]);
122
-
123
- $ error = $ this ->getMock ('Magento\Framework\Message\Error ' , [], [], '' , false );
124
- $ this ->form ->expects ($ this ->once ())
125
- ->method ('validateData ' )
126
- ->willReturn ([$ error ]);
127
-
128
104
$ this ->formFactory = $ this ->getMock ('Magento\Customer\Model\Metadata\FormFactory ' , ['create ' ], [], '' , false );
129
- $ this ->formFactory ->expects ($ this ->atLeastOnce ())
130
- ->method ('create ' )
131
- ->willReturn ($ this ->form );
132
-
105
+ $ this ->formFactory ->expects ($ this ->atLeastOnce ())->method ('create ' )->willReturn ($ this ->form );
133
106
$ this ->extensibleDataObjectConverter = $ this ->getMock (
134
107
'Magento\Framework\Api\ExtensibleDataObjectConverter ' ,
135
108
[],
136
109
[],
137
110
'' ,
138
111
false
139
112
);
140
- $ this ->extensibleDataObjectConverter ->expects ($ this ->once ())
141
- ->method ('toFlatArray ' )
142
- ->willReturn ([]);
143
-
144
113
$ this ->dataObjectHelper = $ this ->getMock ('Magento\Framework\Api\DataObjectHelper ' , [], [], '' , false );
145
- $ this ->dataObjectHelper
146
- ->expects ($ this ->once ())
147
- ->method ('populateWithArray ' );
148
-
114
+ $ this ->dataObjectHelper ->expects ($ this ->once ())->method ('populateWithArray ' );
149
115
$ this ->customerAccountManagement = $ this ->getMockForAbstractClass (
150
116
'Magento\Customer\Api\AccountManagementInterface ' ,
151
117
[],
@@ -154,6 +120,38 @@ public function testExecute()
154
120
true ,
155
121
true
156
122
);
123
+ $ this ->resultJson = $ this ->getMock ('Magento\Framework\Controller\Result\Json ' , [], [], '' , false );
124
+ $ this ->resultJson ->expects ($ this ->once ())->method ('setData ' );
125
+ $ this ->resultJsonFactory = $ this ->getMock (
126
+ 'Magento\Framework\Controller\Result\JsonFactory ' ,
127
+ ['create ' ],
128
+ [],
129
+ '' ,
130
+ false
131
+ );
132
+ $ this ->resultJsonFactory ->expects ($ this ->once ())->method ('create ' )->willReturn ($ this ->resultJson );
133
+ }
134
+
135
+ public function testExecute ()
136
+ {
137
+ $ this ->request ->expects ($ this ->once ())
138
+ ->method ('getPost ' )
139
+ ->willReturn ([
140
+ '_template_ ' => null ,
141
+ 'address_index ' => null
142
+ ]);
143
+
144
+ $ this ->form ->expects ($ this ->once ())->method ('setInvisibleIgnored ' );
145
+ $ this ->form ->expects ($ this ->atLeastOnce ())->method ('extractData ' )->willReturn ([]);
146
+
147
+ $ error = $ this ->getMock ('Magento\Framework\Message\Error ' , [], [], '' , false );
148
+ $ this ->form ->expects ($ this ->once ())
149
+ ->method ('validateData ' )
150
+ ->willReturn ([$ error ]);
151
+
152
+ $ this ->extensibleDataObjectConverter ->expects ($ this ->once ())
153
+ ->method ('toFlatArray ' )
154
+ ->willReturn ([]);
157
155
158
156
$ validationResult = $ this ->getMockForAbstractClass (
159
157
'Magento\Customer\Api\Data\ValidationResultsInterface ' ,
@@ -171,75 +169,14 @@ public function testExecute()
171
169
->method ('validate ' )
172
170
->willReturn ($ validationResult );
173
171
174
- $ this ->resultJson = $ this ->getMock ('Magento\Framework\Controller\Result\Json ' , [], [], '' , false );
175
- $ this ->resultJson ->expects ($ this ->once ())
176
- ->method ('setData ' );
177
- $ this ->resultJsonFactory = $ this ->getMock (
178
- 'Magento\Framework\Controller\Result\JsonFactory ' ,
179
- ['create ' ],
180
- [],
181
- '' ,
182
- false
183
- );
184
- $ this ->resultJsonFactory
185
- ->expects ($ this ->once ())
186
- ->method ('create ' )
187
- ->willReturn ($ this ->resultJson );
188
-
189
172
$ this ->getController ()->execute ();
190
173
}
191
174
192
175
public function testExecuteWithoutAddresses ()
193
176
{
194
- $ this ->customer = $ this ->getMockForAbstractClass (
195
- 'Magento\Customer\Api\Data\CustomerInterface ' ,
196
- [],
197
- '' ,
198
- false ,
199
- true ,
200
- true
201
- );
202
- $ this ->customer ->expects ($ this ->once ())
203
- ->method ('getWebsiteId ' )
204
- ->willReturn (2 );
205
-
206
- $ this ->customerDataFactory = $ this ->getMock (
207
- 'Magento\Customer\Api\Data\CustomerInterfaceFactory ' ,
208
- ['create ' ],
209
- [],
210
- '' ,
211
- false
212
- );
213
- $ this ->customerDataFactory
214
- ->expects ($ this ->once ())
215
- ->method ('create ' )
216
- ->willReturn ($ this ->customer );
217
-
218
- $ this ->request = $ this ->getMockForAbstractClass (
219
- 'Magento\Framework\App\RequestInterface ' ,
220
- [],
221
- '' ,
222
- false ,
223
- true ,
224
- true ,
225
- ['getPost ' ]
226
- );
227
177
$ this ->request ->expects ($ this ->once ())
228
178
->method ('getPost ' )
229
179
->willReturn (null );
230
- $ this ->response = $ this ->getMockForAbstractClass (
231
- 'Magento\Framework\App\ResponseInterface ' ,
232
- [],
233
- '' ,
234
- false
235
- );
236
- $ this ->form = $ this ->getMock (
237
- 'Magento\Customer\Model\Metadata\Form ' ,
238
- [],
239
- [],
240
- '' ,
241
- false
242
- );
243
180
$ this ->form ->expects ($ this ->once ())
244
181
->method ('setInvisibleIgnored ' );
245
182
$ this ->form ->expects ($ this ->atLeastOnce ())
@@ -251,36 +188,10 @@ public function testExecuteWithoutAddresses()
251
188
->method ('validateData ' )
252
189
->willReturn ([$ error ]);
253
190
254
- $ this ->formFactory = $ this ->getMock ('Magento\Customer\Model\Metadata\FormFactory ' , ['create ' ], [], '' , false );
255
- $ this ->formFactory ->expects ($ this ->atLeastOnce ())
256
- ->method ('create ' )
257
- ->willReturn ($ this ->form );
258
-
259
- $ this ->extensibleDataObjectConverter = $ this ->getMock (
260
- 'Magento\Framework\Api\ExtensibleDataObjectConverter ' ,
261
- [],
262
- [],
263
- '' ,
264
- false
265
- );
266
191
$ this ->extensibleDataObjectConverter ->expects ($ this ->once ())
267
192
->method ('toFlatArray ' )
268
193
->willReturn ([]);
269
194
270
- $ this ->dataObjectHelper = $ this ->getMock ('Magento\Framework\Api\DataObjectHelper ' , [], [], '' , false );
271
- $ this ->dataObjectHelper
272
- ->expects ($ this ->once ())
273
- ->method ('populateWithArray ' );
274
-
275
- $ this ->customerAccountManagement = $ this ->getMockForAbstractClass (
276
- 'Magento\Customer\Api\AccountManagementInterface ' ,
277
- [],
278
- '' ,
279
- false ,
280
- true ,
281
- true
282
- );
283
-
284
195
$ validationResult = $ this ->getMockForAbstractClass (
285
196
'Magento\Customer\Api\Data\ValidationResultsInterface ' ,
286
197
[],
@@ -297,75 +208,14 @@ public function testExecuteWithoutAddresses()
297
208
->method ('validate ' )
298
209
->willReturn ($ validationResult );
299
210
300
- $ this ->resultJson = $ this ->getMock ('Magento\Framework\Controller\Result\Json ' , [], [], '' , false );
301
- $ this ->resultJson ->expects ($ this ->once ())
302
- ->method ('setData ' );
303
- $ this ->resultJsonFactory = $ this ->getMock (
304
- 'Magento\Framework\Controller\Result\JsonFactory ' ,
305
- ['create ' ],
306
- [],
307
- '' ,
308
- false
309
- );
310
- $ this ->resultJsonFactory
311
- ->expects ($ this ->once ())
312
- ->method ('create ' )
313
- ->willReturn ($ this ->resultJson );
314
-
315
211
$ this ->getController ()->execute ();
316
212
}
317
213
318
214
public function testExecuteWithException ()
319
215
{
320
- $ this ->customer = $ this ->getMockForAbstractClass (
321
- 'Magento\Customer\Api\Data\CustomerInterface ' ,
322
- [],
323
- '' ,
324
- false ,
325
- true ,
326
- true
327
- );
328
- $ this ->customer ->expects ($ this ->once ())
329
- ->method ('getWebsiteId ' )
330
- ->willReturn (2 );
331
-
332
- $ this ->customerDataFactory = $ this ->getMock (
333
- 'Magento\Customer\Api\Data\CustomerInterfaceFactory ' ,
334
- ['create ' ],
335
- [],
336
- '' ,
337
- false
338
- );
339
- $ this ->customerDataFactory
340
- ->expects ($ this ->once ())
341
- ->method ('create ' )
342
- ->willReturn ($ this ->customer );
343
-
344
- $ this ->request = $ this ->getMockForAbstractClass (
345
- 'Magento\Framework\App\RequestInterface ' ,
346
- [],
347
- '' ,
348
- false ,
349
- true ,
350
- true ,
351
- ['getPost ' ]
352
- );
353
216
$ this ->request ->expects ($ this ->once ())
354
217
->method ('getPost ' )
355
218
->willReturn (null );
356
- $ this ->response = $ this ->getMockForAbstractClass (
357
- 'Magento\Framework\App\ResponseInterface ' ,
358
- [],
359
- '' ,
360
- false
361
- );
362
- $ this ->form = $ this ->getMock (
363
- 'Magento\Customer\Model\Metadata\Form ' ,
364
- [],
365
- [],
366
- '' ,
367
- false
368
- );
369
219
$ this ->form ->expects ($ this ->once ())
370
220
->method ('setInvisibleIgnored ' );
371
221
$ this ->form ->expects ($ this ->atLeastOnce ())
@@ -375,36 +225,10 @@ public function testExecuteWithException()
375
225
$ this ->form ->expects ($ this ->never ())
376
226
->method ('validateData ' );
377
227
378
- $ this ->formFactory = $ this ->getMock ('Magento\Customer\Model\Metadata\FormFactory ' , ['create ' ], [], '' , false );
379
- $ this ->formFactory ->expects ($ this ->atLeastOnce ())
380
- ->method ('create ' )
381
- ->willReturn ($ this ->form );
382
-
383
- $ this ->extensibleDataObjectConverter = $ this ->getMock (
384
- 'Magento\Framework\Api\ExtensibleDataObjectConverter ' ,
385
- [],
386
- [],
387
- '' ,
388
- false
389
- );
390
228
$ this ->extensibleDataObjectConverter ->expects ($ this ->once ())
391
229
->method ('toFlatArray ' )
392
230
->willReturn ([]);
393
231
394
- $ this ->dataObjectHelper = $ this ->getMock ('Magento\Framework\Api\DataObjectHelper ' , [], [], '' , false );
395
- $ this ->dataObjectHelper
396
- ->expects ($ this ->once ())
397
- ->method ('populateWithArray ' );
398
-
399
- $ this ->customerAccountManagement = $ this ->getMockForAbstractClass (
400
- 'Magento\Customer\Api\AccountManagementInterface ' ,
401
- [],
402
- '' ,
403
- false ,
404
- true ,
405
- true
406
- );
407
-
408
232
$ validationResult = $ this ->getMockForAbstractClass (
409
233
'Magento\Customer\Api\Data\ValidationResultsInterface ' ,
410
234
[],
@@ -430,21 +254,6 @@ public function testExecuteWithException()
430
254
->method ('validate ' )
431
255
->willReturn ($ validationResult );
432
256
433
- $ this ->resultJson = $ this ->getMock ('Magento\Framework\Controller\Result\Json ' , [], [], '' , false );
434
- $ this ->resultJson ->expects ($ this ->once ())
435
- ->method ('setData ' );
436
- $ this ->resultJsonFactory = $ this ->getMock (
437
- 'Magento\Framework\Controller\Result\JsonFactory ' ,
438
- ['create ' ],
439
- [],
440
- '' ,
441
- false
442
- );
443
- $ this ->resultJsonFactory
444
- ->expects ($ this ->once ())
445
- ->method ('create ' )
446
- ->willReturn ($ this ->resultJson );
447
-
448
257
$ this ->getController ()->execute ();
449
258
}
450
259
0 commit comments