@@ -312,14 +312,16 @@ public function sendNotificationEmailsDataProvider()
312
312
public function testPasswordReminder ()
313
313
{
314
314
$ customerId = 1 ;
315
+ $ customerWebsiteId = 1 ;
315
316
$ customerStoreId = 2 ;
316
317
$ customerEmail = 'email@email.com ' ;
317
318
$ customerData = ['key ' => 'value ' ];
318
319
$ customerName = 'Customer Name ' ;
319
320
$ templateIdentifier = 'Template Identifier ' ;
320
321
$ sender = 'Sender ' ;
321
322
$ senderValues = ['name ' => $ sender , 'email ' => $ sender ];
322
-
323
+ $ storeIds = [1 , 2 ];
324
+
323
325
$ this ->senderResolverMock
324
326
->expects ($ this ->once ())
325
327
->method ('resolve ' )
@@ -328,6 +330,9 @@ public function testPasswordReminder()
328
330
329
331
/** @var CustomerInterface | \PHPUnit_Framework_MockObject_MockObject $customer */
330
332
$ customer = $ this ->createMock (CustomerInterface::class);
333
+ $ customer ->expects ($ this ->any ())
334
+ ->method ('getWebsiteId ' )
335
+ ->willReturn ($ customerWebsiteId );
331
336
$ customer ->expects ($ this ->any ())
332
337
->method ('getStoreId ' )
333
338
->willReturn ($ customerStoreId );
@@ -346,11 +351,16 @@ public function testPasswordReminder()
346
351
->method ('getStore ' )
347
352
->willReturn ($ this ->storeMock );
348
353
349
- $ this -> storeManagerMock -> expects ( $ this ->at ( 1 ))
350
- -> method ( ' getStore ' )
351
- ->with ( $ customerStoreId )
352
- ->willReturn ($ this -> storeMock );
354
+ $ websiteMock = $ this ->createPartialMock (\ Magento \ Store \ Model \Website::class, [ ' getStoreIds ' ]);
355
+ $ websiteMock -> expects ( $ this -> any () )
356
+ ->method ( ' getStoreIds ' )
357
+ ->willReturn ($ storeIds );
353
358
359
+ $ this ->storeManagerMock ->expects ($ this ->any ())
360
+ ->method ('getWebsite ' )
361
+ ->with ($ customerWebsiteId )
362
+ ->willReturn ($ websiteMock );
363
+
354
364
$ this ->customerRegistryMock ->expects ($ this ->once ())
355
365
->method ('retrieveSecureData ' )
356
366
->with ($ customerId )
@@ -396,6 +406,112 @@ public function testPasswordReminder()
396
406
$ this ->model ->passwordReminder ($ customer );
397
407
}
398
408
409
+ /**
410
+ * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
411
+ */
412
+ public function testPasswordReminderCustomerWithoutStoreId ()
413
+ {
414
+ $ customerId = 1 ;
415
+ $ customerWebsiteId = 1 ;
416
+ $ customerStoreId = null ;
417
+ $ customerEmail = 'email@email.com ' ;
418
+ $ customerData = ['key ' => 'value ' ];
419
+ $ customerName = 'Customer Name ' ;
420
+ $ templateIdentifier = 'Template Identifier ' ;
421
+ $ sender = 'Sender ' ;
422
+ $ senderValues = ['name ' => $ sender , 'email ' => $ sender ];
423
+ $ storeIds = [1 , 2 ];
424
+ $ defaultStoreId = reset ($ storeIds );
425
+
426
+ $ this ->senderResolverMock
427
+ ->expects ($ this ->once ())
428
+ ->method ('resolve ' )
429
+ ->with ($ sender , $ defaultStoreId )
430
+ ->willReturn ($ senderValues );
431
+
432
+ /** @var CustomerInterface | \PHPUnit_Framework_MockObject_MockObject $customer */
433
+ $ customer = $ this ->createMock (CustomerInterface::class);
434
+ $ customer ->expects ($ this ->any ())
435
+ ->method ('getWebsiteId ' )
436
+ ->willReturn ($ customerWebsiteId );
437
+ $ customer ->expects ($ this ->any ())
438
+ ->method ('getStoreId ' )
439
+ ->willReturn ($ customerStoreId );
440
+ $ customer ->expects ($ this ->any ())
441
+ ->method ('getId ' )
442
+ ->willReturn ($ customerId );
443
+ $ customer ->expects ($ this ->any ())
444
+ ->method ('getEmail ' )
445
+ ->willReturn ($ customerEmail );
446
+
447
+ $ this ->storeMock ->expects ($ this ->any ())
448
+ ->method ('getId ' )
449
+ ->willReturn ($ defaultStoreId );
450
+
451
+ $ this ->storeManagerMock ->expects ($ this ->at (0 ))
452
+ ->method ('getStore ' )
453
+ ->willReturn ($ this ->storeMock );
454
+
455
+ $ this ->storeManagerMock ->expects ($ this ->at (1 ))
456
+ ->method ('getStore ' )
457
+ ->with ($ defaultStoreId )
458
+ ->willReturn ($ this ->storeMock );
459
+
460
+ $ websiteMock = $ this ->createPartialMock (\Magento \Store \Model \Website::class, ['getStoreIds ' ]);
461
+ $ websiteMock ->expects ($ this ->any ())
462
+ ->method ('getStoreIds ' )
463
+ ->willReturn ($ storeIds );
464
+
465
+ $ this ->storeManagerMock ->expects ($ this ->any ())
466
+ ->method ('getWebsite ' )
467
+ ->with ($ customerWebsiteId )
468
+ ->willReturn ($ websiteMock );
469
+
470
+ $ this ->customerRegistryMock ->expects ($ this ->once ())
471
+ ->method ('retrieveSecureData ' )
472
+ ->with ($ customerId )
473
+ ->willReturn ($ this ->customerSecureMock );
474
+
475
+ $ this ->dataProcessorMock ->expects ($ this ->once ())
476
+ ->method ('buildOutputDataArray ' )
477
+ ->with ($ customer , CustomerInterface::class)
478
+ ->willReturn ($ customerData );
479
+
480
+ $ this ->customerViewHelperMock ->expects ($ this ->any ())
481
+ ->method ('getCustomerName ' )
482
+ ->with ($ customer )
483
+ ->willReturn ($ customerName );
484
+
485
+ $ this ->customerSecureMock ->expects ($ this ->once ())
486
+ ->method ('addData ' )
487
+ ->with ($ customerData )
488
+ ->willReturnSelf ();
489
+ $ this ->customerSecureMock ->expects ($ this ->once ())
490
+ ->method ('setData ' )
491
+ ->with ('name ' , $ customerName )
492
+ ->willReturnSelf ();
493
+
494
+ $ this ->scopeConfigMock ->expects ($ this ->at (0 ))
495
+ ->method ('getValue ' )
496
+ ->with (EmailNotification::XML_PATH_REMIND_EMAIL_TEMPLATE , ScopeInterface::SCOPE_STORE , $ defaultStoreId )
497
+ ->willReturn ($ templateIdentifier );
498
+ $ this ->scopeConfigMock ->expects ($ this ->at (1 ))
499
+ ->method ('getValue ' )
500
+ ->with (EmailNotification::XML_PATH_FORGOT_EMAIL_IDENTITY , ScopeInterface::SCOPE_STORE , $ defaultStoreId )
501
+ ->willReturn ($ sender );
502
+
503
+ $ this ->mockDefaultTransportBuilder (
504
+ $ templateIdentifier ,
505
+ $ defaultStoreId ,
506
+ $ senderValues ,
507
+ $ customerEmail ,
508
+ $ customerName ,
509
+ ['customer ' => $ this ->customerSecureMock , 'store ' => $ this ->storeMock ]
510
+ );
511
+
512
+ $ this ->model ->passwordReminder ($ customer );
513
+ }
514
+
399
515
/**
400
516
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
401
517
*/
0 commit comments