Skip to content

Commit 4e99a86

Browse files
committed
PB-261: Add Missing Integration P0-P1 Tests For Products
- fix static issues in tests
1 parent b75e66d commit 4e99a86

15 files changed

+437
-342
lines changed

dev/tests/integration/testsuite/Magento/PageBuilder/Model/Catalog/SortingTest.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -142,13 +142,13 @@ public function productSortDataProvider1() : array
142142
'downloadable-product-price-on-link',
143143
'downloadable-product-price-on-product',
144144
'simple-with-fpt',
145+
'grouped',
146+
'simple_100000002',
147+
'simple_100000001',
145148
'configurable',
146149
'bundle_product',
147150
'simple3',
148151
'simple1',
149-
'grouped',
150-
'simple_100000002',
151-
'simple_100000001',
152152
'gift-card',
153153
'PB_VIRTUAL_PRODUCT',
154154
'PB_PRODUCT_CPR',
@@ -165,13 +165,13 @@ public function productSortDataProvider1() : array
165165
'PB_PRODUCT_CPR',
166166
'PB_VIRTUAL_PRODUCT',
167167
'gift-card',
168-
'simple_100000001',
169-
'simple_100000002',
170-
'grouped',
171168
'simple1',
172169
'simple3',
173170
'bundle_product',
174171
'configurable',
172+
'simple_100000001',
173+
'simple_100000002',
174+
'grouped',
175175
'simple-with-fpt',
176176
'downloadable-product-price-on-product',
177177
'downloadable-product-price-on-link'
@@ -269,9 +269,9 @@ public function productSortDataProvider2() : array
269269
],
270270
'low_stock_first' => [
271271
'gift-card',
272-
'grouped',
273272
'bundle_product',
274273
'configurable',
274+
'grouped',
275275
'B_PB_PRODUCT',
276276
'1_PB_PRODUCT',
277277
'a_pb_product',
@@ -300,9 +300,9 @@ public function productSortDataProvider2() : array
300300
'a_pb_product',
301301
'1_PB_PRODUCT',
302302
'B_PB_PRODUCT',
303+
'grouped',
303304
'configurable',
304305
'bundle_product',
305-
'grouped',
306306
'gift-card'
307307
],
308308
],

dev/tests/integration/testsuite/Magento/PageBuilder/_files/catalog_sorting/bundle_product.php

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,31 @@
66

77
require __DIR__ . '/multiple_products.php';
88

9-
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
10-
$productRepository = $objectManager->create(\Magento\Catalog\Api\ProductRepositoryInterface::class);
9+
use Magento\Bundle\Api\Data\LinkInterfaceFactory;
10+
use Magento\Bundle\Api\Data\OptionInterfaceFactory;
11+
use Magento\Bundle\Model\Product\Price;
12+
use Magento\Catalog\Api\CategoryLinkManagementInterface;
13+
use Magento\Catalog\Api\CategoryLinkRepositoryInterface;
14+
use Magento\Catalog\Api\ProductRepositoryInterface;
15+
use Magento\Catalog\Model\Product;
16+
use Magento\Catalog\Model\Product\Attribute\Source\Status;
17+
use Magento\Catalog\Model\Product\Type;
18+
use Magento\Catalog\Model\Product\Visibility;
19+
use Magento\TestFramework\Helper\Bootstrap;
1120

12-
/* @var \Magento\Catalog\Api\CategoryLinkRepositoryInterface $categoryLinkRepository */
21+
$objectManager = Bootstrap::getObjectManager();
22+
$productRepository = $objectManager->create(ProductRepositoryInterface::class);
23+
24+
/* @var CategoryLinkRepositoryInterface $categoryLinkRepository */
1325
$categoryLinkRepository = $objectManager->create(
14-
\Magento\Catalog\Api\CategoryLinkRepositoryInterface::class,
26+
CategoryLinkRepositoryInterface::class,
1527
[
1628
'productRepository' => $productRepository
1729
]
1830
);
1931

20-
/** @var Magento\Catalog\Api\CategoryLinkManagementInterface $linkManagement */
21-
$categoryLinkManagement = $objectManager->create(\Magento\Catalog\Api\CategoryLinkManagementInterface::class);
32+
/** @var CategoryLinkManagementInterface $linkManagement */
33+
$categoryLinkManagement = $objectManager->create(CategoryLinkManagementInterface::class);
2234
$reflectionClass = new \ReflectionClass(get_class($categoryLinkManagement));
2335
$properties = [
2436
'productRepository' => $productRepository,
@@ -32,18 +44,18 @@
3244
}
3345
}
3446

35-
/** @var \Magento\Catalog\Model\Product $bundleProduct */
36-
$bundleProduct = $objectManager->create(\Magento\Catalog\Model\Product::class);
37-
$bundleProduct->setTypeId(\Magento\Catalog\Model\Product\Type::TYPE_BUNDLE)
47+
/** @var Product $bundleProduct */
48+
$bundleProduct = $objectManager->create(Product::class);
49+
$bundleProduct->setTypeId(Type::TYPE_BUNDLE)
3850
->setAttributeSetId(4)
3951
->setWebsiteIds([1])
4052
->setName('Bundle Product')
4153
->setSku('bundle_product')
42-
->setVisibility(\Magento\Catalog\Model\Product\Visibility::VISIBILITY_BOTH)
43-
->setStatus(\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED)
54+
->setVisibility(Visibility::VISIBILITY_BOTH)
55+
->setStatus(Status::STATUS_ENABLED)
4456
->setStockData(['use_config_manage_stock' => 1, 'is_in_stock' => 1])
4557
->setPriceView(0)
46-
->setPriceType(\Magento\Bundle\Model\Product\Price::PRICE_TYPE_FIXED)
58+
->setPriceType(Price::PRICE_TYPE_FIXED)
4759
->setPrice(110.0)
4860
->setShipmentType(0)->save();
4961

@@ -82,12 +94,12 @@
8294
$linksData = $optionData['links'];
8395
unset($optionData['links']);
8496

85-
$option = $objectManager->create(\Magento\Bundle\Api\Data\OptionInterfaceFactory::class)
97+
$option = $objectManager->create(OptionInterfaceFactory::class)
8698
->create(['data' => $optionData])
8799
->setSku($bundleProduct->getSku());
88100

89101
foreach ($linksData as $linkData) {
90-
$links[] = $objectManager->create(\Magento\Bundle\Api\Data\LinkInterfaceFactory::class)
102+
$links[] = $objectManager->create(LinkInterfaceFactory::class)
91103
->create(['data' => $linkData]);
92104
}
93105

dev/tests/integration/testsuite/Magento/PageBuilder/_files/catalog_sorting/configurable_attribute.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,12 @@
5656
$attributeRepository->save($attribute);
5757

5858
/* Assign attribute to attribute set */
59-
$installer->addAttributeToGroup('catalog_product', 'Default', 'General', $attribute->getId());
59+
$installer->addAttributeToGroup(
60+
'catalog_product',
61+
'Default',
62+
'General',
63+
$attribute->getId()
64+
);
6065
}
6166

6267
$eavConfig->clear();

dev/tests/integration/testsuite/Magento/PageBuilder/_files/catalog_sorting/configurable_products.php

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
7+
use Magento\Catalog\Api\CategoryLinkManagementInterface;
68
use Magento\Catalog\Api\ProductRepositoryInterface;
79
use Magento\Catalog\Model\Product;
810
use Magento\Catalog\Model\Product\Attribute\Source\Status;
@@ -12,18 +14,23 @@
1214
use Magento\ConfigurableProduct\Helper\Product\Options\Factory;
1315
use Magento\ConfigurableProduct\Model\Product\Type\Configurable;
1416
use Magento\Eav\Api\Data\AttributeOptionInterface;
17+
use Magento\Framework\App\ObjectManager;
1518
use Magento\TestFramework\Helper\Bootstrap;
1619

1720
require __DIR__ . '/configurable_attribute.php';
1821

22+
/** @var ObjectManager $objectManager */
23+
$objectManager = Bootstrap::getObjectManager();
24+
1925
/** @var ProductRepositoryInterface $productRepository */
20-
$productRepository = Bootstrap::getObjectManager()
21-
->get(ProductRepositoryInterface::class);
22-
/** @var $categoryLinkManagement \Magento\Catalog\Api\CategoryLinkManagementInterface */
23-
$categoryLinkManagement = Bootstrap::getObjectManager()->create(\Magento\Catalog\Api\CategoryLinkManagementInterface::class);
26+
$productRepository = $objectManager->get(ProductRepositoryInterface::class);
27+
28+
/** @var $categoryLinkManagement CategoryLinkManagementInterface */
29+
$categoryLinkManagement = $objectManager
30+
->create(CategoryLinkManagementInterface::class);
2431

2532
/** @var $installer CategorySetup */
26-
$installer = Bootstrap::getObjectManager()->create(CategorySetup::class);
33+
$installer = $objectManager->create(CategorySetup::class);
2734

2835
/* Create simple products per each option value*/
2936
/** @var AttributeOptionInterface[] $options */
@@ -37,7 +44,7 @@
3744

3845
foreach ($options as $option) {
3946
/** @var $product Product */
40-
$product = Bootstrap::getObjectManager()->create(Product::class);
47+
$product = $objectManager->create(Product::class);
4148
$productId = array_shift($productIds);
4249
$product->setTypeId(Type::TYPE_SIMPLE)
4350
->setAttributeSetId($attributeSetId)
@@ -64,9 +71,9 @@
6471
}
6572

6673
/** @var $product Product */
67-
$product = Bootstrap::getObjectManager()->create(Product::class);
74+
$product = $objectManager->create(Product::class);
6875
/** @var Factory $optionsFactory */
69-
$optionsFactory = Bootstrap::getObjectManager()->create(Factory::class);
76+
$optionsFactory = $objectManager->create(Factory::class);
7077
$configurableAttributesData = [
7178
[
7279
'attribute_id' => $attribute->getId(),

dev/tests/integration/testsuite/Magento/PageBuilder/_files/catalog_sorting/downloadable_products.php

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,22 @@
44
* See COPYING.txt for license details.
55
*/
66

7+
use Magento\Catalog\Api\CategoryLinkManagementInterface;
8+
use Magento\Catalog\Api\ProductRepositoryInterface;
9+
use Magento\Catalog\Model\Product;
10+
use Magento\Catalog\Model\Product\Attribute\Source\Status;
11+
use Magento\Catalog\Model\Product\Visibility;
12+
use Magento\Downloadable\Api\Data\LinkInterfaceFactory;
713
use Magento\Downloadable\Api\DomainManagerInterface;
14+
use Magento\Downloadable\Helper\Download;
15+
use Magento\Downloadable\Model\Link;
16+
use Magento\Downloadable\Model\Product\Type;
17+
use Magento\TestFramework\Helper\Bootstrap;
818

9-
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
19+
$objectManager = Bootstrap::getObjectManager();
1020

11-
/** @var $categoryLinkManagement \Magento\Catalog\Api\CategoryLinkManagementInterface */
12-
$categoryLinkManagement = $objectManager->create(\Magento\Catalog\Api\CategoryLinkManagementInterface::class);
21+
/** @var $categoryLinkManagement CategoryLinkManagementInterface */
22+
$categoryLinkManagement = $objectManager->create(CategoryLinkManagementInterface::class);
1323

1424
/** @var DomainManagerInterface $domainManager */
1525
$domainManager = $objectManager->get(DomainManagerInterface::class);
@@ -22,17 +32,17 @@
2232
]
2333
);
2434

25-
/** @var \Magento\Catalog\Model\Product $product */
26-
$product = $objectManager->create(\Magento\Catalog\Model\Product::class);
35+
/** @var Product $product */
36+
$product = $objectManager->create(Product::class);
2737
$product
28-
->setTypeId(\Magento\Downloadable\Model\Product\Type::TYPE_DOWNLOADABLE)
38+
->setTypeId(Type::TYPE_DOWNLOADABLE)
2939
->setAttributeSetId(4)
3040
->setWebsiteIds([1])
3141
->setName('Downloadable Product with product price')
3242
->setSku('downloadable-product-price-on-product')
3343
->setPrice(41)
34-
->setVisibility(\Magento\Catalog\Model\Product\Visibility::VISIBILITY_BOTH)
35-
->setStatus(\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED)
44+
->setVisibility(Visibility::VISIBILITY_BOTH)
45+
->setStatus(Status::STATUS_ENABLED)
3646
->setLinksPurchasedSeparately(true)
3747
->setStockData(
3848
[
@@ -43,15 +53,14 @@
4353
);
4454

4555
/**
46-
* @var \Magento\Downloadable\Api\Data\LinkInterfaceFactory $linkFactory
56+
* @var LinkInterfaceFactory $linkFactory
4757
*/
48-
$linkFactory = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
49-
->get(\Magento\Downloadable\Api\Data\LinkInterfaceFactory::class);
58+
$linkFactory = $objectManager->get(LinkInterfaceFactory::class);
5059
$links = [];
5160
$linkData = [
5261
'title' => 'Downloadable Product Link',
53-
'type' => \Magento\Downloadable\Helper\Download::LINK_TYPE_URL,
54-
'is_shareable' => \Magento\Downloadable\Model\Link::LINK_SHAREABLE_CONFIG,
62+
'type' => Download::LINK_TYPE_URL,
63+
'is_shareable' => Link::LINK_SHAREABLE_CONFIG,
5564
'link_url' => 'http://example.com/downloadable.txt',
5665
'link_id' => 0,
5766
'is_delete' => null,
@@ -70,25 +79,24 @@
7079
$extension->setDownloadableProductLinks($links);
7180
$product->setExtensionAttributes($extension);
7281

73-
$productRepository = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
74-
->get(\Magento\Catalog\Api\ProductRepositoryInterface::class);
82+
$productRepository = $objectManager->get(ProductRepositoryInterface::class);
7583
$productRepository->save($product);
7684
$categoryLinkManagement->assignProductToCategories(
7785
$product->getSku(),
7886
[2]
7987
);
8088

8189

82-
$product = $objectManager->create(\Magento\Catalog\Model\Product::class);
90+
$product = $objectManager->create(Product::class);
8391
$product
84-
->setTypeId(\Magento\Downloadable\Model\Product\Type::TYPE_DOWNLOADABLE)
92+
->setTypeId(Type::TYPE_DOWNLOADABLE)
8593
->setAttributeSetId(4)
8694
->setWebsiteIds([1])
8795
->setName('Downloadable Product with link price')
8896
->setSku('downloadable-product-price-on-link')
8997
->setPrice(0)
90-
->setVisibility(\Magento\Catalog\Model\Product\Visibility::VISIBILITY_BOTH)
91-
->setStatus(\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED)
98+
->setVisibility(Visibility::VISIBILITY_BOTH)
99+
->setStatus(Status::STATUS_ENABLED)
92100
->setLinksPurchasedSeparately(true)
93101
->setStockData(
94102
[
@@ -119,8 +127,8 @@
119127
$links[] = $link;
120128
$extension = $product->getExtensionAttributes();
121129
$extension->setDownloadableProductLinks($links);
122-
$product->setExtensionAttributes($extension)->save();
123-
//$productRepository->save($product);
130+
$product->setExtensionAttributes($extension);
131+
$productRepository->save($product);
124132
$categoryLinkManagement->assignProductToCategories(
125133
$product->getSku(),
126134
[2]

dev/tests/integration/testsuite/Magento/PageBuilder/_files/catalog_sorting/grouped_product.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
7+
use Magento\Catalog\Api\Data\ProductLinkInterface;
68
use Magento\Catalog\Api\ProductRepositoryInterface;
79
use Magento\Catalog\Model\Product;
810
use Magento\Catalog\Model\Product\Attribute\Source\Status;
@@ -11,14 +13,14 @@
1113
use Magento\GroupedProduct\Model\Product\Type\Grouped;
1214
use Magento\TestFramework\Helper\Bootstrap;
1315

16+
$objectManager = Bootstrap::getObjectManager();
17+
1418
/** @var ProductRepositoryInterface $productRepository */
15-
$productRepository = Bootstrap::getObjectManager()
16-
->get(ProductRepositoryInterface::class);
19+
$productRepository = $objectManager->get(ProductRepositoryInterface::class);
1720
/** @var $categoryLinkManagement \Magento\Catalog\Api\CategoryLinkManagementInterface */
18-
$categoryLinkManagement = Bootstrap::getObjectManager()->create(\Magento\Catalog\Api\CategoryLinkManagementInterface::class);
21+
$categoryLinkManagement = $objectManager->create(\Magento\Catalog\Api\CategoryLinkManagementInterface::class);
1922

20-
$productLinkFactory = Bootstrap::getObjectManager()
21-
->get(\Magento\Catalog\Api\Data\ProductLinkInterfaceFactory::class);
23+
$productLinkFactory = $objectManager->get(\Magento\Catalog\Api\Data\ProductLinkInterfaceFactory::class);
2224
$productConfigs = [
2325
[
2426
'id' => '100000001',
@@ -34,9 +36,8 @@
3436

3537
foreach ($productConfigs as $productConfig) {
3638
/** @var $product Product */
37-
$product = Bootstrap::getObjectManager()->create(Product::class);
39+
$product = $objectManager->create(Product::class);
3840
$product->setTypeId(Type::TYPE_SIMPLE)
39-
->setId($productConfig['id'])
4041
->setWebsiteIds([1])
4142
->setAttributeSetId(4)
4243
->setName('Simple ' . $productConfig['id'])
@@ -54,10 +55,9 @@
5455
}
5556

5657
/** @var $product Product */
57-
$product = Bootstrap::getObjectManager()->create(Product::class);
58+
$product = $objectManager->create(Product::class);
5859

5960
$product->setTypeId(Grouped::TYPE_CODE)
60-
->setId('100000003')
6161
->setWebsiteIds([1])
6262
->setAttributeSetId(4)
6363
->setName('Grouped Product')
@@ -67,7 +67,7 @@
6767
->setStockData(['use_config_manage_stock' => 1, 'is_in_stock' => 1]);
6868

6969
foreach ($linkedProducts as $linkedProduct) {
70-
/** @var \Magento\Catalog\Api\Data\ProductLinkInterface $productLink */
70+
/** @var ProductLinkInterface $productLink */
7171
$productLink = $productLinkFactory->create();
7272
$productLink->setSku($product->getSku())
7373
->setLinkType('associated')

0 commit comments

Comments
 (0)