File tree Expand file tree Collapse file tree 2 files changed +47
-3
lines changed
app/code/Magento/Checkout Expand file tree Collapse file tree 2 files changed +47
-3
lines changed Original file line number Diff line number Diff line change 1414use Magento \Framework \Exception \LocalizedException ;
1515use Magento \Framework \Json \Helper \Data ;
1616use Psr \Log \LoggerInterface ;
17+ use Magento \Framework \App \Action \HttpPostActionInterface ;
1718
18- class UpdateItemQty extends Action
19+ class UpdateItemQty extends Action implements HttpPostActionInterface
1920{
2021 /**
2122 * @var Sidebar
@@ -61,12 +62,12 @@ public function __construct(
6162 }
6263
6364 /**
64- * @return $this
65+ * @inheritdoc
6566 */
6667 public function execute ()
6768 {
6869 $ itemId = (int )$ this ->getRequest ()->getParam ('item_id ' );
69- $ itemQty = $ this ->getRequest ()->getParam ('item_qty ' ) * 1 ;
70+ $ itemQty = ( float ) $ this ->getRequest ()->getParam ('item_qty ' ) * 1 ;
7071 $ itemQty = $ this ->quantityProcessor ->prepareQuantity ($ itemQty );
7172
7273 try {
Original file line number Diff line number Diff line change @@ -244,4 +244,47 @@ public function testExecuteWithException(): void
244244
245245 $ this ->assertEquals ('json represented ' , $ this ->updateItemQty ->execute ());
246246 }
247+
248+ /**
249+ * @return void
250+ */
251+ public function testExecuteWithWrongRequestParams (): void
252+ {
253+ $ this ->requestMock
254+ ->method ('getParam ' )
255+ ->withConsecutive (['item_id ' ], ['item_qty ' ])
256+ ->willReturnOnConsecutiveCalls (0 , 'error ' );
257+
258+ $ this ->sidebarMock ->expects ($ this ->once ())
259+ ->method ('checkQuoteItem ' )
260+ ->with (0 )
261+ ->willThrowException (new LocalizedException (__ ('Error! ' )));
262+
263+ $ this ->sidebarMock ->expects ($ this ->once ())
264+ ->method ('getResponseData ' )
265+ ->with ('Error! ' )
266+ ->willReturn (
267+ [
268+ 'success ' => false ,
269+ 'error_message ' => 'Error! '
270+ ]
271+ );
272+
273+ $ this ->jsonHelperMock ->expects ($ this ->once ())
274+ ->method ('jsonEncode ' )
275+ ->with (
276+ [
277+ 'success ' => false ,
278+ 'error_message ' => 'Error! '
279+ ]
280+ )
281+ ->willReturn ('json encoded ' );
282+
283+ $ this ->responseMock ->expects ($ this ->once ())
284+ ->method ('representJson ' )
285+ ->with ('json encoded ' )
286+ ->willReturn ('json represented ' );
287+
288+ $ this ->assertEquals ('json represented ' , $ this ->updateItemQty ->execute ());
289+ }
247290}
You can’t perform that action at this time.
0 commit comments