Skip to content

Commit efb48bb

Browse files
committed
Merge branch 'ACP2E-2607' of https://github.com/adobe-commerce-tier-4/magento2ce into T4-PR-03-18-2024
2 parents 679ca72 + d476ff5 commit efb48bb

File tree

1 file changed

+99
-0
lines changed

1 file changed

+99
-0
lines changed

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

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

88
namespace Magento\GraphQl\Quote\Customer;
99

10+
use Magento\Bundle\Test\Fixture\AddProductToCart as AddBundleProductToCart;
11+
use Magento\Bundle\Test\Fixture\Link as BundleSelectionFixture;
12+
use Magento\Bundle\Test\Fixture\Option as BundleOptionFixture;
13+
use Magento\Bundle\Test\Fixture\Product as BundleProductFixture;
14+
use Magento\Catalog\Test\Fixture\Product as ProductFixture;
15+
use Magento\Customer\Test\Fixture\Customer;
1016
use Magento\Quote\Model\QuoteFactory;
1117
use Magento\Quote\Model\QuoteIdToMaskedQuoteIdInterface;
1218
use Magento\Quote\Model\ResourceModel\Quote as QuoteResource;
19+
use Magento\Quote\Test\Fixture\CustomerCart;
20+
use Magento\Quote\Test\Fixture\GuestCart as GuestCartFixture;
21+
use Magento\TestFramework\Fixture\DataFixture;
22+
use Magento\TestFramework\Fixture\DataFixtureStorage;
23+
use Magento\TestFramework\Fixture\DataFixtureStorageManager;
24+
use Magento\TestFramework\Fixture\DbIsolation;
1325
use Magento\TestFramework\Helper\Bootstrap;
1426
use Magento\TestFramework\TestCase\GraphQlAbstract;
1527
use Magento\Integration\Api\CustomerTokenServiceInterface;
@@ -39,13 +51,31 @@ class MergeCartsTest extends GraphQlAbstract
3951
*/
4052
private $customerTokenService;
4153

54+
/**
55+
* @var DataFixtureStorage
56+
*/
57+
private $fixtures;
58+
59+
/**
60+
* @var \Magento\Quote\Model\QuoteIdMaskFactory
61+
*/
62+
private $quoteIdMaskedFactory;
63+
64+
/**
65+
* @var \Magento\Quote\Model\ResourceModel\Quote\QuoteIdMask
66+
*/
67+
private $quoteIdMaskedResource;
68+
4269
protected function setUp(): void
4370
{
4471
$objectManager = Bootstrap::getObjectManager();
4572
$this->quoteResource = $objectManager->get(QuoteResource::class);
4673
$this->quoteFactory = $objectManager->get(QuoteFactory::class);
4774
$this->quoteIdToMaskedId = $objectManager->get(QuoteIdToMaskedQuoteIdInterface::class);
4875
$this->customerTokenService = $objectManager->get(CustomerTokenServiceInterface::class);
76+
$this->fixtures = DataFixtureStorageManager::getStorage();
77+
$this->quoteIdMaskedFactory = $objectManager->get(\Magento\Quote\Model\QuoteIdMaskFactory::class);
78+
$this->quoteIdMaskedResource = $objectManager->get(\Magento\Quote\Model\ResourceModel\Quote\QuoteIdMask::class);
4979
}
5080

5181
protected function tearDown(): void
@@ -101,6 +131,75 @@ public function testMergeGuestWithCustomerCart()
101131
self::assertEquals(1, $item2['quantity']);
102132
}
103133

134+
#[
135+
DataFixture(ProductFixture::class, ['sku' => 'simple1', 'price' => 10], as:'p1'),
136+
DataFixture(ProductFixture::class, ['sku' => 'simple2', 'price' => 20], as:'p2'),
137+
DataFixture(BundleSelectionFixture::class, ['sku' => '$p1.sku$', 'price' => 10, 'price_type' => 0], as:'link1'),
138+
DataFixture(BundleSelectionFixture::class, ['sku' => '$p2.sku$', 'price' => 25, 'price_type' => 0], as:'link2'),
139+
DataFixture(BundleOptionFixture::class, ['title' => 'Checkbox Options', 'type' => 'checkbox',
140+
'required' => 1,'product_links' => ['$link1$', '$link2$']], 'opt1'),
141+
DataFixture(BundleOptionFixture::class, ['title' => 'Checkbox Options', 'type' => 'checkbox',
142+
'required' => 1,'product_links' => ['$link1$', '$link2$']], 'opt2'),
143+
DataFixture(
144+
BundleProductFixture::class,
145+
['sku' => 'bundle-product-multiselect-checkbox-options','price' => 50,'price_type' => 1,
146+
'_options' => ['$opt1$', '$opt2$']],
147+
as:'bp1'
148+
),
149+
DataFixture(Customer::class, ['email' => 'me@example.com'], as: 'customer'),
150+
DataFixture(CustomerCart::class, ['customer_id' => '$customer.id$'], as: 'customerCart'),
151+
DataFixture(
152+
AddBundleProductToCart::class,
153+
[
154+
'cart_id' => '$customerCart.id$',
155+
'product_id' => '$bp1.id$',
156+
'selections' => [['$p1.id$'], ['$p2.id$']],
157+
'qty' => 1
158+
]
159+
),
160+
DataFixture(GuestCartFixture::class, as: 'guestCart'),
161+
DataFixture(
162+
AddBundleProductToCart::class,
163+
[
164+
'cart_id' => '$guestCart.id$',
165+
'product_id' => '$bp1.id$',
166+
'selections' => [['$p1.id$'], ['$p2.id$']],
167+
'qty' => 2
168+
]
169+
)
170+
]
171+
public function testMergeGuestWithCustomerCartBundleProduct()
172+
{
173+
$guestCart = $this->fixtures->get('guestCart');
174+
$guestQuoteMaskedId = $this->quoteIdToMaskedId->execute((int)$guestCart->getId());
175+
176+
$customerCart = $this->fixtures->get('customerCart');
177+
$customerCartId = (int)$customerCart->getId();
178+
$customerQuoteMaskedId = $this->quoteIdToMaskedId->execute($customerCartId);
179+
if (!$customerQuoteMaskedId) {
180+
$quoteIdMask = $this->quoteIdMaskedFactory->create()->setQuoteId($customerCartId);
181+
$this->quoteIdMaskedResource->save($quoteIdMask);
182+
$customerQuoteMaskedId = $this->quoteIdToMaskedId->execute($customerCartId);
183+
}
184+
185+
$queryHeader = $this->getHeaderMap('me@example.com', 'password');
186+
$cartMergeQuery = $this->getCartMergeMutation($guestQuoteMaskedId, $customerQuoteMaskedId);
187+
$mergeResponse = $this->graphQlMutation($cartMergeQuery, [], '', $queryHeader);
188+
self::assertArrayHasKey('mergeCarts', $mergeResponse);
189+
190+
$cartResponse = $mergeResponse['mergeCarts'];
191+
self::assertArrayHasKey('items', $cartResponse);
192+
self::assertCount(1, $cartResponse['items']);
193+
$cartResponse = $this->graphQlMutation($this->getCartQuery($customerQuoteMaskedId), [], '', $queryHeader);
194+
195+
self::assertArrayHasKey('cart', $cartResponse);
196+
self::assertArrayHasKey('items', $cartResponse['cart']);
197+
self::assertCount(1, $cartResponse['cart']['items']);
198+
$item1 = $cartResponse['cart']['items'][0];
199+
self::assertArrayHasKey('quantity', $item1);
200+
self::assertEquals(3, $item1['quantity']);
201+
}
202+
104203
/**
105204
* @magentoApiDataFixture Magento/Checkout/_files/quote_with_virtual_product_saved.php
106205
* @magentoApiDataFixture Magento/Customer/_files/customer.php

0 commit comments

Comments
 (0)