@@ -34,6 +34,11 @@ class CopierTest extends \PHPUnit_Framework_TestCase
34
34
*/
35
35
protected $ productMock ;
36
36
37
+ /**
38
+ * @var \PHPUnit_Framework_MockObject_MockObject
39
+ */
40
+ protected $ metadata ;
41
+
37
42
protected function setUp ()
38
43
{
39
44
$ this ->copyConstructorMock = $ this ->getMock ('\Magento\Catalog\Model\Product\CopyConstructorInterface ' );
@@ -54,22 +59,33 @@ protected function setUp()
54
59
$ this ->optionRepositoryMock ;
55
60
$ this ->productMock = $ this ->getMock ('\Magento\Catalog\Model\Product ' , [], [], '' , false );
56
61
$ this ->productMock ->expects ($ this ->any ())->method ('getEntityId ' )->willReturn (1 );
57
- $ this ->productMock ->expects ($ this ->any ())->method ('getData ' )->will ($ this ->returnValue ('product data ' ));
58
62
63
+ $ this ->metadata = $ this ->getMockBuilder ('Magento\Framework\EntityManager\EntityMetadata ' )
64
+ ->disableOriginalConstructor ()
65
+ ->getMock ();
66
+ $ metadataPool = $ this ->getMockBuilder ('Magento\Framework\EntityManager\MetadataPool ' )
67
+ ->disableOriginalConstructor ()
68
+ ->getMock ();
69
+ $ metadataPool ->expects ($ this ->any ())->method ('getMetadata ' )->willReturn ($ this ->metadata );
59
70
$ this ->_model = new Copier (
60
71
$ this ->copyConstructorMock ,
61
72
$ this ->productFactoryMock
62
73
);
63
74
64
75
$ this ->setProperties ($ this ->_model , [
65
- 'optionRepository ' => $ this ->optionRepositoryMock
76
+ 'optionRepository ' => $ this ->optionRepositoryMock ,
77
+ 'metadataPool ' => $ metadataPool ,
66
78
]);
67
79
}
68
80
69
81
public function testCopy ()
70
82
{
71
83
$ this ->productMock ->expects ($ this ->atLeastOnce ())->method ('getWebsiteIds ' );
72
84
$ this ->productMock ->expects ($ this ->atLeastOnce ())->method ('getCategoryIds ' );
85
+ $ this ->productMock ->expects ($ this ->any ())->method ('getData ' )->willReturnMap ([
86
+ ['' , null , 'product data ' ],
87
+ ['linkField ' , null , '1 ' ],
88
+ ]);
73
89
74
90
$ resourceMock = $ this ->getMock ('\Magento\Catalog\Model\ResourceModel\Product ' , [], [], '' , false );
75
91
$ this ->productMock ->expects ($ this ->once ())->method ('getResource ' )->will ($ this ->returnValue ($ resourceMock ));
@@ -79,6 +95,7 @@ public function testCopy()
79
95
[
80
96
'__wakeup ' ,
81
97
'setData ' ,
98
+ 'getData ' ,
82
99
'setIsDuplicate ' ,
83
100
'setOriginalId ' ,
84
101
'setStatus ' ,
@@ -121,8 +138,12 @@ public function testCopy()
121
138
$ duplicateMock ->expects ($ this ->once ())->method ('getUrlKey ' )->willReturn ('urk-key-1 ' );
122
139
$ duplicateMock ->expects ($ this ->once ())->method ('setUrlKey ' )->with ('urk-key-2 ' );
123
140
$ duplicateMock ->expects ($ this ->once ())->method ('save ' );
124
- $ duplicateMock ->expects ($ this ->any ())->method ('getEntityId ' )->willReturn (2 );
125
- $ this ->optionRepositoryMock ->expects ($ this ->once ())
141
+
142
+ $ this ->metadata ->expects ($ this ->any ())->method ('getLinkField ' )->willReturn ('linkField ' );
143
+
144
+ $ duplicateMock ->expects ($ this ->any ())->method ('getData ' )->willReturnMap ([
145
+ ['linkField ' , null , '2 ' ],
146
+ ]); $ this ->optionRepositoryMock ->expects ($ this ->once ())
126
147
->method ('duplicate ' )
127
148
->with ($ this ->productMock , $ duplicateMock );
128
149
$ resourceMock ->expects ($ this ->once ())->method ('duplicate ' )->with (1 , 2 );
0 commit comments