Skip to content

Commit

Permalink
ENGCOM-7779: Implement ActionInterface for wishlist/shared #27494
Browse files Browse the repository at this point in the history
 - Merge Pull Request #27494 from dxx004/magento2:refactor/wishlist
 - Merged commits:
   1. a4c74d8
   2. 18e7519
   3. a002bf2
   4. df2c759
   5. 3ac458b
   6. 935bdfa
   7. f474439
   8. 2ce3982
   9. 4a85364
   10. 979ab1f
   11. 2f65f66
   12. 6d8f77c
   13. 2616ba1
   14. e2db162
   15. 2f08064
   16. 9a1da8a
   17. 21f9fa4
   18. 26cd80d
   19. c5f6a1f
   20. a7da7fd
  • Loading branch information
magento-engcom-team committed Aug 21, 2020
2 parents 8b7d949 + a7da7fd commit f9ad1c8
Show file tree
Hide file tree
Showing 4 changed files with 137 additions and 154 deletions.
24 changes: 18 additions & 6 deletions app/code/Magento/Wishlist/Controller/Shared/Allcart.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,32 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

declare(strict_types=1);

namespace Magento\Wishlist\Controller\Shared;

use Magento\Framework\App\Action\Action;
use Magento\Framework\App\Action\Context;
use Magento\Wishlist\Model\ItemCarrier;
use Magento\Framework\App\Action\HttpGetActionInterface;
use Magento\Framework\App\Action\HttpPostActionInterface;
use Magento\Framework\Controller\Result\Forward;
use Magento\Framework\Controller\Result\Redirect;
use Magento\Framework\Controller\ResultFactory;
use Magento\Wishlist\Model\ItemCarrier;

class Allcart extends \Magento\Framework\App\Action\Action
/**
* Wishlist Allcart Controller
*/
class Allcart extends Action implements HttpGetActionInterface, HttpPostActionInterface
{
/**
* @var WishlistProvider
*/
protected $wishlistProvider;

/**
* @var \Magento\Wishlist\Model\ItemCarrier
* @var ItemCarrier
*/
protected $itemCarrier;

Expand All @@ -39,21 +50,22 @@ public function __construct(
/**
* Add all items from wishlist to shopping cart
*
* @return \Magento\Framework\Controller\ResultInterface
* {@inheritDoc}
*/
public function execute()
{
$wishlist = $this->wishlistProvider->getWishlist();
if (!$wishlist) {
/** @var \Magento\Framework\Controller\Result\Forward $resultForward */
/** @var Forward $resultForward */
$resultForward = $this->resultFactory->create(ResultFactory::TYPE_FORWARD);
$resultForward->forward('noroute');
return $resultForward;
}
$redirectUrl = $this->itemCarrier->moveAllToCart($wishlist, $this->getRequest()->getParam('qty'));
/** @var \Magento\Framework\Controller\Result\Redirect $resultRedirect */
/** @var Redirect $resultRedirect */
$resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
$resultRedirect->setUrl($redirectUrl);

return $resultRedirect;
}
}
6 changes: 4 additions & 2 deletions app/code/Magento/Wishlist/Controller/Shared/Cart.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
use Magento\Framework\App\Action\Action;
use Magento\Framework\App\Action\Context as ActionContext;
use Magento\Framework\App\Action\HttpPostActionInterface;
use Magento\Framework\Controller\Result\Redirect;
use Magento\Framework\Controller\Result\Redirect as ResultRedirect;
use Magento\Framework\Controller\ResultFactory;
use Magento\Framework\Escaper;
use Magento\Framework\Exception\LocalizedException;
Expand Down Expand Up @@ -124,9 +124,11 @@ public function execute()
} catch (\Exception $e) {
$this->messageManager->addExceptionMessage($e, __('We can\'t add the item to the cart right now.'));
}
/** @var Redirect $resultRedirect */

/** @var ResultRedirect $resultRedirect */
$resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
$resultRedirect->setUrl($redirectUrl);

return $resultRedirect;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

declare(strict_types=1);

namespace Magento\Wishlist\Test\Unit\Controller\Shared;
Expand All @@ -20,83 +21,60 @@
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;

/**
* Test for \Magento\Wishlist\Controller\Shared\Allcart.
*/
class AllcartTest extends TestCase
{
/**
* @var Allcart
*/
protected $allcartController;

/**
* @var \Magento\Framework\TestFramework\Unit\Helper\ObjectManager
*/
protected $objectManagerHelper;

/**
* @var Context
*/
protected $context;
private $allcartController;

/**
* @var WishlistProvider|MockObject
*/
protected $wishlistProviderMock;
private $wishlistProviderMock;

/**
* @var ItemCarrier|MockObject
*/
protected $itemCarrierMock;
private $itemCarrierMock;

/**
* @var Wishlist|MockObject
*/
protected $wishlistMock;
private $wishlistMock;

/**
* @var Http|MockObject
*/
protected $requestMock;

/**
* @var ResultFactory|MockObject
*/
protected $resultFactoryMock;
private $requestMock;

/**
* @var Redirect|MockObject
*/
protected $resultRedirectMock;
private $resultRedirectMock;

/**
* @var Forward|MockObject
*/
protected $resultForwardMock;
private $resultForwardMock;

/**
* @inheritDoc
*/
protected function setUp(): void
{
$this->wishlistProviderMock = $this->getMockBuilder(WishlistProvider::class)
->disableOriginalConstructor()
->getMock();
$this->itemCarrierMock = $this->getMockBuilder(ItemCarrier::class)
->disableOriginalConstructor()
->getMock();
$this->wishlistMock = $this->getMockBuilder(Wishlist::class)
->disableOriginalConstructor()
->getMock();
$this->requestMock = $this->getMockBuilder(Http::class)
->disableOriginalConstructor()
->getMock();
$this->resultFactoryMock = $this->getMockBuilder(ResultFactory::class)
->disableOriginalConstructor()
->getMock();
$this->resultRedirectMock = $this->getMockBuilder(Redirect::class)
->disableOriginalConstructor()
->getMock();
$this->resultForwardMock = $this->getMockBuilder(Forward::class)
->disableOriginalConstructor()
->getMock();

$this->resultFactoryMock->expects($this->any())
$this->wishlistProviderMock = $this->createMock(WishlistProvider::class);
$this->itemCarrierMock = $this->createMock(ItemCarrier::class);
$this->wishlistMock = $this->createMock(Wishlist::class);
$this->requestMock = $this->createMock(Http::class);
$resultFactoryMock = $this->createMock(ResultFactory::class);
$this->resultRedirectMock = $this->createMock(Redirect::class);
$this->resultForwardMock = $this->createMock(Forward::class);

$resultFactoryMock->expects($this->any())
->method('create')
->willReturnMap(
[
Expand All @@ -105,18 +83,18 @@ protected function setUp(): void
]
);

$this->objectManagerHelper = new ObjectManagerHelper($this);
$this->context = $this->objectManagerHelper->getObject(
$objectManagerHelper = new ObjectManagerHelper($this);
$context = $objectManagerHelper->getObject(
Context::class,
[
'request' => $this->requestMock,
'resultFactory' => $this->resultFactoryMock
'resultFactory' => $resultFactoryMock
]
);
$this->allcartController = $this->objectManagerHelper->getObject(
$this->allcartController = $objectManagerHelper->getObject(
Allcart::class,
[
'context' => $this->context,
'context' => $context,
'wishlistProvider' => $this->wishlistProviderMock,
'itemCarrier' => $this->itemCarrierMock
]
Expand Down
Loading

0 comments on commit f9ad1c8

Please sign in to comment.