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 14
14
use Magento \Framework \Exception \LocalizedException ;
15
15
use Magento \Framework \Json \Helper \Data ;
16
16
use Psr \Log \LoggerInterface ;
17
+ use Magento \Framework \App \Action \HttpPostActionInterface ;
17
18
18
- class UpdateItemQty extends Action
19
+ class UpdateItemQty extends Action implements HttpPostActionInterface
19
20
{
20
21
/**
21
22
* @var Sidebar
@@ -61,12 +62,12 @@ public function __construct(
61
62
}
62
63
63
64
/**
64
- * @return $this
65
+ * @inheritdoc
65
66
*/
66
67
public function execute ()
67
68
{
68
69
$ itemId = (int )$ this ->getRequest ()->getParam ('item_id ' );
69
- $ itemQty = $ this ->getRequest ()->getParam ('item_qty ' ) * 1 ;
70
+ $ itemQty = ( float ) $ this ->getRequest ()->getParam ('item_qty ' ) * 1 ;
70
71
$ itemQty = $ this ->quantityProcessor ->prepareQuantity ($ itemQty );
71
72
72
73
try {
Original file line number Diff line number Diff line change @@ -244,4 +244,47 @@ public function testExecuteWithException(): void
244
244
245
245
$ this ->assertEquals ('json represented ' , $ this ->updateItemQty ->execute ());
246
246
}
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
+ }
247
290
}
You can’t perform that action at this time.
0 commit comments