Skip to content

Commit c081862

Browse files
committed
ACP2E-229: Test for Multiple Order QuoteID
- Adding test
1 parent 1ac00e3 commit c081862

File tree

3 files changed

+162
-0
lines changed

3 files changed

+162
-0
lines changed

dev/tests/integration/testsuite/Magento/Quote/Model/Quote/Item/CartItemPersisterTest.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
namespace Magento\Quote\Model\Quote\Item;
99

10+
use Magento\Framework\Exception\CouldNotSaveException;
1011
use Magento\Framework\Exception\InputException;
1112
use Magento\Framework\Exception\LocalizedException;
1213
use Magento\Framework\Exception\NoSuchEntityException;
@@ -58,6 +59,10 @@ protected function setUp(): void
5859
* @magentoDataFixture Magento/Catalog/_files/simple_product_disabled.php
5960
*
6061
* @return void
62+
* @throws InputException
63+
* @throws LocalizedException
64+
* @throws NoSuchEntityException
65+
* @throws CouldNotSaveException
6166
*/
6267
public function testSaveDisabledItem(): void
6368
{
@@ -70,10 +75,32 @@ public function testSaveDisabledItem(): void
7075
$this->model->save($quote, $item);
7176
}
7277

78+
/**
79+
* @magentoDataFixture Magento/Quote/_files/quote_for_configurable_product.php
80+
* @magentoDbIsolation enabled
81+
*
82+
* @return void
83+
* @throws CouldNotSaveException
84+
* @throws InputException
85+
* @throws LocalizedException
86+
* @throws NoSuchEntityException
87+
*/
88+
public function testSaveWithConfigurableProductWithoutException(): void
89+
{
90+
$quote = $this->quoteFactory->create();
91+
$item = $this->itemFactory->create();
92+
$item->setSku('simple_1')->setQty(1);
93+
$this->model->save($quote, $item);
94+
}
95+
7396
/**
7497
* @magentoDataFixture Magento/Catalog/_files/product_simple_duplicated.php
7598
*
7699
* @return void
100+
* @throws CouldNotSaveException
101+
* @throws InputException
102+
* @throws LocalizedException
103+
* @throws NoSuchEntityException
77104
*/
78105
public function testSaveQuoteItemWithoutQty(): void
79106
{
@@ -86,6 +113,10 @@ public function testSaveQuoteItemWithoutQty(): void
86113

87114
/**
88115
* @return void
116+
* @throws CouldNotSaveException
117+
* @throws InputException
118+
* @throws LocalizedException
119+
* @throws NoSuchEntityException
89120
*/
90121
public function testSaveQuoteItemWithNotExistingProduct(): void
91122
{
@@ -102,6 +133,10 @@ public function testSaveQuoteItemWithNotExistingProduct(): void
102133

103134
/**
104135
* @return void
136+
* @throws CouldNotSaveException
137+
* @throws InputException
138+
* @throws LocalizedException
139+
* @throws NoSuchEntityException
105140
*/
106141
public function testUpdateNotExistingQuoteItem(): void
107142
{
@@ -120,6 +155,10 @@ public function testUpdateNotExistingQuoteItem(): void
120155
* @magentoDataFixture Magento/Checkout/_files/quote_with_taxable_product_and_customer.php
121156
*
122157
* @return void
158+
* @throws CouldNotSaveException
159+
* @throws InputException
160+
* @throws LocalizedException
161+
* @throws NoSuchEntityException
123162
*/
124163
public function testUpdateQuoteItemMoreQty(): void
125164
{
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
use Magento\Catalog\Api\Data\ProductExtensionInterfaceFactory;
9+
use Magento\Catalog\Api\ProductRepositoryInterface;
10+
use Magento\Catalog\Model\Product\Attribute\Source\Status;
11+
use Magento\Catalog\Model\Product\Type;
12+
use Magento\Catalog\Model\Product\Visibility;
13+
use Magento\Catalog\Model\ProductFactory;
14+
use Magento\ConfigurableProduct\Helper\Product\Options\Factory;
15+
use Magento\ConfigurableProduct\Model\Product\Type\Configurable;
16+
use Magento\Store\Api\WebsiteRepositoryInterface;
17+
use Magento\TestFramework\Helper\Bootstrap;
18+
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
19+
20+
Resolver::getInstance()->requireDataFixture('Magento/ConfigurableProduct/_files/configurable_attribute.php');
21+
22+
$objectManager = Bootstrap::getObjectManager();
23+
/** @var ProductRepositoryInterface $productRepository */
24+
$productRepository = $objectManager->get(ProductRepositoryInterface::class);
25+
/** @var ProductFactory $productFactory */
26+
$productFactory = $objectManager->get(ProductFactory::class);
27+
/** @var Factory $optionsFactory */
28+
$optionsFactory = $objectManager->get(Factory::class);
29+
/** @var ProductExtensionInterfaceFactory $productExtensionAttributes */
30+
$productExtensionAttributesFactory = $objectManager->get(ProductExtensionInterfaceFactory::class);
31+
/** @var WebsiteRepositoryInterface $websiteRepository */
32+
$websiteRepository = $objectManager->get(WebsiteRepositoryInterface::class);
33+
$defaultWebsiteId = $websiteRepository->get('base')->getId();
34+
/** @var \Magento\Eav\Model\Config $eavConfig */
35+
$eavConfig = $objectManager->get(\Magento\Eav\Model\Config::class);
36+
$attribute = $eavConfig->getAttribute(\Magento\Catalog\Model\Product::ENTITY, 'test_configurable');
37+
$option = $attribute->getSource()->getOptionId('Option 1');
38+
$product = $productFactory->create();
39+
$product->setTypeId(Type::TYPE_SIMPLE)
40+
->setAttributeSetId($product->getDefaultAttributeSetId())
41+
->setWebsiteIds([$defaultWebsiteId])
42+
->setName('Configurable Option 1')
43+
->setSku('simple_1')
44+
->setPrice(10.00)
45+
->setTestConfigurable($option)
46+
->setVisibility(Visibility::VISIBILITY_NOT_VISIBLE)
47+
->setStatus(Status::STATUS_ENABLED)
48+
->setStockData([
49+
'manage_stock' => 1,
50+
'use_config_manage_stock' => 0,
51+
'qty' => 100,
52+
'is_qty_decimal' => 0,
53+
'is_in_stock' => 1,
54+
'use_config_max_sale_qty' => 0,
55+
'max_sale_qty' => 2
56+
]);
57+
$product = $productRepository->save($product);
58+
59+
$configurableOptions = $optionsFactory->create(
60+
[
61+
[
62+
'attribute_id' => $attribute->getId(),
63+
'code' => $attribute->getAttributeCode(),
64+
'label' => $attribute->getStoreLabel(),
65+
'position' => '0',
66+
'values' => [['label' => 'test', 'attribute_id' => $attribute->getId(), 'value_index' => $option]],
67+
],
68+
]
69+
);
70+
$extensionConfigurableAttributes = $product->getExtensionAttributes() ?: $productExtensionAttributesFactory->create();
71+
$extensionConfigurableAttributes->setConfigurableProductOptions($configurableOptions);
72+
$extensionConfigurableAttributes->setConfigurableProductLinks([$product->getId()]);
73+
74+
$configurableProduct = $productFactory->create();
75+
$configurableProduct->setExtensionAttributes($extensionConfigurableAttributes);
76+
$configurableProduct->setTypeId(Configurable::TYPE_CODE)
77+
->setAttributeSetId($configurableProduct->getDefaultAttributeSetId())
78+
->setWebsiteIds([$defaultWebsiteId])
79+
->setName('Configurable Product')
80+
->setSku('configurable')
81+
->setVisibility(Visibility::VISIBILITY_BOTH)
82+
->setStatus(Status::STATUS_ENABLED)
83+
->setStockData([
84+
'manage_stock' => 1,
85+
'use_config_manage_stock' => 0,
86+
'is_in_stock' => 1,
87+
'use_config_max_sale_qty' => 0,
88+
'max_sale_qty' => 2
89+
]);
90+
$productRepository->save($configurableProduct);
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
use Magento\Catalog\Api\ProductRepositoryInterface;
9+
use Magento\Framework\Exception\NoSuchEntityException;
10+
use Magento\Framework\Registry;
11+
use Magento\TestFramework\Helper\Bootstrap;
12+
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
13+
14+
$objectManager = Bootstrap::getObjectManager();
15+
/** @var Registry $registry */
16+
$registry = $objectManager->get(Registry::class);
17+
/** @var ProductRepositoryInterface $productRepository */
18+
$productRepository = $objectManager->get(ProductRepositoryInterface::class);
19+
$registry->unregister('isSecureArea');
20+
$registry->register('isSecureArea', true);
21+
22+
foreach (['simple_1', 'configurable'] as $sku) {
23+
try {
24+
$product = $productRepository->get($sku);
25+
$productRepository->delete($product);
26+
} catch (NoSuchEntityException $e) {
27+
//Product already removed
28+
}
29+
}
30+
31+
$registry->unregister('isSecureArea');
32+
$registry->register('isSecureArea', false);
33+
Resolver::getInstance()->requireDataFixture('Magento/ConfigurableProduct/_files/configurable_attribute_rollback.php');

0 commit comments

Comments
 (0)