Skip to content

Commit 1a41822

Browse files
committed
ACP2E-2978: Saving product by admin user with different role scope overwrites/deletes existing Related product information in the product
1 parent 797e547 commit 1a41822

File tree

1 file changed

+45
-5
lines changed
  • app/code/Magento/Catalog/Test/Unit/Controller/Adminhtml/Product/Initialization

1 file changed

+45
-5
lines changed

app/code/Magento/Catalog/Test/Unit/Controller/Adminhtml/Product/Initialization/HelperTest.php

Lines changed: 45 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ protected function setUp(): void
151151
->disableOriginalConstructor()
152152
->getMockForAbstractClass();
153153
$productExtensionAttributes = $this->getMockBuilder(ProductExtensionInterface::class)
154-
->addMethods(['getCategoryLinks', 'setCategoryLinks'])
154+
->onlyMethods(['getCategoryLinks', 'setCategoryLinks'])
155155
->getMockForAbstractClass();
156156
$this->productMock->setExtensionAttributes($productExtensionAttributes);
157157

@@ -161,9 +161,7 @@ protected function setUp(): void
161161
->getMock();
162162
$this->productLinksMock = $this->createMock(ProductLinks::class);
163163
$this->linkTypeProviderMock = $this->createMock(LinkTypeProvider::class);
164-
$this->productLinksMock->expects($this->any())
165-
->method('initializeLinks')
166-
->willReturn($this->productMock);
164+
167165
$this->attributeFilterMock = $this->createMock(AttributeFilter::class);
168166
$this->localeFormatMock = $this->createMock(Format::class);
169167

@@ -229,8 +227,17 @@ public function testInitialize(
229227
$links,
230228
$linkTypes,
231229
$expectedLinks,
232-
$tierPrice = null
230+
$tierPrice = null,
231+
$isReadOnlyRelatedItems = null,
232+
$isReadOnlyUpSellItems = null,
233+
$ignoreLinksFlag = false
233234
) {
235+
$this->productMock->setData('related_readonly', $isReadOnlyRelatedItems);
236+
$this->productMock->setData('upsell_readonly', $isReadOnlyUpSellItems);
237+
$this->productLinksMock->expects($this->any())
238+
->method('initializeLinks')
239+
->willReturn($this->productMock);
240+
234241
$this->linkTypeProviderMock->expects($this->once())
235242
->method('getItems')
236243
->willReturn($this->assembleLinkTypes($linkTypes));
@@ -346,6 +353,11 @@ function () {
346353

347354
$productLinks = $this->productMock->getProductLinks();
348355
$this->assertCount(count($expectedLinks), $productLinks);
356+
if ($ignoreLinksFlag) {
357+
$this->assertTrue($this->productMock->getDataByKey('ignore_links_flag'));
358+
} else {
359+
$this->assertFalse($this->productMock->getDataByKey('ignore_links_flag'));
360+
}
349361
$resultLinks = [];
350362

351363
$this->assertEquals($tierPrice ?: [], $this->productMock->getData('tier_price'));
@@ -559,6 +571,34 @@ public static function initializeDataProvider()
559571
['type' => 'related', 'linked_product_sku' => 'Test'],
560572
],
561573
],
574+
575+
// readonly links
576+
[
577+
'single_store' => false,
578+
'website_ids' => ['1' => 1, '2' => 2],
579+
'expected_website_ids' => ['1' => 1, '2' => 2],
580+
'links' => [
581+
'related' => [
582+
0 => [
583+
'id' => 1,
584+
'thumbnail' => 'http://magento.dev/media/no-image.jpg',
585+
'name' => 'Test',
586+
'status' => 'Enabled',
587+
'attribute_set' => 'Default',
588+
'sku' => 'Test',
589+
'price' => 1.00,
590+
'position' => 1,
591+
'record_id' => 1,
592+
],
593+
],
594+
],
595+
'linkTypes' => ['related', 'upsell', 'crosssell'],
596+
'expected_links' => [],
597+
'tierPrice' => [],
598+
true,
599+
true,
600+
true
601+
],
562602
];
563603
}
564604

0 commit comments

Comments
 (0)