88use Magento \Framework \App \Filesystem \DirectoryList ;
99use Magento \Framework \Filesystem \Directory \WriteInterface ;
1010
11+ /**
12+ * Test for Magento\Catalog\Model\Category\Attribute\Backend\Image class.
13+ * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
14+ */
1115class ImageTest extends \PHPUnit \Framework \TestCase
1216{
1317 /**
@@ -96,9 +100,7 @@ public function testBeforeSaveValueDeletion($value)
96100 $ model = $ this ->objectManager ->getObject (\Magento \Catalog \Model \Category \Attribute \Backend \Image::class);
97101 $ model ->setAttribute ($ this ->attribute );
98102
99- $ object = new \Magento \Framework \DataObject ([
100- 'test_attribute ' => $ value
101- ]);
103+ $ object = new \Magento \Framework \DataObject (['test_attribute ' => $ value ]);
102104
103105 $ model ->beforeSave ($ object );
104106
@@ -133,9 +135,7 @@ public function testBeforeSaveValueInvalid($value)
133135 $ model = $ this ->objectManager ->getObject (\Magento \Catalog \Model \Category \Attribute \Backend \Image::class);
134136 $ model ->setAttribute ($ this ->attribute );
135137
136- $ object = new \Magento \Framework \DataObject ([
137- 'test_attribute ' => $ value
138- ]);
138+ $ object = new \Magento \Framework \DataObject (['test_attribute ' => $ value ]);
139139
140140 $ model ->beforeSave ($ object );
141141
@@ -163,11 +163,13 @@ public function testBeforeSaveAttributeFileName()
163163 ->with ('absolute/path/base/path/test123.jpg ' )
164164 ->willReturn (false );
165165
166- $ object = new \Magento \Framework \DataObject ([
167- 'test_attribute ' => [
168- ['name ' => 'test123.jpg ' ]
166+ $ object = new \Magento \Framework \DataObject (
167+ [
168+ 'test_attribute ' => [
169+ ['name ' => 'test123.jpg ' ],
170+ ],
169171 ]
170- ] );
172+ );
171173
172174 $ model ->beforeSave ($ object );
173175
@@ -193,14 +195,16 @@ public function testBeforeSaveAttributeFileNameOutsideOfCategoryDir()
193195 ->with (DirectoryList::MEDIA )
194196 ->willReturn ('pub/media ' );
195197
196- $ object = new \Magento \Framework \DataObject ([
197- 'test_attribute ' => [
198- [
199- 'name ' => '/test123.jpg ' ,
200- 'url ' => '/pub/media/wysiwyg/test123.jpg ' ,
201- ]
198+ $ object = new \Magento \Framework \DataObject (
199+ [
200+ 'test_attribute ' => [
201+ [
202+ 'name ' => '/test123.jpg ' ,
203+ 'url ' => '/pub/media/wysiwyg/test123.jpg ' ,
204+ ],
205+ ],
202206 ]
203- ] );
207+ );
204208
205209 $ model ->beforeSave ($ object );
206210
@@ -225,17 +229,22 @@ public function testBeforeSaveTemporaryAttribute()
225229 ->with (DirectoryList::MEDIA )
226230 ->willReturn ($ mediaDirectoryMock );
227231
228- $ object = new \Magento \Framework \DataObject ([
229- 'test_attribute ' => [
230- ['name ' => 'test123.jpg ' , 'tmp_name ' => 'abc123 ' , 'url ' => 'http://www.example.com/test123.jpg ' ]
232+ $ object = new \Magento \Framework \DataObject (
233+ [
234+ 'test_attribute ' => [
235+ ['name ' => 'test123.jpg ' , 'tmp_name ' => 'abc123 ' , 'url ' => 'http://www.example.com/test123.jpg ' ],
236+ ],
231237 ]
232- ] );
238+ );
233239
234240 $ model ->beforeSave ($ object );
235241
236- $ this ->assertEquals ([
237- ['name ' => 'test123.jpg ' , 'tmp_name ' => 'abc123 ' , 'url ' => 'http://www.example.com/test123.jpg ' ]
238- ], $ object ->getData ('_additional_data_test_attribute ' ));
242+ $ this ->assertEquals (
243+ [
244+ ['name ' => 'test123.jpg ' , 'tmp_name ' => 'abc123 ' , 'url ' => 'http://www.example.com/test123.jpg ' ],
245+ ],
246+ $ object ->getData ('_additional_data_test_attribute ' )
247+ );
239248 }
240249
241250 /**
@@ -246,9 +255,7 @@ public function testBeforeSaveAttributeStringValue()
246255 $ model = $ this ->objectManager ->getObject (\Magento \Catalog \Model \Category \Attribute \Backend \Image::class);
247256 $ model ->setAttribute ($ this ->attribute );
248257
249- $ object = new \Magento \Framework \DataObject ([
250- 'test_attribute ' => 'test123.jpg '
251- ]);
258+ $ object = new \Magento \Framework \DataObject (['test_attribute ' => 'test123.jpg ' ]);
252259
253260 $ model ->beforeSave ($ object );
254261
@@ -267,19 +274,26 @@ private function setUpModelForAfterSave()
267274
268275 $ objectManagerMock ->expects ($ this ->any ())
269276 ->method ('get ' )
270- ->will ($ this ->returnCallback (function ($ class , $ params = []) use ($ imageUploaderMock ) {
271- if ($ class == \Magento \Catalog \CategoryImageUpload::class) {
272- return $ imageUploaderMock ;
273- }
274-
275- return $ this ->objectManager ->get ($ class , $ params );
276- }));
277-
278- $ model = $ this ->objectManager ->getObject (\Magento \Catalog \Model \Category \Attribute \Backend \Image::class, [
279- 'objectManager ' => $ objectManagerMock ,
280- 'logger ' => $ this ->logger ,
281- 'filesystem ' => $ this ->filesystem ,
282- ]);
277+ ->will (
278+ $ this ->returnCallback (
279+ function ($ class , $ params = []) use ($ imageUploaderMock ) {
280+ if ($ class == \Magento \Catalog \CategoryImageUpload::class) {
281+ return $ imageUploaderMock ;
282+ }
283+
284+ return $ this ->objectManager ->get ($ class , $ params );
285+ }
286+ )
287+ );
288+
289+ $ model = $ this ->objectManager ->getObject (
290+ \Magento \Catalog \Model \Category \Attribute \Backend \Image::class,
291+ [
292+ 'objectManager ' => $ objectManagerMock ,
293+ 'logger ' => $ this ->logger ,
294+ 'filesystem ' => $ this ->filesystem ,
295+ ]
296+ );
283297 $ this ->objectManager ->setBackwardCompatibleProperty ($ model , 'imageUploader ' , $ this ->imageUploader );
284298
285299 return $ model ->setAttribute ($ this ->attribute );
0 commit comments