Skip to content

Commit b2f3476

Browse files
committed
MAGETWO-87144: Create tests for all product types
- reverted fixture for api Tests
1 parent 56e7565 commit b2f3476

File tree

4 files changed

+133
-16
lines changed

4 files changed

+133
-16
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class BundleProductViewTest extends GraphQlAbstract
1717
{
1818
const KEY_PRICE_TYPE_FIXED = 'FIXED';
1919
/**
20-
* @magentoApiDataFixture Magento/Bundle/_files/product.php
20+
* @magentoApiDataFixture Magento/Bundle/_files/product_1.php
2121
*/
2222
public function testAllFielsBundleProducts()
2323
{
@@ -302,7 +302,7 @@ public function testAndMaxMinPriceBundleProduct()
302302
}
303303

304304
/**
305-
* @magentoApiDataFixture Magento/Bundle/_files/product.php
305+
* @magentoApiDataFixture Magento/Bundle/_files/product_1.php
306306
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
307307
*/
308308
public function testNonExistentFieldQtyExceptionOnBundleProduct()

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

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,37 +3,31 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6-
76
/*
87
* Since the bundle product creation GUI doesn't allow to choose values for bundled products' custom options,
98
* bundled items should not contain products with required custom options.
109
* However, if to create such a bundle product, it will be always out of stock.
1110
*/
1211
require __DIR__ . '/../../../Magento/Catalog/_files/products.php';
13-
1412
/** @var $objectManager \Magento\TestFramework\ObjectManager */
1513
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
1614
/** @var \Magento\Catalog\Api\ProductRepositoryInterface $productRepository */
1715
$productRepository = $objectManager->create(\Magento\Catalog\Api\ProductRepositoryInterface::class);
1816
$sampleProduct = $productRepository->get('simple');
19-
2017
/** @var $product \Magento\Catalog\Model\Product */
2118
$product = $objectManager->create(\Magento\Catalog\Model\Product::class);
2219
$product->setTypeId('bundle')
2320
->setId(3)
2421
->setAttributeSetId(4)
25-
->setWeight(2)
2622
->setWebsiteIds([1])
2723
->setName('Bundle Product')
2824
->setSku('bundle-product')
2925
->setVisibility(\Magento\Catalog\Model\Product\Visibility::VISIBILITY_BOTH)
3026
->setStatus(\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED)
3127
->setStockData(['use_config_manage_stock' => 1, 'qty' => 100, 'is_qty_decimal' => 0, 'is_in_stock' => 1])
3228
->setPriceView(1)
33-
->setSkuType(1)
34-
->setWeightType(1)
3529
->setPriceType(1)
36-
->setShipmentType(0)
30+
->setShipmentType(1)
3731
->setPrice(10.0)
3832
->setBundleOptionsData(
3933
[
@@ -50,16 +44,13 @@
5044
[
5145
[
5246
'product_id' => $sampleProduct->getId(),
53-
'selection_price_value' => 2.75,
5447
'selection_qty' => 1,
5548
'selection_can_change_qty' => 1,
5649
'delete' => '',
57-
5850
],
5951
],
6052
]
6153
);
62-
6354
if ($product->getBundleOptionsData()) {
6455
$options = [];
6556
foreach ($product->getBundleOptionsData() as $key => $optionData) {
@@ -68,7 +59,6 @@
6859
->create(['data' => $optionData]);
6960
$option->setSku($product->getSku());
7061
$option->setOptionId(null);
71-
7262
$links = [];
7363
$bundleLinks = $product->getBundleSelectionsData();
7464
if (!empty($bundleLinks[$key])) {
@@ -80,7 +70,6 @@
8070
$linkProduct = $productRepository->getById($linkData['product_id']);
8171
$link->setSku($linkProduct->getSku());
8272
$link->setQty($linkData['selection_qty']);
83-
$link->setPrice($linkData['selection_price_value']);
8473
if (isset($linkData['selection_can_change_qty'])) {
8574
$link->setCanChangeQuantity($linkData['selection_can_change_qty']);
8675
}
@@ -96,5 +85,4 @@
9685
$extension->setBundleProductOptions($options);
9786
$product->setExtensionAttributes($extension);
9887
}
99-
//$product->save();
100-
$productRepository->save($product, true);
88+
$product->save();
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
/*
8+
* Since the bundle product creation GUI doesn't allow to choose values for bundled products' custom options,
9+
* bundled items should not contain products with required custom options.
10+
* However, if to create such a bundle product, it will be always out of stock.
11+
*/
12+
require __DIR__ . '/../../../Magento/Catalog/_files/products.php';
13+
14+
/** @var $objectManager \Magento\TestFramework\ObjectManager */
15+
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
16+
/** @var \Magento\Catalog\Api\ProductRepositoryInterface $productRepository */
17+
$productRepository = $objectManager->create(\Magento\Catalog\Api\ProductRepositoryInterface::class);
18+
$sampleProduct = $productRepository->get('simple');
19+
20+
/** @var $product \Magento\Catalog\Model\Product */
21+
$product = $objectManager->create(\Magento\Catalog\Model\Product::class);
22+
$product->setTypeId('bundle')
23+
->setId(3)
24+
->setAttributeSetId(4)
25+
->setWeight(2)
26+
->setWebsiteIds([1])
27+
->setName('Bundle Product')
28+
->setSku('bundle-product')
29+
->setVisibility(\Magento\Catalog\Model\Product\Visibility::VISIBILITY_BOTH)
30+
->setStatus(\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED)
31+
->setStockData(['use_config_manage_stock' => 1, 'qty' => 100, 'is_qty_decimal' => 0, 'is_in_stock' => 1])
32+
->setPriceView(1)
33+
->setSkuType(1)
34+
->setWeightType(1)
35+
->setPriceType(1)
36+
->setShipmentType(0)
37+
->setPrice(10.0)
38+
->setBundleOptionsData(
39+
[
40+
[
41+
'title' => 'Bundle Product Items',
42+
'default_title' => 'Bundle Product Items',
43+
'type' => 'select', 'required' => 1,
44+
'delete' => '',
45+
],
46+
]
47+
)
48+
->setBundleSelectionsData(
49+
[
50+
[
51+
[
52+
'product_id' => $sampleProduct->getId(),
53+
'selection_price_value' => 2.75,
54+
'selection_qty' => 1,
55+
'selection_can_change_qty' => 1,
56+
'delete' => '',
57+
58+
],
59+
],
60+
]
61+
);
62+
63+
if ($product->getBundleOptionsData()) {
64+
$options = [];
65+
foreach ($product->getBundleOptionsData() as $key => $optionData) {
66+
if (!(bool)$optionData['delete']) {
67+
$option = $objectManager->create(\Magento\Bundle\Api\Data\OptionInterfaceFactory::class)
68+
->create(['data' => $optionData]);
69+
$option->setSku($product->getSku());
70+
$option->setOptionId(null);
71+
72+
$links = [];
73+
$bundleLinks = $product->getBundleSelectionsData();
74+
if (!empty($bundleLinks[$key])) {
75+
foreach ($bundleLinks[$key] as $linkData) {
76+
if (!(bool)$linkData['delete']) {
77+
/** @var \Magento\Bundle\Api\Data\LinkInterface$link */
78+
$link = $objectManager->create(\Magento\Bundle\Api\Data\LinkInterfaceFactory::class)
79+
->create(['data' => $linkData]);
80+
$linkProduct = $productRepository->getById($linkData['product_id']);
81+
$link->setSku($linkProduct->getSku());
82+
$link->setQty($linkData['selection_qty']);
83+
$link->setPrice($linkData['selection_price_value']);
84+
if (isset($linkData['selection_can_change_qty'])) {
85+
$link->setCanChangeQuantity($linkData['selection_can_change_qty']);
86+
}
87+
$links[] = $link;
88+
}
89+
}
90+
$option->setProductLinks($links);
91+
$options[] = $option;
92+
}
93+
}
94+
}
95+
$extension = $product->getExtensionAttributes();
96+
$extension->setBundleProductOptions($options);
97+
$product->setExtensionAttributes($extension);
98+
}
99+
//$product->save();
100+
$productRepository->save($product, true);
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
/*
8+
* Since the bundle product creation GUI doesn't allow to choose values for bundled products' custom options,
9+
* bundled items should not contain products with required custom options.
10+
* However, if to create such a bundle product, it will be always out of stock.
11+
*/
12+
require __DIR__ . '/../../../Magento/Catalog/_files/products_rollback.php';
13+
14+
/** @var \Magento\Framework\Registry $registry */
15+
$registry = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(\Magento\Framework\Registry::class);
16+
$registry->unregister('isSecureArea');
17+
$registry->register('isSecureArea', true);
18+
19+
$productRepository = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
20+
->get(\Magento\Catalog\Api\ProductRepositoryInterface::class);
21+
try {
22+
$product = $productRepository->get('bundle-product', false, null, true);
23+
$productRepository->delete($product);
24+
} catch (\Magento\Framework\Exception\NoSuchEntityException $e) {
25+
//Product already removed
26+
}
27+
28+
$registry->unregister('isSecureArea');
29+
$registry->register('isSecureArea', false);

0 commit comments

Comments
 (0)