38 $this->linkTypeFactoryMock = $this->createPartialMock(
39 \
Magento\Catalog\Api\Data\ProductLinkTypeInterfaceFactory::class,
42 $this->linkAttributeFactoryMock = $this->createPartialMock(
43 \
Magento\Catalog\Api\Data\ProductLinkAttributeInterfaceFactory::class,
46 $this->linkFactoryMock = $this->createPartialMock(
51 'test_product_link_1' =>
'test_code_1',
52 'test_product_link_2' =>
'test_code_2',
53 'test_product_link_3' =>
'test_code_3',
55 $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
59 'linkTypeFactory' => $this->linkTypeFactoryMock,
60 'linkAttributeFactory' => $this->linkAttributeFactoryMock,
61 'linkFactory' => $this->linkFactoryMock,
62 'linkTypes' => $this->linkTypes
74 foreach ($this->linkTypes as
$type => $typeCode) {
76 $linkTypeMock = $this->createMock(\
Magento\Catalog\Api\Data\ProductLinkTypeInterface::class);
77 $linkTypeMock->expects($this->once())
81 $linkTypeMock->expects($this->once())
85 $linkTypeMocks[] = $linkTypeMock;
86 $expectedResult[] = $linkTypeMock;
88 $this->linkTypeFactoryMock->expects($this->exactly(3))
90 ->will($this->onConsecutiveCalls($linkTypeMocks[0], $linkTypeMocks[1], $linkTypeMocks[2]));
91 $this->assertEquals($expectedResult, $this->model->getItems());
100 [
'code' =>
'test_code_1',
'type' =>
'test_type_1'],
102 $linkAttributeMock = $this->createMock(\
Magento\Catalog\Api\Data\ProductLinkAttributeInterface::class);
103 $linkAttributeMock->expects($this->once())
107 $linkAttributeMock->expects($this->once())
114 $linkMock = $this->createPartialMock(\
Magento\Catalog\Model\
Product\Link::class, [
'getAttributes']);
115 $linkMock->expects($this->once())->method(
'getAttributes')->willReturn(
$attributes);
116 $this->linkFactoryMock->expects($this->once())->method(
'create')->with($typeId)->willReturn($linkMock);
117 $this->linkAttributeFactoryMock->expects($this->once())->method(
'create')->willReturn($linkAttributeMock);
118 $this->assertEquals($expectedResult, $this->model->getItemAttributes(
$type));
127 [
'test_product_link_2', [
'data' => [
'link_type_id' =>
'test_code_2']]],
128 [
'null_product', [
'data' => [
'link_type_id' =>
null]]]
testGetItemAttributes($type, $typeId)
getItemAttributesDataProvider()
$linkAttributeFactoryMock