Skip to content

Commit 21bdc67

Browse files
committed
Cover changes with Unit test
1 parent 860af38 commit 21bdc67

File tree

1 file changed

+119
-0
lines changed

1 file changed

+119
-0
lines changed
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Wishlist\Test\Unit\Controller\Index;
7+
8+
use Magento\Backend\Model\View\Result\Redirect;
9+
use Magento\Framework\App\Action\Context;
10+
use Magento\Framework\App\RequestInterface;
11+
use Magento\Framework\Controller\ResultFactory;
12+
use Magento\Framework\Data\Form\FormKey\Validator;
13+
use Magento\Wishlist\Controller\Index\Update;
14+
use Magento\Wishlist\Controller\WishlistProviderInterface;
15+
use Magento\Wishlist\Model\LocaleQuantityProcessor;
16+
use PHPUnit\Framework\TestCase;
17+
18+
/**
19+
* Test for upate controller wishlist
20+
*/
21+
class UpdateTest extends TestCase
22+
{
23+
/**
24+
* @var Validator $formKeyValidator
25+
*/
26+
private $formKeyValidator;
27+
28+
/**
29+
* @var WishlistProviderInterface $wishlistProvider
30+
*/
31+
private $wishlistProvider;
32+
33+
/**
34+
* @var LocaleQuantityProcessor $quantityProcessor
35+
*/
36+
private $quantityProcessor;
37+
38+
/**
39+
* @var Update $updateController
40+
*/
41+
private $updateController;
42+
43+
/**
44+
* @var $context
45+
*/
46+
private $context;
47+
48+
/**
49+
* @var Redirect $resultRedirect
50+
*/
51+
private $resultRedirect;
52+
53+
/**
54+
* @var ResultFactory $resultFatory
55+
*/
56+
private $resultFactory;
57+
58+
/**
59+
* @var RequestInterface $requestMock
60+
*/
61+
private $requestMock;
62+
63+
/**
64+
* @inheritdoc
65+
*/
66+
protected function setUp()
67+
{
68+
$this->formKeyValidator = $this->createMock(Validator::class);
69+
$this->wishlistProvider = $this->createMock(WishlistProviderInterface::class);
70+
$this->quantityProcessor = $this->createMock(LocaleQuantityProcessor::class);
71+
$this->context = $this->createMock(Context::class);
72+
$this->resultRedirect = $this->createMock(Redirect::class);
73+
$this->resultFactory = $this->createPartialMock(ResultFactory::class, ['create']);
74+
$this->requestMock = $this->getMockBuilder(RequestInterface::class)
75+
->setMethods(['getPostValue'])
76+
->getMockForAbstractClass();
77+
78+
$this->context->expects($this->once())
79+
->method('getResultFactory')
80+
->willReturn($this->resultFactory);
81+
82+
$this->resultFactory->expects($this->any())
83+
->method('create')
84+
->willReturn($this->resultRedirect);
85+
$this->context->expects($this->any())
86+
->method('getRequest')
87+
->willReturn($this->requestMock);
88+
89+
$this->updateController = new Update(
90+
$this->context,
91+
$this->formKeyValidator,
92+
$this->wishlistProvider,
93+
$this->quantityProcessor
94+
);
95+
}
96+
97+
/**
98+
* Test for update method Wishlist controller.
99+
*
100+
* Check if there is not post value result redirect returned.
101+
*
102+
* @return void
103+
*/
104+
public function testUpdate(): void
105+
{
106+
$this->formKeyValidator->expects($this->once())
107+
->method('validate')
108+
->willReturn(true);
109+
110+
$wishlist = $this->createMock(\Magento\Wishlist\Model\Wishlist::class);
111+
$this->wishlistProvider->expects($this->once())
112+
->method('getWishlist')
113+
->willReturn($wishlist);
114+
$this->requestMock->expects($this->once())
115+
->method('getPostValue')
116+
->willReturn(null);
117+
$this->assertEquals($this->resultRedirect, $this->updateController->execute());
118+
}
119+
}

0 commit comments

Comments
 (0)