@@ -151,7 +151,7 @@ protected function setUp(): void
151
151
->disableOriginalConstructor ()
152
152
->getMockForAbstractClass ();
153
153
$ productExtensionAttributes = $ this ->getMockBuilder (ProductExtensionInterface::class)
154
- ->addMethods (['getCategoryLinks ' , 'setCategoryLinks ' ])
154
+ ->onlyMethods (['getCategoryLinks ' , 'setCategoryLinks ' ])
155
155
->getMockForAbstractClass ();
156
156
$ this ->productMock ->setExtensionAttributes ($ productExtensionAttributes );
157
157
@@ -161,9 +161,7 @@ protected function setUp(): void
161
161
->getMock ();
162
162
$ this ->productLinksMock = $ this ->createMock (ProductLinks::class);
163
163
$ this ->linkTypeProviderMock = $ this ->createMock (LinkTypeProvider::class);
164
- $ this ->productLinksMock ->expects ($ this ->any ())
165
- ->method ('initializeLinks ' )
166
- ->willReturn ($ this ->productMock );
164
+
167
165
$ this ->attributeFilterMock = $ this ->createMock (AttributeFilter::class);
168
166
$ this ->localeFormatMock = $ this ->createMock (Format::class);
169
167
@@ -229,8 +227,17 @@ public function testInitialize(
229
227
$ links ,
230
228
$ linkTypes ,
231
229
$ expectedLinks ,
232
- $ tierPrice = null
230
+ $ tierPrice = null ,
231
+ $ isReadOnlyRelatedItems = null ,
232
+ $ isReadOnlyUpSellItems = null ,
233
+ $ ignoreLinksFlag = false
233
234
) {
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
+
234
241
$ this ->linkTypeProviderMock ->expects ($ this ->once ())
235
242
->method ('getItems ' )
236
243
->willReturn ($ this ->assembleLinkTypes ($ linkTypes ));
@@ -346,6 +353,11 @@ function () {
346
353
347
354
$ productLinks = $ this ->productMock ->getProductLinks ();
348
355
$ 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
+ }
349
361
$ resultLinks = [];
350
362
351
363
$ this ->assertEquals ($ tierPrice ?: [], $ this ->productMock ->getData ('tier_price ' ));
@@ -559,6 +571,34 @@ public static function initializeDataProvider()
559
571
['type ' => 'related ' , 'linked_product_sku ' => 'Test ' ],
560
572
],
561
573
],
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
+ ],
562
602
];
563
603
}
564
604
0 commit comments