Skip to content

Commit 8c4a0b6

Browse files
committed
ACP2E-1345, added unit test
1 parent 5f7b00f commit 8c4a0b6

File tree

3 files changed

+64
-30
lines changed

3 files changed

+64
-30
lines changed

app/code/Magento/Bundle/Model/ResourceModel/Selection.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -174,12 +174,11 @@ public function saveSelectionPrice($item)
174174
$values = [
175175
'selection_id' => $item->getSelectionId(),
176176
'website_id' => $item->getWebsiteId(),
177-
//'selection_price_type' => $item->getSelectionPriceType() ?? 0,
178-
'selection_price_type' => $item->getSelectionPriceType(),
179-
//'selection_price_value' => $item->getSelectionPriceValue() ?? 0,
180-
'selection_price_value' => $item->getSelectionPriceValue(),
177+
'selection_price_type' => $item->getSelectionPriceType() ?? 0,
178+
'selection_price_value' => $item->getSelectionPriceValue() ?? 0,
181179
'parent_product_id' => $item->getParentProductId(),
182180
];
181+
183182
$connection->insertOnDuplicate(
184183
$this->getTable('catalog_product_bundle_selection_price'),
185184
$values,
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Bundle\Test\Unit\Model\ResourceModel;
7+
8+
use Codeception\PHPUnit\TestCase;
9+
use Magento\Bundle\Model\ResourceModel\Selection as ResourceSelection;
10+
use Magento\Bundle\Model\Selection;
11+
use Magento\Framework\DB\Adapter\AdapterInterface;
12+
13+
/**
14+
* Class to test Selection Resource Model
15+
*/
16+
class SelectionTest extends TestCase
17+
{
18+
public function testSaveSelectionPrice()
19+
{
20+
$item = $this->getMockBuilder(Selection::class)
21+
->disableOriginalConstructor()
22+
->addMethods(['getSelectionId', 'getWebsiteId', 'getSelectionPriceType', 'getSelectionPriceValue', 'getParentProductId', 'getDefaultPriceScope'])
23+
->getMock();
24+
$values = [
25+
'selection_id' => 1,
26+
'website_id' => 1,
27+
'selection_price_type' => null,
28+
'selection_price_value' => null,
29+
'parent_product_id' => 1,
30+
];
31+
$item->expects($this->once())->method('getDefaultPriceScope')->willReturn(false);
32+
$item->expects($this->once())->method('getSelectionId')->willReturn($values['selection_id']);
33+
$item->expects($this->once())->method('getWebsiteId')->willReturn($values['website_id']);
34+
$item->expects($this->once())->method('getSelectionPriceType')->willReturn($values['selection_price_type']);
35+
$item->expects($this->once())->method('getSelectionPriceValue')->willReturn($values['selection_price_value']);
36+
$item->expects($this->once())->method('getParentProductId')->willReturn($values['parent_product_id']);
37+
38+
$selection = $this->getMockBuilder(ResourceSelection::class)
39+
->disableOriginalConstructor()
40+
->onlyMethods(['getConnection', 'getTable'])
41+
->getMock();
42+
$selection->expects($this->any())
43+
->method('getTable')
44+
->with('catalog_product_bundle_selection_price')
45+
->willReturn('catalog_product_bundle_selection_price');
46+
47+
$connection = $this->createMock(AdapterInterface::class);
48+
$connection->expects($this->once())
49+
->method('insertOnDuplicate')
50+
->with(
51+
$selection->getTable('catalog_product_bundle_selection_price'),
52+
$this->callback(function ($insertValues) {
53+
return $insertValues['selection_price_type'] === 0 && $insertValues['selection_price_value'] === 0;
54+
}),
55+
['selection_price_type', 'selection_price_value']
56+
);
57+
58+
$selection->expects($this->once())->method('getConnection')->willReturn($connection);
59+
$selection->saveSelectionPrice($item);
60+
}
61+
}

dev/tests/api-functional/testsuite/Magento/Bundle/Api/ProductLinkManagementTest.php

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -87,32 +87,6 @@ public function testAddChild()
8787
$this->assertGreaterThan(0, $childId);
8888
}
8989

90-
/**
91-
* @magentoApiDataFixture Magento/Bundle/_files/product.php
92-
* @magentoApiDataFixture Magento/Catalog/_files/product_virtual.php
93-
*/
94-
public function testAddChildWithoutPriceAndPriceType()
95-
{
96-
$productSku = 'bundle-product';
97-
$children = $this->getChildren($productSku);
98-
99-
$optionId = $children[0]['option_id'];
100-
101-
$linkedProduct = [
102-
'sku' => 'virtual-product',
103-
'option_id' => $optionId,
104-
'position' => '1',
105-
'is_default' => 1,
106-
'priceType' => null,
107-
'price' => null,
108-
'qty' => 8,
109-
'can_change_quantity' => 1,
110-
];
111-
112-
$childId = $this->addChild($productSku, $optionId, $linkedProduct);
113-
$this->assertGreaterThan(0, $childId);
114-
}
115-
11690
/**
11791
* Verify empty out of stock bundle product is in stock after child has been added.
11892
*

0 commit comments

Comments
 (0)