Skip to content

Commit 68aeb6d

Browse files
authored
Merge pull request #5352 from magento-tsg/2.4-develop-com-pr8
[TSG-Commerce] Tests for 2.4 (pr8)
2 parents a1fad2b + 6968f6a commit 68aeb6d

35 files changed

+2417
-183
lines changed

dev/tests/integration/testsuite/Magento/Bundle/Model/Product/PriceTest.php

Lines changed: 497 additions & 28 deletions
Large diffs are not rendered by default.
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
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\Bundle\Model\Product\Price;
9+
use Magento\Catalog\Model\Product\Attribute\Source\Status;
10+
use Magento\Catalog\Model\Product\Type;
11+
use Magento\Catalog\Model\Product\Type\AbstractType;
12+
use Magento\Catalog\Model\Product\Visibility;
13+
use Magento\CatalogRule\Api\CatalogRuleRepositoryInterface;
14+
use Magento\CatalogRule\Api\Data\RuleInterface;
15+
use Magento\CatalogRule\Api\Data\RuleInterfaceFactory;
16+
use Magento\CatalogRule\Model\Indexer\IndexBuilder;
17+
use Magento\CatalogRule\Model\Rule\Condition\Combine;
18+
use Magento\CatalogRule\Model\Rule\Condition\Product;
19+
use Magento\Customer\Model\Group;
20+
use Magento\TestFramework\Bundle\Model\PrepareBundleLinks;
21+
22+
require __DIR__ . '/../../../Magento/Catalog/_files/category_with_different_price_products.php';
23+
24+
/** @var PrepareBundleLinks $prepareBundleLinks */
25+
$prepareBundleLinks = $objectManager->get(PrepareBundleLinks::class);
26+
/** @var RuleInterfaceFactory $catalogRuleFactory */
27+
$catalogRuleFactory = $objectManager->get(RuleInterfaceFactory::class);
28+
/** @var CatalogRuleRepositoryInterface $catalogRuleRepository */
29+
$catalogRuleRepository = $objectManager->get(CatalogRuleRepositoryInterface::class);
30+
/** @var IndexBuilder $indexBuilder */
31+
$indexBuilder = $objectManager->get(IndexBuilder::class);
32+
$defaultWebsiteId = $storeManager->getWebsite('base')->getId();
33+
34+
$category = $categoryFactory->create();
35+
$category->isObjectNew(true);
36+
$category->setName('Category with bundle product and rule')
37+
->setParentId($categoryHelper->getId())
38+
->setIsActive(true)
39+
->setPosition(1);
40+
$category = $categoryRepository->save($category);
41+
42+
$bundleProduct = $productFactory->create();
43+
$bundleProduct->setTypeId(Type::TYPE_BUNDLE)
44+
->setAttributeSetId($bundleProduct->getDefaultAttributeSetId())
45+
->setWebsiteIds([$defaultWebsiteId])
46+
->setName('Bundle Product')
47+
->setSku('dynamic_bundle_product_with_catalog_rule')
48+
->setVisibility(Visibility::VISIBILITY_BOTH)
49+
->setStatus(Status::STATUS_ENABLED)
50+
->setStockData(
51+
[
52+
'use_config_manage_stock' => 1,
53+
'qty' => 100,
54+
'is_qty_decimal' => 0,
55+
'is_in_stock' => 1,
56+
]
57+
)
58+
->setSkuType(0)
59+
->setPriceView(0)
60+
->setPriceType(Price::PRICE_TYPE_DYNAMIC)
61+
->setPrice(null)
62+
->setWeightType(0)
63+
->setCategoryIds([$category->getId()])
64+
->setShipmentType(AbstractType::SHIPMENT_TOGETHER);
65+
66+
$bundleOptionsData = [
67+
[
68+
'title' => 'Option 1',
69+
'default_title' => 'Option 1',
70+
'type' => 'select',
71+
'required' => 1,
72+
],
73+
];
74+
$bundleSelectionsData = [
75+
[
76+
[
77+
'sku' => $product->getSku(),
78+
'selection_qty' => 1,
79+
'selection_price_value' => 0,
80+
'selection_can_change_qty' => 1,
81+
],
82+
[
83+
'sku' => $product2->getSku(),
84+
'selection_qty' => 1,
85+
'selection_price_value' => 0,
86+
'selection_can_change_qty' => 1,
87+
],
88+
]
89+
];
90+
$bundleProduct = $prepareBundleLinks->execute($bundleProduct, $bundleOptionsData, $bundleSelectionsData);
91+
$productRepository->save($bundleProduct);
92+
93+
$ruleData = [
94+
RuleInterface::NAME => 'Rule for bundle product',
95+
RuleInterface::IS_ACTIVE => 1,
96+
'website_ids' => [$defaultWebsiteId],
97+
'customer_group_ids' => Group::NOT_LOGGED_IN_ID,
98+
RuleInterface::DISCOUNT_AMOUNT => 50,
99+
RuleInterface::SIMPLE_ACTION => 'by_percent',
100+
'conditions' => [
101+
'1' => [
102+
'type' => Combine::class,
103+
'aggregator' => 'all',
104+
'value' => '1',
105+
],
106+
'1--1' => [
107+
'type' => Product::class,
108+
'attribute' => 'category_ids',
109+
'operator' => '==',
110+
'value' => $category->getId(),
111+
],
112+
],
113+
];
114+
$catalogRule = $catalogRuleFactory->create();
115+
$catalogRule->loadPost($ruleData);
116+
$catalogRuleRepository->save($catalogRule);
117+
$indexBuilder->reindexFull();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
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\CatalogRule\Api\CatalogRuleRepositoryInterface;
9+
use Magento\CatalogRule\Model\Indexer\IndexBuilder;
10+
use Magento\CatalogRule\Model\ResourceModel\Rule\CollectionFactory;
11+
use Magento\Framework\Exception\NoSuchEntityException;
12+
use Magento\TestFramework\Catalog\Model\GetCategoryByName;
13+
14+
require __DIR__ . '/../../../Magento/Catalog/_files/category_with_different_price_products_rollback.php';
15+
16+
/** @var GetCategoryByName $getCategoryByName */
17+
$getCategoryByName = $objectManager->create(GetCategoryByName::class);
18+
/** @var CollectionFactory $ruleCollectionFactory */
19+
$ruleCollectionFactory = $objectManager->get(CollectionFactory::class);
20+
/** @var CatalogRuleRepositoryInterface $ruleRepository */
21+
$ruleRepository = $objectManager->get(CatalogRuleRepositoryInterface::class);
22+
/** @var IndexBuilder $indexBuilder */
23+
$indexBuilder = $objectManager->get(IndexBuilder::class);
24+
25+
$registry->unregister('isSecureArea');
26+
$registry->register('isSecureArea', true);
27+
28+
try {
29+
$product = $productRepository->get('dynamic_bundle_product_with_catalog_rule', false, null, true);
30+
$productRepository->delete($product);
31+
} catch (NoSuchEntityException $e) {
32+
//product already deleted.
33+
}
34+
35+
$category = $getCategoryByName->execute('Category with bundle product and rule');
36+
37+
try {
38+
$categoryRepository->delete($category);
39+
} catch (NoSuchEntityException $e) {
40+
//category already deleted.
41+
}
42+
43+
$ruleCollection = $ruleCollectionFactory->create();
44+
$ruleCollection->addFieldToFilter('name', 'Rule for bundle product');
45+
$ruleCollection->setPageSize(1);
46+
$catalogRule = $ruleCollection->getFirstItem();
47+
48+
try {
49+
$ruleRepository->delete($catalogRule);
50+
} catch (Exception $ex) {
51+
//Nothing to remove
52+
}
53+
54+
$indexBuilder->reindexFull();
55+
56+
$registry->unregister('isSecureArea');
57+
$registry->register('isSecureArea', false);
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
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\Bundle\Model\Product\Price;
9+
use Magento\Catalog\Model\Product\Attribute\Source\Status;
10+
use Magento\Catalog\Model\Product\Type;
11+
use Magento\Catalog\Model\Product\Type\AbstractType;
12+
use Magento\Catalog\Model\Product\Visibility;
13+
use Magento\TestFramework\Bundle\Model\PrepareBundleLinks;
14+
15+
require __DIR__ . '/../../../Magento/Catalog/_files/category_with_different_price_products.php';
16+
17+
/** @var PrepareBundleLinks $prepareBundleLinks */
18+
$prepareBundleLinks = $objectManager->get(PrepareBundleLinks::class);
19+
$defaultWebsiteId = $storeManager->getWebsite('base')->getId();
20+
21+
$bundleProduct = $productFactory->create();
22+
$bundleProduct->setTypeId(Type::TYPE_BUNDLE)
23+
->setAttributeSetId($bundleProduct->getDefaultAttributeSetId())
24+
->setWebsiteIds([$defaultWebsiteId])
25+
->setName('Bundle Product')
26+
->setSku('dynamic_bundle_product_with_special_price')
27+
->setVisibility(Visibility::VISIBILITY_BOTH)
28+
->setStatus(Status::STATUS_ENABLED)
29+
->setStockData(
30+
[
31+
'use_config_manage_stock' => 1,
32+
'qty' => 100,
33+
'is_qty_decimal' => 0,
34+
'is_in_stock' => 1,
35+
]
36+
)
37+
->setSkuType(0)
38+
->setPriceView(0)
39+
->setPriceType(Price::PRICE_TYPE_DYNAMIC)
40+
->setPrice(null)
41+
->setSpecialPrice(75)
42+
->setWeightType(0)
43+
->setShipmentType(AbstractType::SHIPMENT_TOGETHER);
44+
45+
$bundleOptionsData = [
46+
[
47+
'title' => 'Option 1',
48+
'default_title' => 'Option 1',
49+
'type' => 'select',
50+
'required' => 1,
51+
],
52+
];
53+
$bundleSelectionsData = [
54+
[
55+
[
56+
'sku' => $product->getSku(),
57+
'selection_qty' => 1,
58+
'selection_price_value' => 0,
59+
'selection_can_change_qty' => 1,
60+
],
61+
[
62+
'sku' => $product2->getSku(),
63+
'selection_qty' => 1,
64+
'selection_price_value' => 0,
65+
'selection_can_change_qty' => 1,
66+
],
67+
]
68+
];
69+
$bundleProduct = $prepareBundleLinks->execute($bundleProduct, $bundleOptionsData, $bundleSelectionsData);
70+
$productRepository->save($bundleProduct);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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\Framework\Exception\NoSuchEntityException;
9+
10+
require __DIR__ . '/../../../Magento/Catalog/_files/category_with_different_price_products_rollback.php';
11+
12+
$registry->unregister('isSecureArea');
13+
$registry->register('isSecureArea', true);
14+
15+
try {
16+
$product = $productRepository->get('dynamic_bundle_product_with_special_price', false, null, true);
17+
$productRepository->delete($product);
18+
} catch (NoSuchEntityException $e) {
19+
//product already deleted.
20+
}
21+
22+
$registry->unregister('isSecureArea');
23+
$registry->register('isSecureArea', false);
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
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\Bundle\Model\Product\Price;
9+
use Magento\Catalog\Api\Data\ProductTierPriceExtensionFactory;
10+
use Magento\Catalog\Api\Data\ProductTierPriceInterfaceFactory;
11+
use Magento\Catalog\Model\Product\Attribute\Source\Status;
12+
use Magento\Catalog\Model\Product\Type;
13+
use Magento\Catalog\Model\Product\Type\AbstractType;
14+
use Magento\Catalog\Model\Product\Visibility;
15+
use Magento\TestFramework\Bundle\Model\PrepareBundleLinks;
16+
use Magento\Customer\Model\Group;
17+
18+
require __DIR__ . '/../../../Magento/Catalog/_files/category_with_different_price_products.php';
19+
20+
/** @var PrepareBundleLinks $prepareBundleLinks */
21+
$prepareBundleLinks = $objectManager->get(PrepareBundleLinks::class);
22+
/** @var ProductTierPriceInterfaceFactory $tierPriceFactory */
23+
$tierPriceFactory = $objectManager->get(ProductTierPriceInterfaceFactory::class);
24+
/** @var $tierPriceExtensionAttributesFactory */
25+
$tierPriceExtensionAttributesFactory = $objectManager->get(ProductTierPriceExtensionFactory::class);
26+
$defaultWebsiteId = $storeManager->getWebsite('base')->getId();
27+
28+
$bundleProduct = $productFactory->create();
29+
$bundleProduct->setTypeId(Type::TYPE_BUNDLE)
30+
->setAttributeSetId($bundleProduct->getDefaultAttributeSetId())
31+
->setWebsiteIds([$defaultWebsiteId])
32+
->setName('Bundle Product')
33+
->setSku('dynamic_bundle_product_with_tier_price')
34+
->setVisibility(Visibility::VISIBILITY_BOTH)
35+
->setStatus(Status::STATUS_ENABLED)
36+
->setStockData(
37+
[
38+
'use_config_manage_stock' => 1,
39+
'qty' => 100,
40+
'is_qty_decimal' => 0,
41+
'is_in_stock' => 1,
42+
]
43+
)
44+
->setSkuType(0)
45+
->setPriceView(0)
46+
->setPriceType(Price::PRICE_TYPE_DYNAMIC)
47+
->setPrice(null)
48+
->setWeightType(0)
49+
->setShipmentType(AbstractType::SHIPMENT_TOGETHER);
50+
51+
$bundleOptionsData = [
52+
[
53+
'title' => 'Option 1',
54+
'default_title' => 'Option 1',
55+
'type' => 'select',
56+
'required' => 1,
57+
],
58+
];
59+
$bundleSelectionsData = [
60+
[
61+
[
62+
'sku' => $product->getSku(),
63+
'selection_qty' => 1,
64+
'selection_price_value' => 0,
65+
'selection_can_change_qty' => 1,
66+
],
67+
[
68+
'sku' => $product2->getSku(),
69+
'selection_qty' => 1,
70+
'selection_price_value' => 0,
71+
'selection_can_change_qty' => 1,
72+
],
73+
]
74+
];
75+
$bundleProduct = $prepareBundleLinks->execute($bundleProduct, $bundleOptionsData, $bundleSelectionsData);
76+
77+
$tierPriceExtensionAttribute = $tierPriceExtensionAttributesFactory->create(
78+
[
79+
'data' => [
80+
'website_id' => 0,
81+
'percentage_value' => 25,
82+
]
83+
]
84+
);
85+
$tierPrices[] = $tierPriceFactory->create(
86+
[
87+
'data' => [
88+
'customer_group_id' => Group::CUST_GROUP_ALL,
89+
'qty' => 1,
90+
]
91+
]
92+
)->setExtensionAttributes($tierPriceExtensionAttribute);
93+
$bundleProduct->setTierPrices($tierPrices);
94+
$productRepository->save($bundleProduct);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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\Framework\Exception\NoSuchEntityException;
9+
10+
require __DIR__ . '/../../../Magento/Catalog/_files/category_with_different_price_products_rollback.php';
11+
12+
$registry->unregister('isSecureArea');
13+
$registry->register('isSecureArea', true);
14+
15+
try {
16+
$product = $productRepository->get('dynamic_bundle_product_with_tier_price', false, null, true);
17+
$productRepository->delete($product);
18+
} catch (NoSuchEntityException $e) {
19+
//product already deleted.
20+
}
21+
22+
$registry->unregister('isSecureArea');
23+
$registry->register('isSecureArea', false);

0 commit comments

Comments
 (0)