12
12
use Magento \Catalog \Api \Data \ProductAttributeInterface ;
13
13
use Magento \Catalog \Model \Product \Attribute \Repository ;
14
14
use Magento \Catalog \Model \ResourceModel \Eav \Attribute ;
15
- use Magento \Eav \Api \Data \AttributeFrontendLabelInterface ;
16
15
17
16
/**
18
17
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
@@ -87,7 +86,10 @@ protected function setUp()
87
86
$ this ->eavConfigMock = $ this ->createMock (\Magento \Eav \Model \Config::class);
88
87
$ this ->eavConfigMock ->expects ($ this ->any ())->method ('getEntityType ' )
89
88
->willReturn (new \Magento \Framework \DataObject (['default_attribute_set_id ' => 4 ]));
90
- $ this ->validatorFactoryMock = $ this ->createPartialMock (\Magento \Eav \Model \Adminhtml \System \Config \Source \Inputtype \ValidatorFactory::class, ['create ' ]);
89
+ $ this ->validatorFactoryMock = $ this ->createPartialMock (
90
+ \Magento \Eav \Model \Adminhtml \System \Config \Source \Inputtype \ValidatorFactory::class,
91
+ ['create ' ]
92
+ );
91
93
$ this ->searchCriteriaBuilderMock =
92
94
$ this ->createMock (\Magento \Framework \Api \SearchCriteriaBuilder::class);
93
95
$ this ->searchResultMock =
@@ -210,7 +212,10 @@ public function testSaveNoSuchEntityException()
210
212
*/
211
213
public function testSaveInputExceptionRequiredField ()
212
214
{
213
- $ attributeMock = $ this ->createPartialMock (\Magento \Catalog \Model \ResourceModel \Eav \Attribute::class, ['getFrontendLabels ' , 'getDefaultFrontendLabel ' , '__wakeup ' , 'getAttributeId ' , 'setAttributeId ' ]);
215
+ $ attributeMock = $ this ->createPartialMock (
216
+ \Magento \Catalog \Model \ResourceModel \Eav \Attribute::class,
217
+ ['getFrontendLabels ' , 'getDefaultFrontendLabel ' , '__wakeup ' , 'getAttributeId ' , 'setAttributeId ' ]
218
+ );
214
219
$ attributeMock ->expects ($ this ->once ())->method ('getAttributeId ' )->willReturn (null );
215
220
$ attributeMock ->expects ($ this ->once ())->method ('setAttributeId ' )->with (null )->willReturnSelf ();
216
221
$ attributeMock ->expects ($ this ->once ())->method ('getFrontendLabels ' )->willReturn (null );
@@ -225,12 +230,15 @@ public function testSaveInputExceptionRequiredField()
225
230
*/
226
231
public function testSaveInputExceptionInvalidFieldValue ()
227
232
{
228
- $ attributeMock = $ this ->createPartialMock (\Magento \Catalog \Model \ResourceModel \Eav \Attribute::class, ['getFrontendLabels ' , 'getDefaultFrontendLabel ' , 'getAttributeId ' , '__wakeup ' , 'setAttributeId ' ]);
233
+ $ attributeMock = $ this ->createPartialMock (
234
+ \Magento \Catalog \Model \ResourceModel \Eav \Attribute::class,
235
+ ['getFrontendLabels ' , 'getDefaultFrontendLabel ' , 'getAttributeId ' , '__wakeup ' , 'setAttributeId ' ]
236
+ );
229
237
$ attributeMock ->expects ($ this ->once ())->method ('getAttributeId ' )->willReturn (null );
230
238
$ attributeMock ->expects ($ this ->once ())->method ('setAttributeId ' )->with (null )->willReturnSelf ();
231
- $ labelMock = $ this ->createMock (\Magento \Eav \Api \ Data \AttributeFrontendLabelInterface ::class);
232
- $ attributeMock ->expects ($ this ->exactly ( 4 ))->method ('getFrontendLabels ' )->willReturn ([$ labelMock ]);
233
- $ attributeMock ->expects ($ this ->exactly ( 2 ))->method ('getDefaultFrontendLabel ' )->willReturn (' test ' );
239
+ $ labelMock = $ this ->createMock (\Magento \Eav \Model \ Entity \ Attribute \FrontendLabel ::class);
240
+ $ attributeMock ->expects ($ this ->any ( ))->method ('getFrontendLabels ' )->willReturn ([$ labelMock ]);
241
+ $ attributeMock ->expects ($ this ->any ( ))->method ('getDefaultFrontendLabel ' )->willReturn (null );
234
242
$ labelMock ->expects ($ this ->once ())->method ('getStoreId ' )->willReturn (0 );
235
243
$ labelMock ->expects ($ this ->once ())->method ('getLabel ' )->willReturn (null );
236
244
@@ -253,7 +261,7 @@ public function testSaveDoesNotSaveAttributeOptionsIfOptionsAreAbsentInPayload()
253
261
->method ('get ' )
254
262
->with (ProductAttributeInterface::ENTITY_TYPE_CODE , $ attributeCode )
255
263
->willReturn ($ existingModelMock );
256
-
264
+ $ existingModelMock -> expects ( $ this -> once ())-> method ( ' getDefaultFrontendLabel ' )-> willReturn ( ' default_label ' );
257
265
// Attribute code must not be changed after attribute creation
258
266
$ attributeMock ->expects ($ this ->once ())->method ('setAttributeCode ' )->with ($ attributeCode );
259
267
$ this ->attributeResourceMock ->expects ($ this ->once ())->method ('save ' )->with ($ attributeMock );
@@ -264,7 +272,7 @@ public function testSaveDoesNotSaveAttributeOptionsIfOptionsAreAbsentInPayload()
264
272
265
273
public function testSaveSavesDefaultFrontendLabelIfItIsPresentInPayload ()
266
274
{
267
- $ labelMock = $ this ->createMock (AttributeFrontendLabelInterface::class);
275
+ $ labelMock = $ this ->createMock (\ Magento \ Eav \ Api \ Data \ AttributeFrontendLabelInterface::class);
268
276
$ labelMock ->expects ($ this ->any ())->method ('getStoreId ' )->willReturn (1 );
269
277
$ labelMock ->expects ($ this ->any ())->method ('getLabel ' )->willReturn ('Store Scope Label ' );
270
278
@@ -273,11 +281,12 @@ public function testSaveSavesDefaultFrontendLabelIfItIsPresentInPayload()
273
281
$ attributeMock = $ this ->createMock (Attribute::class);
274
282
$ attributeMock ->expects ($ this ->any ())->method ('getAttributeCode ' )->willReturn ($ attributeCode );
275
283
$ attributeMock ->expects ($ this ->any ())->method ('getAttributeId ' )->willReturn ($ attributeId );
276
- $ attributeMock ->expects ($ this ->any ())->method ('getDefaultFrontendLabel ' )->willReturn (' Default Label ' );
284
+ $ attributeMock ->expects ($ this ->any ())->method ('getDefaultFrontendLabel ' )->willReturn (null );
277
285
$ attributeMock ->expects ($ this ->any ())->method ('getFrontendLabels ' )->willReturn ([$ labelMock ]);
278
286
$ attributeMock ->expects ($ this ->any ())->method ('getOptions ' )->willReturn ([]);
279
287
280
288
$ existingModelMock = $ this ->createMock (Attribute::class);
289
+ $ existingModelMock ->expects ($ this ->any ())->method ('getDefaultFrontendLabel ' )->willReturn ('Default Label ' );
281
290
$ existingModelMock ->expects ($ this ->any ())->method ('getAttributeId ' )->willReturn ($ attributeId );
282
291
$ existingModelMock ->expects ($ this ->any ())->method ('getAttributeCode ' )->willReturn ($ attributeCode );
283
292
@@ -288,12 +297,7 @@ public function testSaveSavesDefaultFrontendLabelIfItIsPresentInPayload()
288
297
289
298
$ attributeMock ->expects ($ this ->once ())
290
299
->method ('setDefaultFrontendLabel ' )
291
- ->with (
292
- [
293
- 0 => 'Default Label ' ,
294
- 1 => 'Store Scope Label '
295
- ]
296
- );
300
+ ->with ('Default Label ' );
297
301
$ this ->attributeResourceMock ->expects ($ this ->once ())->method ('save ' )->with ($ attributeMock );
298
302
299
303
$ this ->model ->save ($ attributeMock );
0 commit comments