Skip to content

Commit 7bc31e4

Browse files
committed
MAGETWO-70993: Revert MAGETWO-57153 from 2.1.8 release
1 parent c849b07 commit 7bc31e4

File tree

1 file changed

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

1 file changed

+11
-251
lines changed

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

Lines changed: 11 additions & 251 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@
1919
use Magento\Catalog\Api\Data\ProductCustomOptionInterfaceFactory;
2020
use Magento\Catalog\Api\Data\ProductCustomOptionInterface;
2121
use Magento\Catalog\Model\Product\Initialization\Helper\ProductLinks;
22-
use Magento\Catalog\Model\Product\LinkTypeProvider;
23-
use Magento\Catalog\Api\Data\ProductLinkTypeInterface;
24-
use Magento\Catalog\Model\ProductLink\Link as ProductLink;
2522

2623
/**
2724
* Class HelperTest
@@ -107,11 +104,6 @@ class HelperTest extends \PHPUnit_Framework_TestCase
107104
*/
108105
protected $linkResolverMock;
109106

110-
/**
111-
* @var \Magento\Catalog\Model\Product\LinkTypeProvider|\PHPUnit_Framework_MockObject_MockObject
112-
*/
113-
protected $linkTypeProviderMock;
114-
115107
/**
116108
* @var ProductLinks|\PHPUnit_Framework_MockObject_MockObject
117109
*/
@@ -121,7 +113,6 @@ protected function setUp()
121113
{
122114
$this->objectManager = new ObjectManager($this);
123115
$this->productLinkFactoryMock = $this->getMockBuilder(ProductLinkInterfaceFactory::class)
124-
->setMethods(['create'])
125116
->disableOriginalConstructor()
126117
->getMock();
127118
$this->productRepositoryMock = $this->getMockBuilder(ProductRepository::class)
@@ -159,6 +150,7 @@ protected function setUp()
159150
'__sleep',
160151
'__wakeup',
161152
'getSku',
153+
'getProductLinks',
162154
'getWebsiteIds'
163155
])
164156
->disableOriginalConstructor()
@@ -176,9 +168,6 @@ protected function setUp()
176168
$this->productLinksMock->expects($this->any())
177169
->method('initializeLinks')
178170
->willReturn($this->productMock);
179-
$this->linkTypeProviderMock = $this->getMockBuilder(LinkTypeProvider::class)
180-
->disableOriginalConstructor()
181-
->getMock();
182171

183172
$this->helper = $this->objectManager->getObject(Helper::class, [
184173
'request' => $this->requestMock,
@@ -189,7 +178,6 @@ protected function setUp()
189178
'customOptionFactory' => $this->customOptionFactoryMock,
190179
'productLinkFactory' => $this->productLinkFactoryMock,
191180
'productRepository' => $this->productRepositoryMock,
192-
'linkTypeProvider' => $this->linkTypeProviderMock,
193181
]);
194182

195183
$this->linkResolverMock = $this->getMockBuilder(\Magento\Catalog\Model\Product\Link\Resolver::class)
@@ -202,10 +190,10 @@ protected function setUp()
202190
}
203191

204192
/**
193+
* @covers \Magento\Catalog\Controller\Adminhtml\Product\Initialization\Helper::initialize
205194
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
206-
* @param array $links
207195
*/
208-
private function assembleProductMock($links = [])
196+
public function testInitialize()
209197
{
210198
$this->customOptionMock->expects($this->once())
211199
->method('setProductSku');
@@ -241,6 +229,9 @@ private function assembleProductMock($links = [])
241229
$attributeDate->expects($this->any())
242230
->method('getBackend')
243231
->willReturn($attributeDateBackEnd);
232+
$this->productMock->expects($this->any())
233+
->method('getProductLinks')
234+
->willReturn([]);
244235
$attributeNonDateBackEnd->expects($this->any())
245236
->method('getType')
246237
->willReturn('non-datetime');
@@ -263,7 +254,7 @@ private function assembleProductMock($links = [])
263254
->method('getPost')
264255
->with('use_default')
265256
->willReturn($useDefaults);
266-
$this->linkResolverMock->expects($this->once())->method('getLinks')->willReturn($links);
257+
$this->linkResolverMock->expects($this->once())->method('getLinks')->willReturn([]);
267258
$this->stockFilterMock->expects($this->once())
268259
->method('filter')
269260
->with(['stock_data'])
@@ -275,6 +266,9 @@ private function assembleProductMock($links = [])
275266
$this->productMock->expects($this->once())
276267
->method('unlockAttribute')
277268
->with('media');
269+
$this->productMock->expects($this->any())
270+
->method('getProductLinks')
271+
->willReturn([]);
278272
$this->productMock->expects($this->once())
279273
->method('lockAttribute')
280274
->with('media');
@@ -289,7 +283,7 @@ private function assembleProductMock($links = [])
289283
$this->productMock->expects($this->once())
290284
->method('addData')
291285
->with($productData);
292-
$this->productMock->expects($this->any())
286+
$this->productMock->expects($this->once())
293287
->method('getSku')
294288
->willReturn('sku');
295289
$this->productMock->expects($this->any())
@@ -303,193 +297,10 @@ private function assembleProductMock($links = [])
303297
$this->productMock->expects($this->once())
304298
->method('setOptions')
305299
->with([$this->customOptionMock]);
306-
}
307-
308-
/**
309-
* @covers \Magento\Catalog\Controller\Adminhtml\Product\Initialization\Helper::initialize
310-
*/
311-
public function testInitialize()
312-
{
313-
$this->assembleProductMock();
314-
$this->linkTypeProviderMock->expects($this->once())
315-
->method('getItems')
316-
->willReturn($this->assembleLinkTypes(['related', 'upsell', 'crosssell']));
317300

318301
$this->assertEquals($this->productMock, $this->helper->initialize($this->productMock));
319302
}
320303

321-
/**
322-
* @covers \Magento\Catalog\Controller\Adminhtml\Product\Initialization\Helper::initialize
323-
* @dataProvider initializeWithLinksDataProvider
324-
*/
325-
public function testInitializeWithLinks($links, $linkTypes, $expectedLinks)
326-
{
327-
$this->productLinkFactoryMock->expects($this->any())
328-
->method('create')
329-
->willReturnCallback(function () {
330-
return $this->getMockBuilder(ProductLink::class)
331-
->setMethods(null)
332-
->disableOriginalConstructor()
333-
->getMock();
334-
});
335-
336-
$this->linkTypeProviderMock->expects($this->once())
337-
->method('getItems')
338-
->willReturn($this->assembleLinkTypes($linkTypes));
339-
340-
$this->assembleProductRepositoryMock($links);
341-
$this->assembleProductMock($links);
342-
343-
$this->assertEquals($this->productMock, $this->helper->initialize($this->productMock));
344-
345-
$productLinks = $this->productMock->getProductLinks();
346-
$this->assertCount(count($expectedLinks), $productLinks);
347-
$resultLinks = [];
348-
349-
foreach ($productLinks as $link) {
350-
$this->assertInstanceOf(ProductLink::class, $link);
351-
$this->assertEquals('sku', $link->getSku());
352-
$resultLinks[] = ['type' => $link->getLinkType(), 'linked_product_sku' => $link->getLinkedProductSku()];
353-
}
354-
355-
$this->assertEquals($expectedLinks, $resultLinks);
356-
}
357-
358-
/**
359-
* @return array
360-
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
361-
*/
362-
public function initializeWithLinksDataProvider()
363-
{
364-
return [
365-
// No links
366-
[
367-
'links' => [],
368-
'linkTypes' => ['related', 'upsell', 'crosssell'],
369-
'expected_links' => [],
370-
],
371-
372-
// Related links
373-
[
374-
'links' => [
375-
'related' => [
376-
0 => [
377-
'id' => 1,
378-
'thumbnail' => 'http://magento.dev/media/no-image.jpg',
379-
'name' => 'Test',
380-
'status' => 'Enabled',
381-
'attribute_set' => 'Default',
382-
'sku' => 'Test',
383-
'price' => 1.00,
384-
'position' => 1,
385-
'record_id' => 1,
386-
]
387-
]
388-
],
389-
'linkTypes' => ['related', 'upsell', 'crosssell'],
390-
'expected_links' => [
391-
['type' => 'related', 'linked_product_sku' => 'Test'],
392-
],
393-
],
394-
395-
// Custom link
396-
[
397-
'links' => [
398-
'customlink' => [
399-
0 => [
400-
'id' => 4,
401-
'thumbnail' => 'http://magento.dev/media/no-image.jpg',
402-
'name' => 'Test Custom',
403-
'status' => 'Enabled',
404-
'attribute_set' => 'Default',
405-
'sku' => 'Testcustom',
406-
'price' => 1.00,
407-
'position' => 1,
408-
'record_id' => 1,
409-
],
410-
],
411-
],
412-
'linkTypes' => ['related', 'upsell', 'crosssell', 'customlink'],
413-
'expected_links' => [
414-
['type' => 'customlink', 'linked_product_sku' => 'Testcustom'],
415-
],
416-
],
417-
418-
// Both links
419-
[
420-
'links' => [
421-
'related' => [
422-
0 => [
423-
'id' => 1,
424-
'thumbnail' => 'http://magento.dev/media/no-image.jpg',
425-
'name' => 'Test',
426-
'status' => 'Enabled',
427-
'attribute_set' => 'Default',
428-
'sku' => 'Test',
429-
'price' => 1.00,
430-
'position' => 1,
431-
'record_id' => 1,
432-
],
433-
],
434-
'customlink' => [
435-
0 => [
436-
'id' => 4,
437-
'thumbnail' => 'http://magento.dev/media/no-image.jpg',
438-
'name' => 'Test Custom',
439-
'status' => 'Enabled',
440-
'attribute_set' => 'Default',
441-
'sku' => 'Testcustom',
442-
'price' => 2.00,
443-
'position' => 2,
444-
'record_id' => 1,
445-
],
446-
],
447-
],
448-
'linkTypes' => ['related', 'upsell', 'crosssell', 'customlink'],
449-
'expected_links' => [
450-
['type' => 'related', 'linked_product_sku' => 'Test'],
451-
['type' => 'customlink', 'linked_product_sku' => 'Testcustom'],
452-
],
453-
],
454-
455-
// Undefined link type
456-
[
457-
'links' => [
458-
'related' => [
459-
0 => [
460-
'id' => 1,
461-
'thumbnail' => 'http://magento.dev/media/no-image.jpg',
462-
'name' => 'Test',
463-
'status' => 'Enabled',
464-
'attribute_set' => 'Default',
465-
'sku' => 'Test',
466-
'price' => 1.00,
467-
'position' => 1,
468-
'record_id' => 1,
469-
],
470-
],
471-
'customlink' => [
472-
0 => [
473-
'id' => 4,
474-
'thumbnail' => 'http://magento.dev/media/no-image.jpg',
475-
'name' => 'Test Custom',
476-
'status' => 'Enabled',
477-
'attribute_set' => 'Default',
478-
'sku' => 'Testcustom',
479-
'price' => 2.00,
480-
'position' => 2,
481-
'record_id' => 1,
482-
],
483-
],
484-
],
485-
'linkTypes' => ['related', 'upsell', 'crosssell'],
486-
'expected_links' => [
487-
['type' => 'related', 'linked_product_sku' => 'Test'],
488-
],
489-
],
490-
];
491-
}
492-
493304
/**
494305
* Data provider for testMergeProductOptions
495306
*
@@ -579,55 +390,4 @@ public function testMergeProductOptions($productOptions, $defaultOptions, $expec
579390
$result = $this->helper->mergeProductOptions($productOptions, $defaultOptions);
580391
$this->assertEquals($expectedResults, $result);
581392
}
582-
583-
/**
584-
* @param array $types
585-
* @return array
586-
*/
587-
private function assembleLinkTypes($types)
588-
{
589-
$linkTypes = [];
590-
$linkTypeCode = 1;
591-
592-
foreach ($types as $typeName) {
593-
$linkType = $this->getMock(ProductLinkTypeInterface::class);
594-
$linkType->method('getCode')->willReturn($linkTypeCode++);
595-
$linkType->method('getName')->willReturn($typeName);
596-
597-
$linkTypes[] = $linkType;
598-
}
599-
600-
return $linkTypes;
601-
}
602-
603-
/**
604-
* @param array $links
605-
*/
606-
private function assembleProductRepositoryMock($links)
607-
{
608-
$repositoryReturnMap = [];
609-
610-
foreach ($links as $linkType) {
611-
foreach ($linkType as $link) {
612-
$mockLinkedProduct = $this->getMockBuilder(Product::class)
613-
->disableOriginalConstructor()
614-
->getMock();
615-
616-
$mockLinkedProduct->expects($this->any())
617-
->method('getId')
618-
->willReturn($link['id']);
619-
620-
$mockLinkedProduct->expects($this->any())
621-
->method('getSku')
622-
->willReturn($link['sku']);
623-
624-
// Even optional arguments need to be provided for returnMapValue
625-
$repositoryReturnMap[] = [$link['id'], false, null, false, $mockLinkedProduct];
626-
}
627-
}
628-
629-
$this->productRepositoryMock->expects($this->any())
630-
->method('getById')
631-
->will($this->returnValueMap($repositoryReturnMap));
632-
}
633393
}

0 commit comments

Comments
 (0)