8
8
use Magento \Framework \App \Filesystem \DirectoryList ;
9
9
use Magento \Framework \Filesystem \Directory \WriteInterface ;
10
10
11
+ /**
12
+ * Test for Magento\Catalog\Model\Category\Attribute\Backend\Image class.
13
+ * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
14
+ */
11
15
class ImageTest extends \PHPUnit \Framework \TestCase
12
16
{
13
17
/**
@@ -96,9 +100,7 @@ public function testBeforeSaveValueDeletion($value)
96
100
$ model = $ this ->objectManager ->getObject (\Magento \Catalog \Model \Category \Attribute \Backend \Image::class);
97
101
$ model ->setAttribute ($ this ->attribute );
98
102
99
- $ object = new \Magento \Framework \DataObject ([
100
- 'test_attribute ' => $ value
101
- ]);
103
+ $ object = new \Magento \Framework \DataObject (['test_attribute ' => $ value ]);
102
104
103
105
$ model ->beforeSave ($ object );
104
106
@@ -133,9 +135,7 @@ public function testBeforeSaveValueInvalid($value)
133
135
$ model = $ this ->objectManager ->getObject (\Magento \Catalog \Model \Category \Attribute \Backend \Image::class);
134
136
$ model ->setAttribute ($ this ->attribute );
135
137
136
- $ object = new \Magento \Framework \DataObject ([
137
- 'test_attribute ' => $ value
138
- ]);
138
+ $ object = new \Magento \Framework \DataObject (['test_attribute ' => $ value ]);
139
139
140
140
$ model ->beforeSave ($ object );
141
141
@@ -163,11 +163,13 @@ public function testBeforeSaveAttributeFileName()
163
163
->with ('absolute/path/base/path/test123.jpg ' )
164
164
->willReturn (false );
165
165
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
+ ],
169
171
]
170
- ] );
172
+ );
171
173
172
174
$ model ->beforeSave ($ object );
173
175
@@ -193,14 +195,16 @@ public function testBeforeSaveAttributeFileNameOutsideOfCategoryDir()
193
195
->with (DirectoryList::MEDIA )
194
196
->willReturn ('pub/media ' );
195
197
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
+ ],
202
206
]
203
- ] );
207
+ );
204
208
205
209
$ model ->beforeSave ($ object );
206
210
@@ -225,17 +229,22 @@ public function testBeforeSaveTemporaryAttribute()
225
229
->with (DirectoryList::MEDIA )
226
230
->willReturn ($ mediaDirectoryMock );
227
231
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
+ ],
231
237
]
232
- ] );
238
+ );
233
239
234
240
$ model ->beforeSave ($ object );
235
241
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
+ );
239
248
}
240
249
241
250
/**
@@ -246,9 +255,7 @@ public function testBeforeSaveAttributeStringValue()
246
255
$ model = $ this ->objectManager ->getObject (\Magento \Catalog \Model \Category \Attribute \Backend \Image::class);
247
256
$ model ->setAttribute ($ this ->attribute );
248
257
249
- $ object = new \Magento \Framework \DataObject ([
250
- 'test_attribute ' => 'test123.jpg '
251
- ]);
258
+ $ object = new \Magento \Framework \DataObject (['test_attribute ' => 'test123.jpg ' ]);
252
259
253
260
$ model ->beforeSave ($ object );
254
261
@@ -267,19 +274,26 @@ private function setUpModelForAfterSave()
267
274
268
275
$ objectManagerMock ->expects ($ this ->any ())
269
276
->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
+ );
283
297
$ this ->objectManager ->setBackwardCompatibleProperty ($ model , 'imageUploader ' , $ this ->imageUploader );
284
298
285
299
return $ model ->setAttribute ($ this ->attribute );
0 commit comments