@@ -154,7 +154,7 @@ protected function setUp()
154
154
155
155
$ this ->responseMock = $ this ->getMockBuilder ('Magento\Framework\App\ResponseInterface ' )
156
156
->disableOriginalConstructor ()
157
- ->setMethods (['setRedirect ' ])
157
+ ->setMethods (['setRedirect ' , ' representJson ' ])
158
158
->getMockForAbstractClass ();
159
159
160
160
$ this ->redirectMock = $ this ->getMockBuilder ('Magento\Framework\App\Response\RedirectInterface ' )
@@ -295,9 +295,13 @@ public function testExecuteWithNoWishlist()
295
295
}
296
296
297
297
/**
298
+ * @param bool $isAjax
299
+ *
300
+ * @dataProvider dataProviderExecuteWithQuantityArray
301
+ *
298
302
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
299
303
*/
300
- public function testExecuteWithQuantityArray ()
304
+ public function testExecuteWithQuantityArray ($ isAjax )
301
305
{
302
306
$ itemId = 2 ;
303
307
$ wishlistId = 1 ;
@@ -419,7 +423,7 @@ public function testExecuteWithQuantityArray()
419
423
->willReturn ($ params );
420
424
$ this ->requestMock ->expects ($ this ->once ())
421
425
->method ('isAjax ' )
422
- ->willReturn (false );
426
+ ->willReturn ($ isAjax );
423
427
424
428
$ buyRequestMock = $ this ->getMockBuilder ('Magento\Framework\Object ' )
425
429
->disableOriginalConstructor ()
@@ -502,12 +506,33 @@ public function testExecuteWithQuantityArray()
502
506
->method ('calculate ' )
503
507
->willReturnSelf ();
504
508
505
- $ this ->responseMock ->expects ($ this ->once ())
509
+ $ this ->jsonHelperMock ->expects ($ this ->any ())
510
+ ->method ('jsonEncode ' )
511
+ ->with (['backUrl ' => $ refererUrl ])
512
+ ->willReturn ('{"backUrl":" ' . $ refererUrl . '"} ' );
513
+
514
+ $ this ->responseMock ->expects ($ this ->any ())
506
515
->method ('setRedirect ' )
507
516
->with ($ refererUrl )
508
517
->willReturn ($ this ->responseMock );
518
+ $ this ->responseMock ->expects ($ this ->any ())
519
+ ->method ('representJson ' )
520
+ ->with ('{"backUrl":" ' . $ refererUrl . '"} ' )
521
+ ->willReturnSelf ();
509
522
510
- $ this ->assertEquals ($ this ->responseMock , $ this ->model ->execute ());
523
+ $ expectedResult = ($ isAjax ? null : $ this ->responseMock );
524
+ $ this ->assertEquals ($ expectedResult , $ this ->model ->execute ());
525
+ }
526
+
527
+ /**
528
+ * @return array
529
+ */
530
+ public function dataProviderExecuteWithQuantityArray ()
531
+ {
532
+ return [
533
+ ['isAjax ' => false ],
534
+ ['isAjax ' => true ],
535
+ ];
511
536
}
512
537
513
538
/**
0 commit comments