Skip to content

Commit a201f17

Browse files
authored
Merge pull request #5318 from magento-tsg/2.3.5-develop-pr98
[TSG] Fixes for 2.3 (pr98) (2.3.5-develop)
2 parents 998d5a2 + ee22a3b commit a201f17

File tree

3 files changed

+59
-2
lines changed

3 files changed

+59
-2
lines changed

app/code/Magento/Checkout/Controller/Sidebar/RemoveItem.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77

88
use Magento\Framework\App\Action\HttpPostActionInterface as HttpPostActionInterface;
99

10+
/**
11+
* Controller for removing quote item from shopping cart.
12+
*/
1013
class RemoveItem extends \Magento\Framework\App\Action\Action implements HttpPostActionInterface
1114
{
1215
/**
@@ -56,7 +59,7 @@ public function __construct(
5659
}
5760

5861
/**
59-
* @return $this
62+
* @inheritdoc
6063
*/
6164
public function execute()
6265
{
@@ -67,11 +70,17 @@ public function execute()
6770
try {
6871
$this->sidebar->checkQuoteItem($itemId);
6972
$this->sidebar->removeQuoteItem($itemId);
73+
7074
return $this->jsonResponse();
7175
} catch (\Magento\Framework\Exception\LocalizedException $e) {
7276
return $this->jsonResponse($e->getMessage());
77+
} catch (\Zend_Db_Exception $e) {
78+
$this->logger->critical($e);
79+
80+
return $this->jsonResponse(__('An unspecified error occurred. Please contact us for assistance.'));
7381
} catch (\Exception $e) {
7482
$this->logger->critical($e);
83+
7584
return $this->jsonResponse($e->getMessage());
7685
}
7786
}
@@ -92,6 +101,8 @@ protected function jsonResponse($error = '')
92101
}
93102

94103
/**
104+
* Return formKey Validator object instance.
105+
*
95106
* @return \Magento\Framework\Data\Form\FormKey\Validator
96107
* @deprecated 100.0.9
97108
*/

app/code/Magento/Checkout/Test/Unit/Controller/Sidebar/RemoveItemTest.php

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,52 @@ public function testExecuteWithException()
234234
$this->assertEquals('json represented', $this->removeItem->execute());
235235
}
236236

237+
/**
238+
* Test controller when DB exception is thrown.
239+
*
240+
* @return void
241+
*/
242+
public function testExecuteWithDbException(): void
243+
{
244+
$itemId = 1;
245+
$dbError = 'Error';
246+
$message = __('An unspecified error occurred. Please contact us for assistance.');
247+
$response = [
248+
'success' => false,
249+
'error_message' => $message,
250+
];
251+
252+
$this->getPropertyValue($this->removeItem, 'formKeyValidator')
253+
->expects($this->once())
254+
->method('validate')
255+
->with($this->requestMock)
256+
->willReturn(true);
257+
$this->requestMock->expects($this->once())->method('getParam')->with('item_id')->willReturn($itemId);
258+
259+
$exception = new \Zend_Db_Exception($dbError);
260+
261+
$this->sidebarMock->expects($this->once())
262+
->method('checkQuoteItem')
263+
->with($itemId)
264+
->willThrowException($exception);
265+
266+
$this->loggerMock->expects($this->once())->method('critical')->with($exception);
267+
268+
$this->sidebarMock->expects($this->once())->method('getResponseData')->with($message)->willReturn($response);
269+
$encodedResponse = json_encode($response);
270+
$this->jsonHelperMock->expects($this->once())
271+
->method('jsonEncode')
272+
->with($response)
273+
->willReturn($encodedResponse);
274+
275+
$this->responseMock->expects($this->once())
276+
->method('representJson')
277+
->with($encodedResponse)
278+
->willReturn($this->responseMock);
279+
280+
$this->removeItem->execute();
281+
}
282+
237283
public function testExecuteWhenFormKeyValidationFailed()
238284
{
239285
$resultRedirect = $this->createMock(\Magento\Framework\Controller\Result\Redirect::class);

lib/internal/Magento/Framework/Filter/VariableResolver/LegacyResolver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ private function handleObjectMethod(Template $filter, array $templateVariables,
160160
{
161161
$object = $stackArgs[$i - 1]['variable'];
162162
$method = $stackArgs[$i]['name'];
163-
if (method_exists($object, $method)) {
163+
if (method_exists($object, $method) && substr($method, 0, 3) !== 'set') {
164164
$args = $this->getStackArgs($stackArgs[$i]['args'], $filter, $templateVariables);
165165
$stackArgs[$i]['variable'] = call_user_func_array([$object, $method], $args);
166166
}

0 commit comments

Comments
 (0)