@@ -103,8 +103,44 @@ public function testCopy()
103
103
['linkField ' , null , '1 ' ],
104
104
]);
105
105
106
- $ resourceMock = $ this ->createMock (\Magento \Catalog \Model \ResourceModel \Product::class);
107
- $ this ->productMock ->expects ($ this ->once ())->method ('getResource ' )->will ($ this ->returnValue ($ resourceMock ));
106
+ $ entityMock = $ this ->getMockForAbstractClass (
107
+ \Magento \Eav \Model \Entity \AbstractEntity::class,
108
+ [],
109
+ '' ,
110
+ false ,
111
+ true ,
112
+ true ,
113
+ ['checkAttributeUniqueValue ' ]
114
+ );
115
+ $ entityMock ->expects ($ this ->any ())
116
+ ->method ('checkAttributeUniqueValue ' )
117
+ ->willReturn (true );
118
+
119
+ $ attributeMock = $ this ->getMockForAbstractClass (
120
+ \Magento \Eav \Model \Entity \Attribute \AbstractAttribute::class,
121
+ [],
122
+ '' ,
123
+ false ,
124
+ true ,
125
+ true ,
126
+ ['getEntity ' ]
127
+ );
128
+ $ attributeMock ->expects ($ this ->any ())
129
+ ->method ('getEntity ' )
130
+ ->willReturn ($ entityMock );
131
+
132
+ $ resourceMock = $ this ->getMockBuilder (\Magento \Catalog \Model \ResourceModel \Product::class)
133
+ ->disableOriginalConstructor ()
134
+ ->setMethods (['getAttributeRawValue ' , 'duplicate ' , 'getAttribute ' ])
135
+ ->getMock ();
136
+ $ resourceMock ->expects ($ this ->any ())
137
+ ->method ('getAttributeRawValue ' )
138
+ ->willReturn ('urk-key-1 ' );
139
+ $ resourceMock ->expects ($ this ->any ())
140
+ ->method ('getAttribute ' )
141
+ ->willReturn ($ attributeMock );
142
+
143
+ $ this ->productMock ->expects ($ this ->any ())->method ('getResource ' )->will ($ this ->returnValue ($ resourceMock ));
108
144
109
145
$ duplicateMock = $ this ->createPartialMock (
110
146
Product::class,
@@ -119,11 +155,11 @@ public function testCopy()
119
155
'setCreatedAt ' ,
120
156
'setUpdatedAt ' ,
121
157
'setId ' ,
122
- 'setStoreId ' ,
123
158
'getEntityId ' ,
124
159
'save ' ,
125
160
'setUrlKey ' ,
126
- 'getUrlKey ' ,
161
+ 'setStoreId ' ,
162
+ 'getStoreIds ' ,
127
163
]
128
164
);
129
165
$ this ->productFactoryMock ->expects ($ this ->once ())->method ('create ' )->will ($ this ->returnValue ($ duplicateMock ));
@@ -138,27 +174,22 @@ public function testCopy()
138
174
)->with (
139
175
\Magento \Catalog \Model \Product \Attribute \Source \Status::STATUS_DISABLED
140
176
);
177
+ $ duplicateMock ->expects ($ this ->atLeastOnce ())->method ('setStoreId ' );
141
178
$ duplicateMock ->expects ($ this ->once ())->method ('setCreatedAt ' )->with (null );
142
179
$ duplicateMock ->expects ($ this ->once ())->method ('setUpdatedAt ' )->with (null );
143
180
$ duplicateMock ->expects ($ this ->once ())->method ('setId ' )->with (null );
144
- $ duplicateMock ->expects (
145
- $ this ->once ()
146
- )->method (
147
- 'setStoreId '
148
- )->with (
149
- \Magento \Store \Model \Store::DEFAULT_STORE_ID
150
- );
181
+ $ duplicateMock ->expects ($ this ->atLeastOnce ())->method ('getStoreIds ' )->willReturn ([]);
151
182
$ duplicateMock ->expects ($ this ->atLeastOnce ())->method ('setData ' )->willReturn ($ duplicateMock );
152
183
$ this ->copyConstructorMock ->expects ($ this ->once ())->method ('build ' )->with ($ this ->productMock , $ duplicateMock );
153
- $ duplicateMock ->expects ($ this ->once ())->method ('getUrlKey ' )->willReturn ('urk-key-1 ' );
154
184
$ duplicateMock ->expects ($ this ->once ())->method ('setUrlKey ' )->with ('urk-key-2 ' )->willReturn ($ duplicateMock );
155
185
$ duplicateMock ->expects ($ this ->once ())->method ('save ' );
156
186
157
187
$ this ->metadata ->expects ($ this ->any ())->method ('getLinkField ' )->willReturn ('linkField ' );
158
188
159
189
$ duplicateMock ->expects ($ this ->any ())->method ('getData ' )->willReturnMap ([
160
190
['linkField ' , null , '2 ' ],
161
- ]); $ this ->optionRepositoryMock ->expects ($ this ->once ())
191
+ ]);
192
+ $ this ->optionRepositoryMock ->expects ($ this ->once ())
162
193
->method ('duplicate ' )
163
194
->with ($ this ->productMock , $ duplicateMock );
164
195
$ resourceMock ->expects ($ this ->once ())->method ('duplicate ' )->with (1 , 2 );
0 commit comments