Skip to content

Commit 0f20be6

Browse files
committed
Merge remote-tracking branch 'origin/MAGETWO-35331' into BUGS
2 parents 56703c5 + 7029294 commit 0f20be6

File tree

3 files changed

+415
-125
lines changed

3 files changed

+415
-125
lines changed
Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Wishlist\Test\Unit\Controller\Shared;
8+
9+
class AllcartTest extends \PHPUnit_Framework_TestCase
10+
{
11+
/**
12+
* @var \Magento\Wishlist\Controller\Shared\WishlistProvider|\PHPUnit_Framework_MockObject_MockObject
13+
*/
14+
protected $wishlistProvider;
15+
16+
/**
17+
* @var \Magento\Framework\App\Request\Http|\PHPUnit_Framework_MockObject_MockObject
18+
*/
19+
protected $request;
20+
21+
/**
22+
* @var \Magento\Wishlist\Model\ItemCarrier|\PHPUnit_Framework_MockObject_MockObject
23+
*/
24+
protected $itemCarrier;
25+
26+
/**
27+
* @var \Magento\Framework\App\Response\Http|\PHPUnit_Framework_MockObject_MockObject
28+
*/
29+
protected $response;
30+
31+
/**
32+
* @var \Magento\Framework\App\Action\Context|\PHPUnit_Framework_MockObject_MockObject
33+
*/
34+
protected $context;
35+
36+
protected function setUp()
37+
{
38+
$this->wishlistProvider = $this->getMock(
39+
'\Magento\Wishlist\Controller\Shared\WishlistProvider',
40+
[],
41+
[],
42+
'',
43+
false
44+
);
45+
$this->request = $this->getMock('Magento\Framework\App\Request\Http', [], [], '', false);
46+
$this->itemCarrier = $this->getMock('Magento\Wishlist\Model\ItemCarrier', [], [], '', false);
47+
$this->context = $this->getMock('Magento\Framework\App\Action\Context', [], [], '', false);
48+
$this->response = $this->getMock('Magento\Framework\App\Response\Http', [], [], '', false);
49+
}
50+
51+
protected function prepareContext()
52+
{
53+
$om = $this->getMock('Magento\Framework\App\ObjectManager', [], [], '', false);
54+
$eventManager = $this->getMock('Magento\Framework\Event\Manager', null, [], '', false);
55+
$url = $this->getMock('Magento\Framework\Url', [], [], '', false);
56+
$actionFlag = $this->getMock('Magento\Framework\App\ActionFlag', [], [], '', false);
57+
$redirect = $this->getMock('\Magento\Store\App\Response\Redirect', [], [], '', false);
58+
$view = $this->getMock('Magento\Framework\App\View', [], [], '', false);
59+
$messageManager = $this->getMock('Magento\Framework\Message\Manager', [], [], '', false);
60+
61+
$this->context
62+
->expects($this->any())
63+
->method('getObjectManager')
64+
->will($this->returnValue($om));
65+
$this->context
66+
->expects($this->any())
67+
->method('getRequest')
68+
->will($this->returnValue($this->request));
69+
$this->context
70+
->expects($this->any())
71+
->method('getResponse')
72+
->will($this->returnValue($this->response));
73+
$this->context
74+
->expects($this->any())
75+
->method('getEventManager')
76+
->will($this->returnValue($eventManager));
77+
$this->context
78+
->expects($this->any())
79+
->method('getUrl')
80+
->will($this->returnValue($url));
81+
$this->context
82+
->expects($this->any())
83+
->method('getActionFlag')
84+
->will($this->returnValue($actionFlag));
85+
$this->context
86+
->expects($this->any())
87+
->method('getRedirect')
88+
->will($this->returnValue($redirect));
89+
$this->context
90+
->expects($this->any())
91+
->method('getView')
92+
->will($this->returnValue($view));
93+
$this->context
94+
->expects($this->any())
95+
->method('getMessageManager')
96+
->will($this->returnValue($messageManager));
97+
}
98+
99+
public function getController()
100+
{
101+
$this->prepareContext();
102+
return new \Magento\Wishlist\Controller\Shared\Allcart(
103+
$this->context,
104+
$this->wishlistProvider,
105+
$this->itemCarrier
106+
);
107+
}
108+
109+
public function testExecuteWithNoWishlist()
110+
{
111+
$this->wishlistProvider->expects($this->once())
112+
->method('getWishlist')
113+
->willReturn(false);
114+
115+
$this->request
116+
->expects($this->once())
117+
->method('initForward')
118+
->will($this->returnValue(true));
119+
$this->request
120+
->expects($this->once())
121+
->method('setActionName')
122+
->with('noroute')
123+
->will($this->returnValue(true));
124+
$this->request
125+
->expects($this->once())
126+
->method('setDispatched')
127+
->with(false)
128+
->will($this->returnValue(true));
129+
130+
$controller = $this->getController();
131+
$controller->execute();
132+
}
133+
134+
public function testExecuteWithWishlist()
135+
{
136+
$wishlist = $this->getMockBuilder('Magento\Wishlist\Model\Wishlist')
137+
->disableOriginalConstructor()
138+
->getMock();
139+
$this->wishlistProvider->expects($this->once())
140+
->method('getWishlist')
141+
->willReturn($wishlist);
142+
143+
$this->request
144+
->expects($this->once())
145+
->method('getParam')
146+
->with('qty')
147+
->will($this->returnValue(2));
148+
149+
$this->itemCarrier
150+
->expects($this->once())
151+
->method('moveAllToCart')
152+
->with($wishlist, 2)
153+
->will($this->returnValue('http://redirect-url.com'));
154+
155+
$this->response
156+
->expects($this->once())
157+
->method('setRedirect')
158+
->will($this->returnValue('http://redirect-url.com'));
159+
160+
$controller = $this->getController();
161+
$controller->execute();
162+
}
163+
}

0 commit comments

Comments
 (0)