43 private $resultRedirectFactory;
47 $this->sidebarMock = $this->createMock(\
Magento\Checkout\Model\Sidebar::class);
48 $this->loggerMock = $this->createMock(\Psr\Log\LoggerInterface::class);
49 $this->jsonHelperMock = $this->createMock(\
Magento\Framework\Json\Helper\Data::class);
50 $this->requestMock = $this->createMock(\
Magento\Framework\
App\RequestInterface::class);
51 $this->responseMock = $this->getMockForAbstractClass(
52 \
Magento\Framework\
App\ResponseInterface::class,
60 $this->resultPageFactoryMock = $this->createMock(\
Magento\Framework\View\Result\PageFactory::class);
61 $this->resultRedirectFactory = $this->createPartialMock(
62 \
Magento\Framework\Controller\Result\RedirectFactory::class,
66 $this->objectManagerHelper =
new ObjectManagerHelper($this);
67 $this->removeItem = $this->objectManagerHelper->getObject(
68 \
Magento\Checkout\Controller\Sidebar\RemoveItem::class,
70 'sidebar' => $this->sidebarMock,
71 'logger' => $this->loggerMock,
72 'jsonHelper' => $this->jsonHelperMock,
73 'request' => $this->requestMock,
74 'response' => $this->responseMock,
75 'resultPageFactory' => $this->resultPageFactoryMock,
76 'resultRedirectFactory' => $this->resultRedirectFactory
80 $formKeyValidatorMock = $this->createMock(\
Magento\Framework\Data\Form\FormKey\Validator::class);
81 $this->
setPropertyValue($this->removeItem,
'formKeyValidator', $formKeyValidatorMock);
87 ->expects($this->once())
89 ->with($this->requestMock)
91 $this->requestMock->expects($this->once())
93 ->with(
'item_id',
null)
96 $this->sidebarMock->expects($this->once())
97 ->method(
'checkQuoteItem')
100 $this->sidebarMock->expects($this->once())
101 ->method(
'removeQuoteItem')
104 $this->sidebarMock->expects($this->once())
105 ->method(
'getResponseData')
112 'summary_text' =>
__(
' items'),
118 $this->jsonHelperMock->expects($this->once())
119 ->method(
'jsonEncode')
125 'summary_text' =>
__(
' items'),
130 ->willReturn(
'json encoded');
132 $this->responseMock->expects($this->once())
133 ->method(
'representJson')
134 ->with(
'json encoded')
135 ->willReturn(
'json represented');
137 $this->assertEquals(
'json represented', $this->removeItem->execute());
143 ->expects($this->once())
145 ->with($this->requestMock)
147 $this->requestMock->expects($this->once())
149 ->with(
'item_id',
null)
152 $this->sidebarMock->expects($this->once())
153 ->method(
'checkQuoteItem')
157 $this->sidebarMock->expects($this->once())
158 ->method(
'getResponseData')
159 ->with(
'Error message!')
163 'error_message' =>
'Error message!',
167 $this->jsonHelperMock->expects($this->once())
168 ->method(
'jsonEncode')
172 'error_message' =>
'Error message!',
175 ->willReturn(
'json encoded');
177 $this->responseMock->expects($this->once())
178 ->method(
'representJson')
179 ->with(
'json encoded')
180 ->willReturn(
'json represented');
182 $this->assertEquals(
'json represented', $this->removeItem->execute());
188 ->expects($this->once())
190 ->with($this->requestMock)
192 $this->requestMock->expects($this->once())
194 ->with(
'item_id',
null)
197 $exception = new \Exception(
'Error message!');
199 $this->sidebarMock->expects($this->once())
200 ->method(
'checkQuoteItem')
202 ->willThrowException($exception);
204 $this->loggerMock->expects($this->once())
209 $this->sidebarMock->expects($this->once())
210 ->method(
'getResponseData')
211 ->with(
'Error message!')
215 'error_message' =>
'Error message!',
219 $this->jsonHelperMock->expects($this->once())
220 ->method(
'jsonEncode')
224 'error_message' =>
'Error message!',
227 ->willReturn(
'json encoded');
229 $this->responseMock->expects($this->once())
230 ->method(
'representJson')
231 ->with(
'json encoded')
232 ->willReturn(
'json represented');
234 $this->assertEquals(
'json represented', $this->removeItem->execute());
239 $resultRedirect = $this->createMock(\
Magento\Framework\Controller\Result\Redirect::class);
240 $resultRedirect->expects($this->once())->method(
'setPath')->with(
'*/cart/')->willReturnSelf();
241 $this->resultRedirectFactory->expects($this->once())->method(
'create')->willReturn($resultRedirect);
243 ->expects($this->once())
245 ->with($this->requestMock)
247 $this->assertEquals($resultRedirect, $this->removeItem->execute());
260 $reflection = new \ReflectionClass(get_class($object));
261 $reflectionProperty = $reflection->getProperty($property);
262 $reflectionProperty->setAccessible(
true);
264 return $reflectionProperty->getValue($object);
277 $reflection = new \ReflectionClass(get_class($object));
278 $reflectionProperty = $reflection->getProperty($property);
279 $reflectionProperty->setAccessible(
true);
280 $reflectionProperty->setValue($object,
$value);