Skip to content

Commit be26487

Browse files
committed
Add test updating bundle cart item quantity
1 parent ff59f00 commit be26487

File tree

3 files changed

+71
-2
lines changed

3 files changed

+71
-2
lines changed

dev/tests/api-functional/testsuite/Magento/GraphQl/Bundle/AddBundleProductToCartTest.php

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,67 @@ public function testAddBundleProductToCart()
144144
$this->assertEquals(1, $value['quantity']);
145145
}
146146

147+
/**
148+
* @magentoApiDataFixture Magento/Bundle/_files/quote_with_bundle_and_options.php
149+
* @dataProvider dataProviderTestUpdateBundleItemQuantity
150+
*/
151+
public function testUpdateBundleItemQuantity(int $quantity)
152+
{
153+
$this->quoteResource->load(
154+
$this->quote,
155+
'test_cart_with_bundle_and_options',
156+
'reserved_order_id'
157+
);
158+
159+
$item = current($this->quote->getAllVisibleItems());
160+
161+
$maskedQuoteId = $this->quoteIdToMaskedId->execute((int)$this->quote->getId());
162+
$mutation = <<<QUERY
163+
mutation {
164+
updateCartItems(
165+
input: {
166+
cart_id: "{$maskedQuoteId}"
167+
cart_items: {
168+
cart_item_id: {$item->getId()}
169+
quantity: {$quantity}
170+
}
171+
}
172+
) {
173+
cart {
174+
items {
175+
id
176+
quantity
177+
product {
178+
sku
179+
}
180+
}
181+
}
182+
}
183+
}
184+
QUERY;
185+
186+
$response = $this->graphQlMutation($mutation);
187+
188+
$this->assertArrayHasKey('updateCartItems', $response);
189+
$this->assertArrayHasKey('cart', $response['updateCartItems']);
190+
$cart = $response['updateCartItems']['cart'];
191+
if ($quantity === 0) {
192+
$this->assertCount(0, $cart['items']);
193+
return;
194+
}
195+
196+
$bundleItem = current($cart['items']);
197+
$this->assertEquals($quantity, $bundleItem['quantity']);
198+
}
199+
200+
public function dataProviderTestUpdateBundleItemQuantity(): array
201+
{
202+
return [
203+
[2],
204+
[0],
205+
];
206+
}
207+
147208
/**
148209
* @magentoApiDataFixture Magento/Bundle/_files/product_1.php
149210
* @magentoApiDataFixture Magento/Checkout/_files/active_quote.php

dev/tests/integration/testsuite/Magento/Bundle/_files/quote_with_bundle_and_options.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
use Magento\TestFramework\Helper\Bootstrap;
1010

11-
require __DIR__ . 'product_with_multiple_options.php';
11+
require __DIR__ . '/product_with_multiple_options.php';
1212

1313
$objectManager = Bootstrap::getObjectManager();
1414

@@ -49,6 +49,14 @@
4949
$cart->getQuote()->setReservedOrderId('test_cart_with_bundle_and_options');
5050
$cart->save();
5151

52+
/** @var \Magento\Quote\Model\QuoteIdMask $quoteIdMask */
53+
$quoteIdMask = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
54+
->create(\Magento\Quote\Model\QuoteIdMaskFactory::class)
55+
->create();
56+
$quoteIdMask->setQuoteId($cart->getQuote()->getId());
57+
$quoteIdMask->setDataChanges(true);
58+
$quoteIdMask->save();
59+
5260
/** @var $objectManager \Magento\TestFramework\ObjectManager */
5361
$objectManager = Bootstrap::getObjectManager();
5462
$objectManager->removeSharedInstance(\Magento\Checkout\Model\Session::class);

dev/tests/integration/testsuite/Magento/Bundle/_files/quote_with_bundle_and_options_rollback.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
$quoteIdMask = $objectManager->create(\Magento\Quote\Model\QuoteIdMask::class);
2323
$quoteIdMask->delete($quote->getId());
2424

25-
require __DIR__ . 'product_with_multiple_options_rollback.php';
25+
require __DIR__ . '/product_with_multiple_options_rollback.php';
2626

2727
$registry->unregister('isSecureArea');
2828
$registry->register('isSecureArea', false);

0 commit comments

Comments
 (0)