Skip to content

Commit 07313e6

Browse files
author
Serhii Balko
committed
Merge remote-tracking branch 'origin/MC-39276' into 2.4-develop-pr48
2 parents 0918dad + 0073eb3 commit 07313e6

File tree

2 files changed

+176
-7
lines changed

2 files changed

+176
-7
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
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+
namespace Magento\Bundle\Test\Unit\Ui\DataProvider\Product\Form\Modifier;
9+
10+
use Magento\Bundle\Model\Product\Attribute\Source\Shipment\Type as ShipmentType;
11+
use Magento\Bundle\Ui\DataProvider\Product\Form\Modifier\BundlePanel;
12+
use Magento\Bundle\Ui\DataProvider\Product\Form\Modifier\BundlePrice;
13+
use Magento\Catalog\Api\Data\ProductInterface;
14+
use Magento\Catalog\Model\Locator\LocatorInterface;
15+
use Magento\Framework\Stdlib\ArrayManager;
16+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
17+
use Magento\Framework\UrlInterface;
18+
use PHPUnit\Framework\MockObject\MockObject;
19+
use PHPUnit\Framework\TestCase;
20+
21+
/**
22+
* Test for bundle panel
23+
*/
24+
class BundlePanelTest extends TestCase
25+
{
26+
/**
27+
* @var UrlInterface|MockObject
28+
*/
29+
private $urlBuilder;
30+
31+
/**
32+
* @var ShipmentType|MockObject
33+
*/
34+
private $shipmentType;
35+
36+
/**
37+
* @var LocatorInterface|MockObject
38+
*/
39+
private $locatorMock;
40+
41+
/**
42+
* @var ProductInterface|MockObject
43+
*/
44+
private $productMock;
45+
46+
/**
47+
* @var ArrayManager|MockObject
48+
*/
49+
private $arrayManagerMock;
50+
51+
/**
52+
* @var BundlePanel
53+
*/
54+
private $bundlePanelModel;
55+
56+
/**
57+
* @return void
58+
*/
59+
protected function setUp(): void
60+
{
61+
$this->objectManager = new ObjectManager($this);
62+
$this->arrayManagerMock = $this->getMockBuilder(ArrayManager::class)
63+
->disableOriginalConstructor()
64+
->getMock();
65+
$this->arrayManagerMock->expects($this->any())
66+
->method('get')
67+
->willReturn([]);
68+
$this->urlBuilder = $this->getMockBuilder(UrlInterface::class)
69+
->getMockForAbstractClass();
70+
$this->shipmentType = $this->getMockBuilder(ShipmentType::class)
71+
->getMockForAbstractClass();
72+
$this->productMock = $this->getMockBuilder(ProductInterface::class)
73+
->addMethods(['getStoreId'])
74+
->getMockForAbstractClass();
75+
$this->productMock->method('getId')
76+
->willReturn(true);
77+
$this->productMock->method('getStoreId')
78+
->willReturn(0);
79+
$this->locatorMock = $this->getMockBuilder(LocatorInterface::class)
80+
->onlyMethods(['getProduct'])
81+
->getMockForAbstractClass();
82+
$this->locatorMock->method('getProduct')
83+
->willReturn($this->productMock);
84+
85+
$this->bundlePanelModel = $this->objectManager->getObject(
86+
BundlePanel::class,
87+
[
88+
'locator' => $this->locatorMock,
89+
'urlBuilder' => $this->urlBuilder,
90+
'shipmentType' => $this->shipmentType,
91+
'arrayManager' => $this->arrayManagerMock,
92+
]
93+
);
94+
}
95+
96+
/**
97+
* Test for modify meta
98+
*
99+
* @param string $shipmentTypePath
100+
* @param string $dataScope
101+
*
102+
* @return void
103+
* @dataProvider getDataModifyMeta
104+
*/
105+
public function testModifyMeta(string $shipmentTypePath, string $dataScope): void
106+
{
107+
$sourceMeta = [
108+
'bundle-items' => [
109+
'children' => [
110+
BundlePrice::CODE_PRICE_TYPE => []
111+
]
112+
]
113+
];
114+
$this->arrayManagerMock->method('findPath')
115+
->willReturnMap(
116+
[
117+
[
118+
BundlePanel::CODE_SHIPMENT_TYPE,
119+
[],
120+
null,
121+
'children',
122+
ArrayManager::DEFAULT_PATH_DELIMITER,
123+
$shipmentTypePath
124+
],
125+
]
126+
);
127+
$this->arrayManagerMock->method('merge')
128+
->willReturn([]);
129+
$this->arrayManagerMock->method('remove')
130+
->willReturn([]);
131+
$this->arrayManagerMock->method('set')
132+
->willReturn([]);
133+
$this->arrayManagerMock->expects($this->at(12))
134+
->method('merge')
135+
->with(
136+
$shipmentTypePath . BundlePanel::META_CONFIG_PATH,
137+
[],
138+
[
139+
'dataScope' => $dataScope,
140+
'validation' => [
141+
'required-entry' => false
142+
]
143+
]
144+
);
145+
$this->bundlePanelModel->modifyMeta($sourceMeta);
146+
}
147+
148+
/**
149+
* Data provider for modify meta test
150+
*
151+
* @return string[][]
152+
*/
153+
public function getDataModifyMeta(): array
154+
{
155+
return [
156+
[
157+
'bundle-items/children',
158+
'data.product.shipment_type'
159+
],
160+
[
161+
'someAttrGroup/children',
162+
'shipment_type'
163+
],
164+
];
165+
}
166+
}

app/code/Magento/Bundle/Ui/DataProvider/Product/Form/Modifier/BundlePanel.php

+10-7
Original file line numberDiff line numberDiff line change
@@ -252,16 +252,19 @@ public function modifyData(array $data)
252252
*/
253253
private function modifyShipmentType(array $meta)
254254
{
255+
$actualPath = $this->arrayManager->findPath(
256+
static::CODE_SHIPMENT_TYPE,
257+
$meta,
258+
null,
259+
'children'
260+
);
261+
255262
$meta = $this->arrayManager->merge(
256-
$this->arrayManager->findPath(
257-
static::CODE_SHIPMENT_TYPE,
258-
$meta,
259-
null,
260-
'children'
261-
) . static::META_CONFIG_PATH,
263+
$actualPath . static::META_CONFIG_PATH,
262264
$meta,
263265
[
264-
'dataScope' => 'data.product.shipment_type',
266+
'dataScope' => stripos($actualPath, self::CODE_BUNDLE_DATA) === 0
267+
? 'data.product.shipment_type' : 'shipment_type',
265268
'validation' => [
266269
'required-entry' => false
267270
]

0 commit comments

Comments
 (0)