Skip to content

Commit f57a4ef

Browse files
[EngCom] Public Pull Requests - 2.3-develop
- merged latest code from mainline branch
2 parents 32486c5 + eca9d9d commit f57a4ef

File tree

18 files changed

+163
-25
lines changed

18 files changed

+163
-25
lines changed

app/code/Magento/Catalog/Test/Unit/Ui/DataProvider/Product/Form/Modifier/AbstractModifierTest.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ protected function setUp()
6363
'getAttributes',
6464
'getStore',
6565
'getAttributeDefaultValue',
66-
'getExistsStoreValueFlag'
66+
'getExistsStoreValueFlag',
67+
'isLockedAttribute'
6768
])->getMockForAbstractClass();
6869
$this->storeMock = $this->getMockBuilder(StoreInterface::class)
6970
->setMethods(['load', 'getId', 'getConfig'])
@@ -81,9 +82,6 @@ protected function setUp()
8182
$this->arrayManagerMock->expects($this->any())
8283
->method('set')
8384
->willReturnArgument(1);
84-
$this->arrayManagerMock->expects($this->any())
85-
->method('merge')
86-
->willReturnArgument(1);
8785
$this->arrayManagerMock->expects($this->any())
8886
->method('remove')
8987
->willReturnArgument(1);

app/code/Magento/Catalog/Test/Unit/Ui/DataProvider/Product/Form/Modifier/AttributeSetTest.php

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66
namespace Magento\Catalog\Test\Unit\Ui\DataProvider\Product\Form\Modifier;
77

8+
use Magento\Catalog\Ui\DataProvider\Product\Form\Modifier\AbstractModifier;
89
use Magento\Catalog\Ui\DataProvider\Product\Form\Modifier\AttributeSet;
910
use Magento\Eav\Model\ResourceModel\Entity\Attribute\Set\CollectionFactory;
1011
use Magento\Eav\Model\ResourceModel\Entity\Attribute\Set\Collection;
@@ -84,7 +85,30 @@ protected function createModel()
8485

8586
public function testModifyMeta()
8687
{
87-
$this->assertNotEmpty($this->getModel()->modifyMeta(['test_group' => []]));
88+
$modifyMeta = $this->getModel()->modifyMeta(['test_group' => []]);
89+
$this->assertNotEmpty($modifyMeta);
90+
}
91+
92+
/**
93+
* @param bool $locked
94+
* @dataProvider modifyMetaLockedDataProvider
95+
*/
96+
public function testModifyMetaLocked($locked)
97+
{
98+
$this->productMock->expects($this->any())
99+
->method('isLockedAttribute')
100+
->willReturn($locked);
101+
$modifyMeta = $this->getModel()->modifyMeta([AbstractModifier::DEFAULT_GENERAL_PANEL => []]);
102+
$children = $modifyMeta[AbstractModifier::DEFAULT_GENERAL_PANEL]['children'];
103+
$this->assertEquals(
104+
$locked,
105+
$children['attribute_set_id']['arguments']['data']['config']['disabled']
106+
);
107+
}
108+
109+
public function modifyMetaLockedDataProvider()
110+
{
111+
return [[true], [false]];
88112
}
89113

90114
public function testModifyMetaToBeEmpty()

app/code/Magento/Catalog/Test/Unit/Ui/DataProvider/Product/Form/Modifier/CategoriesTest.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,44 @@ public function testModifyMeta()
114114
$this->assertArrayHasKey($groupCode, $this->getModel()->modifyMeta($meta));
115115
}
116116

117+
/**
118+
* @param bool $locked
119+
* @dataProvider modifyMetaLockedDataProvider
120+
*/
121+
public function testModifyMetaLocked($locked)
122+
{
123+
$groupCode = 'test_group_code';
124+
$meta = [
125+
$groupCode => [
126+
'children' => [
127+
'category_ids' => [
128+
'sortOrder' => 10,
129+
],
130+
],
131+
],
132+
];
133+
134+
$this->arrayManagerMock->expects($this->any())
135+
->method('findPath')
136+
->willReturn('path');
137+
138+
$this->productMock->expects($this->any())
139+
->method('isLockedAttribute')
140+
->willReturn($locked);
141+
142+
$this->arrayManagerMock->expects($this->any())
143+
->method('merge')
144+
->willReturnArgument(2);
145+
146+
$modifyMeta = $this->createModel()->modifyMeta($meta);
147+
$this->assertEquals($locked, $modifyMeta['arguments']['data']['config']['disabled']);
148+
}
149+
150+
public function modifyMetaLockedDataProvider()
151+
{
152+
return [[true], [false]];
153+
}
154+
117155
public function testModifyMetaWithCaching()
118156
{
119157
$this->arrayManagerMock->expects($this->exactly(2))

app/code/Magento/Catalog/Test/Unit/Ui/DataProvider/Product/Form/Modifier/EavTest.php

Lines changed: 47 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ public function testModifyData()
462462
* @param bool $productRequired
463463
* @param string|null $attrValue
464464
* @param array $expected
465-
* @return void
465+
* @param bool $locked
466466
* @covers \Magento\Catalog\Ui\DataProvider\Product\Form\Modifier\Eav::isProductExists
467467
* @covers \Magento\Catalog\Ui\DataProvider\Product\Form\Modifier\Eav::setupAttributeMeta
468468
* @dataProvider setupAttributeMetaDataProvider
@@ -471,7 +471,8 @@ public function testSetupAttributeMetaDefaultAttribute(
471471
$productId,
472472
bool $productRequired,
473473
$attrValue,
474-
array $expected
474+
array $expected,
475+
$locked = false
475476
) : void {
476477
$configPath = 'arguments/data/config';
477478
$groupCode = 'product-details';
@@ -492,6 +493,7 @@ public function testSetupAttributeMetaDefaultAttribute(
492493
];
493494

494495
$this->productMock->method('getId')->willReturn($productId);
496+
$this->productMock->expects($this->any())->method('isLockedAttribute')->willReturn($locked);
495497
$this->productAttributeMock->method('getIsRequired')->willReturn($productRequired);
496498
$this->productAttributeMock->method('getDefaultValue')->willReturn('required_value');
497499
$this->productAttributeMock->method('getAttributeCode')->willReturn('code');
@@ -520,14 +522,14 @@ public function testSetupAttributeMetaDefaultAttribute(
520522
)
521523
->willReturn($expected);
522524

523-
$this->arrayManagerMock->expects($this->once())
525+
$this->arrayManagerMock->expects($this->any())
524526
->method('merge')
525527
->with(
526528
$this->anything(),
527529
$this->anything(),
528530
$this->callback(
529531
function ($value) use ($attributeOptionsExpected) {
530-
return $value['options'] === $attributeOptionsExpected;
532+
return isset($value['options']) ? $value['options'] === $attributeOptionsExpected : true;
531533
}
532534
)
533535
)
@@ -544,6 +546,7 @@ function ($value) use ($attributeOptionsExpected) {
544546

545547
/**
546548
* @return array
549+
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
547550
*/
548551
public function setupAttributeMetaDataProvider()
549552
{
@@ -567,6 +570,26 @@ public function setupAttributeMetaDataProvider()
567570
'sortOrder' => 0,
568571
],
569572
],
573+
'default_null_prod_not_new_locked_and_required' => [
574+
'productId' => 1,
575+
'productRequired' => true,
576+
'attrValue' => 'val',
577+
'expected' => [
578+
'dataType' => null,
579+
'formElement' => null,
580+
'visible' => null,
581+
'required' => true,
582+
'notice' => null,
583+
'default' => null,
584+
'label' => new Phrase(null),
585+
'code' => 'code',
586+
'source' => 'product-details',
587+
'scopeLabel' => '',
588+
'globalScope' => false,
589+
'sortOrder' => 0,
590+
],
591+
'locked' => true,
592+
],
570593
'default_null_prod_not_new_and_not_required' => [
571594
'productId' => 1,
572595
'productRequired' => false,
@@ -605,6 +628,26 @@ public function setupAttributeMetaDataProvider()
605628
'sortOrder' => 0,
606629
],
607630
],
631+
'default_null_prod_new_locked_and_not_required' => [
632+
'productId' => null,
633+
'productRequired' => false,
634+
'attrValue' => null,
635+
'expected' => [
636+
'dataType' => null,
637+
'formElement' => null,
638+
'visible' => null,
639+
'required' => false,
640+
'notice' => null,
641+
'default' => 'required_value',
642+
'label' => new Phrase(null),
643+
'code' => 'code',
644+
'source' => 'product-details',
645+
'scopeLabel' => '',
646+
'globalScope' => false,
647+
'sortOrder' => 0,
648+
],
649+
'locked' => true,
650+
],
608651
'default_null_prod_new_and_required' => [
609652
'productId' => null,
610653
'productRequired' => false,

app/code/Magento/Catalog/Test/Unit/Ui/DataProvider/Product/Form/Modifier/GeneralTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ protected function createModel()
6060

6161
public function testModifyMeta()
6262
{
63+
$this->arrayManagerMock->expects($this->any())
64+
->method('merge')
65+
->willReturnArgument(2);
6366
$this->assertNotEmpty($this->getModel()->modifyMeta([
6467
'first_panel_code' => [
6568
'arguments' => [

app/code/Magento/Catalog/Test/Unit/Ui/DataProvider/Product/Form/Modifier/ScheduleDesignUpdateTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ protected function createModel()
2424

2525
public function testModifyMeta()
2626
{
27+
$this->arrayManagerMock->expects($this->any())
28+
->method('merge')
29+
->willReturnArgument(1);
2730
$this->assertSame([], $this->getModel()->modifyMeta([]));
2831
}
2932

app/code/Magento/Catalog/Test/Unit/Ui/DataProvider/Product/Form/Modifier/WebsitesTest.php

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,10 @@ class WebsitesTest extends AbstractModifierTest
7676

7777
protected function setUp()
7878
{
79-
$this->objectManager = new ObjectManager($this);
79+
parent::setUp();
80+
$this->productMock->expects($this->any())
81+
->method('getId')
82+
->willReturn(self::PRODUCT_ID);
8083
$this->assignedWebsites = [self::SECOND_WEBSITE_ID];
8184
$this->websiteMock = $this->getMockBuilder(\Magento\Store\Model\Website::class)
8285
->setMethods(['getId', 'getName'])
@@ -101,15 +104,9 @@ protected function setUp()
101104
$this->storeRepositoryMock = $this->getMockBuilder(\Magento\Store\Api\StoreRepositoryInterface::class)
102105
->setMethods(['getList'])
103106
->getMockForAbstractClass();
104-
$this->locatorMock = $this->getMockBuilder(\Magento\Catalog\Model\Locator\LocatorInterface::class)
105-
->setMethods(['getProduct', 'getWebsiteIds'])
106-
->getMockForAbstractClass();
107107
$this->productMock = $this->getMockBuilder(\Magento\Catalog\Api\Data\ProductInterface::class)
108108
->setMethods(['getId'])
109109
->getMockForAbstractClass();
110-
$this->locatorMock->expects($this->any())
111-
->method('getProduct')
112-
->willReturn($this->productMock);
113110
$this->locatorMock->expects($this->any())
114111
->method('getWebsiteIds')
115112
->willReturn($this->assignedWebsites);
@@ -148,9 +145,6 @@ protected function setUp()
148145
$this->storeRepositoryMock->expects($this->any())
149146
->method('getList')
150147
->willReturn([$this->storeViewMock]);
151-
$this->productMock->expects($this->any())
152-
->method('getId')
153-
->willReturn(self::PRODUCT_ID);
154148
$this->secondWebsiteMock->expects($this->any())
155149
->method('getId')
156150
->willReturn($this->assignedWebsites[0]);

app/code/Magento/Catalog/Ui/DataProvider/Product/Form/Modifier/AdvancedPricing.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,8 @@ private function getTierPriceStructure($tierPricePath)
432432
'dndConfig' => [
433433
'enabled' => false,
434434
],
435-
'disabled' => false,
435+
'disabled' =>
436+
$this->arrayManager->get($tierPricePath . '/arguments/data/config/disabled', $this->meta),
436437
'required' => false,
437438
'sortOrder' =>
438439
$this->arrayManager->get($tierPricePath . '/arguments/data/config/sortOrder', $this->meta),

app/code/Magento/Catalog/Ui/DataProvider/Product/Form/Modifier/AttributeSet.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ public function modifyMeta(array $meta)
108108
self::ATTRIBUTE_SET_FIELD_ORDER
109109
),
110110
'multiple' => false,
111+
'disabled' => $this->locator->getProduct()->isLockedAttribute('attribute_set_id'),
111112
];
112113
}
113114

app/code/Magento/Catalog/Ui/DataProvider/Product/Form/Modifier/Categories.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@ protected function customizeCategoriesField(array $meta)
228228
'componentType' => 'container',
229229
'component' => 'Magento_Ui/js/form/components/group',
230230
'scopeLabel' => __('[GLOBAL]'),
231+
'disabled' => $this->locator->getProduct()->isLockedAttribute($fieldCode),
231232
],
232233
],
233234
],

0 commit comments

Comments
 (0)