8
8
namespace Magento \GraphQl \Quote ;
9
9
10
10
use Magento \Catalog \Api \ProductRepositoryInterface ;
11
+ use Magento \Framework \ObjectManagerInterface ;
11
12
use Magento \Quote \Model \Quote ;
12
13
use Magento \Quote \Model \QuoteIdToMaskedQuoteIdInterface ;
13
14
use Magento \Quote \Model \ResourceModel \Quote as QuoteResource ;
19
20
*/
20
21
class UpdateCartItemsTest extends GraphQlAbstract
21
22
{
23
+ /**
24
+ * @var ObjectManagerInterface
25
+ */
26
+ private $ objectManager ;
27
+
22
28
/**
23
29
* @var QuoteResource
24
30
*/
@@ -41,11 +47,11 @@ class UpdateCartItemsTest extends GraphQlAbstract
41
47
42
48
protected function setUp ()
43
49
{
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);
49
55
}
50
56
51
57
/**
@@ -116,6 +122,36 @@ public function testUpdateCartItemNoSuchItemEntity()
116
122
$ this ->graphQlQuery ($ query );
117
123
}
118
124
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
+
119
155
private function prepareUpdateItemsQuery (string $ maskedQuoteId , string $ itemId , float $ qty ): string
120
156
{
121
157
return <<<QUERY
0 commit comments