Skip to content

Commit f4b5d22

Browse files
author
Sergey Semenov
committed
MAGETWO-36224: Success message is absent while adding product with options from wishlist to shopping cart
1 parent 10382ac commit f4b5d22

File tree

2 files changed

+34
-5
lines changed

2 files changed

+34
-5
lines changed

app/code/Magento/Wishlist/Controller/Index/Cart.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,10 @@ class Cart extends Action\Action implements IndexInterface
7676
* @param \Magento\Catalog\Helper\Product $productHelper
7777
* @param \Magento\Framework\Escaper $escaper
7878
* @param \Magento\Wishlist\Helper\Data $helper
79+
* @param \Magento\Checkout\Helper\Cart $cartHelper
80+
* @param \Magento\Framework\Json\Helper\Data $jsonHelper
81+
*
82+
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
7983
*/
8084
public function __construct(
8185
Action\Context $context,

app/code/Magento/Wishlist/Test/Unit/Controller/Index/CartTest.php

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ protected function setUp()
154154

155155
$this->responseMock = $this->getMockBuilder('Magento\Framework\App\ResponseInterface')
156156
->disableOriginalConstructor()
157-
->setMethods(['setRedirect'])
157+
->setMethods(['setRedirect', 'representJson'])
158158
->getMockForAbstractClass();
159159

160160
$this->redirectMock = $this->getMockBuilder('Magento\Framework\App\Response\RedirectInterface')
@@ -295,9 +295,13 @@ public function testExecuteWithNoWishlist()
295295
}
296296

297297
/**
298+
* @param bool $isAjax
299+
*
300+
* @dataProvider dataProviderExecuteWithQuantityArray
301+
*
298302
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
299303
*/
300-
public function testExecuteWithQuantityArray()
304+
public function testExecuteWithQuantityArray($isAjax)
301305
{
302306
$itemId = 2;
303307
$wishlistId = 1;
@@ -419,7 +423,7 @@ public function testExecuteWithQuantityArray()
419423
->willReturn($params);
420424
$this->requestMock->expects($this->once())
421425
->method('isAjax')
422-
->willReturn(false);
426+
->willReturn($isAjax);
423427

424428
$buyRequestMock = $this->getMockBuilder('Magento\Framework\Object')
425429
->disableOriginalConstructor()
@@ -502,12 +506,33 @@ public function testExecuteWithQuantityArray()
502506
->method('calculate')
503507
->willReturnSelf();
504508

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())
506515
->method('setRedirect')
507516
->with($refererUrl)
508517
->willReturn($this->responseMock);
518+
$this->responseMock->expects($this->any())
519+
->method('representJson')
520+
->with('{"backUrl":"' . $refererUrl . '"}')
521+
->willReturnSelf();
509522

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+
];
511536
}
512537

513538
/**

0 commit comments

Comments
 (0)