@@ -164,8 +164,131 @@ public function testExecute()
164
164
true
165
165
);
166
166
$ validationResult ->expects ($ this ->once ())
167
- ->method ('isValid ' )
168
- ->willReturn (false );
167
+ ->method ('getMessages ' )
168
+ ->willReturn (['Error message ' ]);
169
+
170
+ $ this ->customerAccountManagement ->expects ($ this ->once ())
171
+ ->method ('validate ' )
172
+ ->willReturn ($ validationResult );
173
+
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
+ $ this ->getController ()->execute ();
190
+ }
191
+
192
+ public function testExecuteWithoutAddresses ()
193
+ {
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
+ $ this ->request ->expects ($ this ->once ())
228
+ ->method ('getPost ' )
229
+ ->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
+ $ this ->form ->expects ($ this ->once ())
244
+ ->method ('setInvisibleIgnored ' );
245
+ $ this ->form ->expects ($ this ->atLeastOnce ())
246
+ ->method ('extractData ' )
247
+ ->willReturn ([]);
248
+
249
+ $ error = $ this ->getMock ('Magento\Framework\Message\Error ' , [], [], '' , false );
250
+ $ this ->form ->expects ($ this ->never ())
251
+ ->method ('validateData ' )
252
+ ->willReturn ([$ error ]);
253
+
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
+ $ this ->extensibleDataObjectConverter ->expects ($ this ->once ())
267
+ ->method ('toFlatArray ' )
268
+ ->willReturn ([]);
269
+
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
+ $ validationResult = $ this ->getMockForAbstractClass (
285
+ 'Magento\Customer\Api\Data\ValidationResultsInterface ' ,
286
+ [],
287
+ '' ,
288
+ false ,
289
+ true ,
290
+ true
291
+ );
169
292
$ validationResult ->expects ($ this ->once ())
170
293
->method ('getMessages ' )
171
294
->willReturn (['Error message ' ]);
@@ -192,6 +315,139 @@ public function testExecute()
192
315
$ this ->getController ()->execute ();
193
316
}
194
317
318
+ public function testExecuteWithException ()
319
+ {
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
+ $ this ->request ->expects ($ this ->once ())
354
+ ->method ('getPost ' )
355
+ ->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
+ $ this ->form ->expects ($ this ->once ())
370
+ ->method ('setInvisibleIgnored ' );
371
+ $ this ->form ->expects ($ this ->atLeastOnce ())
372
+ ->method ('extractData ' )
373
+ ->willReturn ([]);
374
+
375
+ $ this ->form ->expects ($ this ->never ())
376
+ ->method ('validateData ' );
377
+
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
+ $ this ->extensibleDataObjectConverter ->expects ($ this ->once ())
391
+ ->method ('toFlatArray ' )
392
+ ->willReturn ([]);
393
+
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
+ $ validationResult = $ this ->getMockForAbstractClass (
409
+ 'Magento\Customer\Api\Data\ValidationResultsInterface ' ,
410
+ [],
411
+ '' ,
412
+ false ,
413
+ true ,
414
+ true
415
+ );
416
+ $ error = $ this ->getMock ('Magento\Framework\Message\Error ' , [], [], '' , false );
417
+ $ error ->expects ($ this ->once ())
418
+ ->method ('getText ' )
419
+ ->willReturn ('Error text ' );
420
+
421
+ $ exception = $ this ->getMock ('Magento\Framework\Validator\Exception ' , [], [], '' , false );
422
+ $ exception ->expects ($ this ->once ())
423
+ ->method ('getMessages ' )
424
+ ->willReturn ([$ error ]);
425
+ $ validationResult ->expects ($ this ->once ())
426
+ ->method ('getMessages ' )
427
+ ->willThrowException ($ exception );
428
+
429
+ $ this ->customerAccountManagement ->expects ($ this ->once ())
430
+ ->method ('validate ' )
431
+ ->willReturn ($ validationResult );
432
+
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
+ $ this ->getController ()->execute ();
449
+ }
450
+
195
451
public function getController ()
196
452
{
197
453
$ objectHelper = new \Magento \Framework \TestFramework \Unit \Helper \ObjectManager ($ this );
0 commit comments