public function testUpdateQuoteItemWithZeroQty() { $itemId = 1; $itemQty = 0; $this->resolverMock->expects($this->never())->method('getLocale'); $this->cartMock->expects($this->once())->method('updateItems')->with([$itemId => ['qty' => $itemQty]])->willReturnSelf(); $this->cartMock->expects($this->once())->method('save')->willReturnSelf(); $this->assertEquals($this->sidebar, $this->sidebar->updateQuoteItem($itemId, $itemQty)); }
/** * Compile JSON response * * @param string $error * @return Http */ protected function jsonResponse($error = '') { $response = $this->sidebar->getResponseData($error); if (empty($error)) { $resultPage = $this->resultPageFactory->create(); $block = $resultPage->getLayout()->getBlock('minicart.content')->toHtml(); $response['content'] = $block; } return $this->getResponse()->representJson($this->jsonHelper->jsonEncode($response)); }
public function testExecuteWithException() { $this->requestMock->expects($this->once())->method('getParam')->with('item_id', null)->willReturn('1'); $exception = new \Exception('Error message!'); $this->sidebarMock->expects($this->once())->method('checkQuoteItem')->with(1)->willThrowException($exception); $this->loggerMock->expects($this->once())->method('critical')->with($exception)->willReturn(null); $this->sidebarMock->expects($this->once())->method('getResponseData')->with('Error message!')->willReturn(['success' => false, 'error_message' => 'Error message!']); $this->jsonHelperMock->expects($this->once())->method('jsonEncode')->with(['success' => false, 'error_message' => 'Error message!'])->willReturn('json encoded'); $this->responseMock->expects($this->once())->method('representJson')->with('json encoded')->willReturn('json represented'); $this->assertEquals('json represented', $this->removeItem->executeInternal()); }
/** * Compile JSON response * * @param string $error * @return Http */ protected function jsonResponse($error = '') { $response = $this->sidebar->getResponseData($error); return $this->getResponse()->representJson($this->jsonHelper->jsonEncode($response)); }