Skip to content
This repository was archived by the owner on Dec 19, 2019. It is now read-only.

Commit dd42a46

Browse files
committed
Add functional test validating only items from requested cart can be updated
1 parent 37eacee commit dd42a46

File tree

1 file changed

+41
-5
lines changed

1 file changed

+41
-5
lines changed

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

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
namespace Magento\GraphQl\Quote;
99

1010
use Magento\Catalog\Api\ProductRepositoryInterface;
11+
use Magento\Framework\ObjectManagerInterface;
1112
use Magento\Quote\Model\Quote;
1213
use Magento\Quote\Model\QuoteIdToMaskedQuoteIdInterface;
1314
use Magento\Quote\Model\ResourceModel\Quote as QuoteResource;
@@ -19,6 +20,11 @@
1920
*/
2021
class UpdateCartItemsTest extends GraphQlAbstract
2122
{
23+
/**
24+
* @var ObjectManagerInterface
25+
*/
26+
private $objectManager;
27+
2228
/**
2329
* @var QuoteResource
2430
*/
@@ -41,11 +47,11 @@ class UpdateCartItemsTest extends GraphQlAbstract
4147

4248
protected function setUp()
4349
{
44-
$objectManager = Bootstrap::getObjectManager();
45-
$this->quoteResource = $objectManager->create(QuoteResource::class);
46-
$this->quote = $objectManager->create(Quote::class);
47-
$this->quoteIdToMaskedId = $objectManager->get(QuoteIdToMaskedQuoteIdInterface::class);
48-
$this->productRepository = $objectManager->get(ProductRepositoryInterface::class);
50+
$this->objectManager = Bootstrap::getObjectManager();
51+
$this->quoteResource = $this->objectManager->create(QuoteResource::class);
52+
$this->quote = $this->objectManager->create(Quote::class);
53+
$this->quoteIdToMaskedId = $this->objectManager->get(QuoteIdToMaskedQuoteIdInterface::class);
54+
$this->productRepository = $this->objectManager->get(ProductRepositoryInterface::class);
4955
}
5056

5157
/**
@@ -116,6 +122,36 @@ public function testUpdateCartItemNoSuchItemEntity()
116122
$this->graphQlQuery($query);
117123
}
118124

125+
/**
126+
* Test mutation is only able to update quote items belonging to the requested cart
127+
*
128+
* @magentoApiDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php
129+
* @magentoApiDataFixture Magento/Checkout/_files/quote_with_virtual_product_saved.php
130+
* @expectedException \Exception
131+
* @expectedExceptionMessage Could not find cart item with id
132+
*/
133+
public function testUpdateItemFromDifferentQuote()
134+
{
135+
/** @var Quote $secondQuote */
136+
$secondQuote = $this->objectManager->create(Quote::class);
137+
$this->quoteResource->load(
138+
$secondQuote,
139+
'test_order_with_virtual_product_without_address',
140+
'reserved_order_id'
141+
);
142+
$secondQuoteItem = $secondQuote->getItemByProduct($this->productRepository->get('virtual-product'));
143+
144+
$this->quoteResource->load(
145+
$this->quote,
146+
'test_order_with_simple_product_without_address',
147+
'reserved_order_id'
148+
);
149+
$maskedQuoteId = $this->quoteIdToMaskedId->execute((int)$this->quote->getId());
150+
151+
$query = $this->prepareUpdateItemsQuery($maskedQuoteId, $secondQuoteItem->getId(), 4);
152+
$this->graphQlQuery($query);
153+
}
154+
119155
private function prepareUpdateItemsQuery(string $maskedQuoteId, string $itemId, float $qty): string
120156
{
121157
return <<<QUERY

0 commit comments

Comments
 (0)