Skip to content

Commit ba03d89

Browse files
committed
Merge branch 'ACP2E-1513' of https://github.com/magento-l3/magento2ce into PR-2023-02-07
2 parents 548deec + f84b45a commit ba03d89

File tree

2 files changed

+51
-5
lines changed

2 files changed

+51
-5
lines changed

app/code/Magento/QuoteGraphQl/Model/Resolver/RemoveItemFromCart.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value
8686
$itemId = $processedArgs['input']['cart_item_id'];
8787

8888
$storeId = (int)$context->getExtensionAttributes()->getStore()->getId();
89+
/** Check if the current user is allowed to perform actions with the cart */
90+
$this->getCartForUser->execute($maskedCartId, $context->getUserId(), $storeId);
8991

9092
try {
9193
$this->cartItemRepository->deleteById($cartId, $itemId);

dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/RemoveItemFromCartTest.php

Lines changed: 49 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
namespace Magento\GraphQl\Quote\Customer;
99

10+
use Magento\TestFramework\TestCase\GraphQl\ResponseContainsErrorsException;
1011
use Magento\GraphQl\Quote\GetMaskedQuoteIdByReservedOrderId;
1112
use Magento\GraphQl\Quote\GetQuoteItemIdByReservedQuoteIdAndSku;
1213
use Magento\Integration\Api\CustomerTokenServiceInterface;
@@ -147,13 +148,56 @@ public function testRemoveItemFromAnotherCustomerCart()
147148
'test_quote',
148149
'simple_product'
149150
);
151+
$query = $this->getQuery($anotherCustomerQuoteMaskedId, $anotherCustomerQuoteItemId);
150152

151-
$this->expectExceptionMessage(
152-
"The current user cannot perform operations on cart \"$anotherCustomerQuoteMaskedId\""
153-
);
153+
try {
154+
$this->graphQlMutation(
155+
$query,
156+
[],
157+
'',
158+
$this->getHeaderMap('customer2@search.example.com')
159+
);
160+
$this->fail('ResponseContainsErrorsException was not thrown');
161+
} catch (ResponseContainsErrorsException $e) {
162+
$this->assertStringContainsString(
163+
"The current user cannot perform operations on cart \"$anotherCustomerQuoteMaskedId\"",
164+
$e->getMessage()
165+
);
166+
$cartQuery = $this->getCartQuery($anotherCustomerQuoteMaskedId);
167+
$cart = $this->graphQlQuery(
168+
$cartQuery,
169+
[],
170+
'',
171+
$this->getHeaderMap('customer@search.example.com')
172+
);
173+
$this->assertTrue(count($cart['cart']['items']) > 0, 'The cart is empty');
174+
$this->assertTrue(
175+
$cart['cart']['items'][0]['product']['sku'] === 'simple_product',
176+
'The cart doesn\'t contain product'
177+
);
178+
}
179+
}
154180

155-
$query = $this->getQuery($anotherCustomerQuoteMaskedId, $anotherCustomerQuoteItemId);
156-
$this->graphQlMutation($query, [], '', $this->getHeaderMap('customer2@search.example.com'));
181+
/**
182+
* @param string $maskedQuoteId
183+
* @return string
184+
*/
185+
private function getCartQuery(string $maskedQuoteId): string
186+
{
187+
return <<<QUERY
188+
{
189+
cart(cart_id: "{$maskedQuoteId}") {
190+
id
191+
items {
192+
id
193+
quantity
194+
product {
195+
sku
196+
}
197+
}
198+
}
199+
}
200+
QUERY;
157201
}
158202

159203
/**

0 commit comments

Comments
 (0)