Skip to content

Commit beec4a4

Browse files
committed
Functional test validating only items from requested cart can be removed
1 parent 75573a9 commit beec4a4

File tree

1 file changed

+63
-7
lines changed

1 file changed

+63
-7
lines changed

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

Lines changed: 63 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
use Magento\Catalog\Api\ProductRepositoryInterface;
1111
use Magento\Integration\Api\CustomerTokenServiceInterface;
12-
use Magento\Quote\Api\Data\CartInterface;
12+
use Magento\Framework\ObjectManagerInterface;
1313
use Magento\Quote\Api\GuestCartRepositoryInterface;
1414
use Magento\Quote\Model\Quote;
1515
use Magento\Quote\Model\QuoteIdToMaskedQuoteIdInterface;
@@ -23,6 +23,11 @@
2323
*/
2424
class RemoveItemFromCartTest extends GraphQlAbstract
2525
{
26+
/**
27+
* @var ObjectManagerInterface
28+
*/
29+
private $objectManager;
30+
2631
/**
2732
* @var QuoteResource
2833
*/
@@ -50,12 +55,12 @@ class RemoveItemFromCartTest extends GraphQlAbstract
5055

5156
protected function setUp()
5257
{
53-
$objectManager = Bootstrap::getObjectManager();
54-
$this->quoteResource = $objectManager->create(QuoteResource::class);
55-
$this->quote = $objectManager->create(Quote::class);
56-
$this->quoteIdToMaskedId = $objectManager->create(QuoteIdToMaskedQuoteIdInterface::class);
57-
$this->productRepository = $objectManager->create(ProductRepositoryInterface::class);
58-
$this->guestCartRepository = $objectManager->create(GuestCartRepositoryInterface::class);
58+
$this->objectManager = Bootstrap::getObjectManager();
59+
$this->quoteResource = $this->objectManager->create(QuoteResource::class);
60+
$this->quote = $this->objectManager->create(Quote::class);
61+
$this->quoteIdToMaskedId = $this->objectManager->create(QuoteIdToMaskedQuoteIdInterface::class);
62+
$this->productRepository = $this->objectManager->create(ProductRepositoryInterface::class);
63+
$this->guestCartRepository = $this->objectManager->create(GuestCartRepositoryInterface::class);
5964
}
6065

6166
/**
@@ -210,6 +215,57 @@ public function testRemoveItemFromCartNoSuchCartItem()
210215
$this->graphQlQuery($query);
211216
}
212217

218+
/**
219+
* Test mutation is only able to remove quote item belonging to the requested cart
220+
*
221+
* @magentoApiDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php
222+
* @magentoApiDataFixture Magento/Checkout/_files/quote_with_virtual_product_saved.php
223+
* @expectedException \Exception
224+
* @expectedExceptionMessage Could not find cart item with id
225+
*/
226+
public function testRemoveItemFromDifferentQuote()
227+
{
228+
/** @var Quote $secondQuote */
229+
$secondQuote = $this->objectManager->create(Quote::class);
230+
$this->quoteResource->load(
231+
$secondQuote,
232+
'test_order_with_virtual_product_without_address',
233+
'reserved_order_id'
234+
);
235+
$secondQuoteItem = $secondQuote->getItemByProduct($this->productRepository->get('virtual-product'));
236+
237+
$this->quoteResource->load(
238+
$this->quote,
239+
'test_order_with_simple_product_without_address',
240+
'reserved_order_id'
241+
);
242+
$maskedQuoteId = $this->quoteIdToMaskedId->execute((int)$this->quote->getId());
243+
$itemId = $secondQuoteItem->getItemId();
244+
245+
$this->expectExceptionMessage(sprintf('Cart doesn\'t contain the %s item.', $itemId));
246+
247+
$query = <<<QUERY
248+
mutation {
249+
removeItemFromCart(
250+
input: {
251+
cart_id: "$maskedQuoteId"
252+
cart_item_id: "$itemId"
253+
}
254+
) {
255+
cart {
256+
cart_id
257+
items {
258+
id
259+
qty
260+
}
261+
}
262+
}
263+
}
264+
QUERY;
265+
266+
$this->graphQlQuery($query);
267+
}
268+
213269
/**
214270
* @param string $username
215271
* @return array

0 commit comments

Comments
 (0)