|
9 | 9 |
|
10 | 10 | use Magento\Catalog\Api\ProductRepositoryInterface;
|
11 | 11 | use Magento\Integration\Api\CustomerTokenServiceInterface;
|
12 |
| -use Magento\Quote\Api\Data\CartInterface; |
| 12 | +use Magento\Framework\ObjectManagerInterface; |
13 | 13 | use Magento\Quote\Api\GuestCartRepositoryInterface;
|
14 | 14 | use Magento\Quote\Model\Quote;
|
15 | 15 | use Magento\Quote\Model\QuoteIdToMaskedQuoteIdInterface;
|
|
23 | 23 | */
|
24 | 24 | class RemoveItemFromCartTest extends GraphQlAbstract
|
25 | 25 | {
|
| 26 | + /** |
| 27 | + * @var ObjectManagerInterface |
| 28 | + */ |
| 29 | + private $objectManager; |
| 30 | + |
26 | 31 | /**
|
27 | 32 | * @var QuoteResource
|
28 | 33 | */
|
@@ -50,12 +55,12 @@ class RemoveItemFromCartTest extends GraphQlAbstract
|
50 | 55 |
|
51 | 56 | protected function setUp()
|
52 | 57 | {
|
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); |
59 | 64 | }
|
60 | 65 |
|
61 | 66 | /**
|
@@ -210,6 +215,57 @@ public function testRemoveItemFromCartNoSuchCartItem()
|
210 | 215 | $this->graphQlQuery($query);
|
211 | 216 | }
|
212 | 217 |
|
| 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 | + |
213 | 269 | /**
|
214 | 270 | * @param string $username
|
215 | 271 | * @return array
|
|
0 commit comments