@@ -119,19 +119,33 @@ class ImageResizeTest extends TestCase
119
119
* @var string
120
120
*/
121
121
private $ testfilepath ;
122
+
123
+ /**
124
+ * @var string
125
+ */
126
+ private $ testImageHiddenFilename ;
127
+
122
128
/**
123
129
* @var MockObject|StoreManagerInterface
124
130
*/
125
131
private $ storeManager ;
126
132
133
+ /**
134
+ * @var string
135
+ */
136
+ private $ testImageHiddenfilepath ;
137
+
127
138
/**
128
139
* @inheritDoc
129
140
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
130
141
*/
131
142
protected function setUp (): void
132
143
{
133
144
$ this ->testfilename = "image.jpg " ;
145
+ $ this ->testImageHiddenFilename = "image_hidden.jpg " ;
134
146
$ this ->testfilepath = "/image.jpg " ;
147
+ $ this ->testImageHiddenfilepath = "/image_hidden.jpg " ;
148
+
135
149
136
150
$ this ->appStateMock = $ this ->createMock (State::class);
137
151
$ this ->imageConfigMock = $ this ->createMock (MediaConfig::class);
@@ -160,7 +174,7 @@ protected function setUp(): void
160
174
161
175
$ this ->assetImageMock ->expects ($ this ->any ())
162
176
->method ('getPath ' )
163
- ->willReturn ($ this ->testfilepath );
177
+ ->willReturnOnConsecutiveCalls ($ this ->testfilepath , $ this -> testImageHiddenfilepath );
164
178
$ this ->assetImageFactoryMock ->expects ($ this ->any ())
165
179
->method ('create ' )
166
180
->willReturn ($ this ->assetImageMock );
@@ -182,16 +196,15 @@ protected function setUp(): void
182
196
183
197
$ this ->imageConfigMock ->expects ($ this ->any ())
184
198
->method ('getMediaPath ' )
185
- ->with ( $ this ->testfilename )
186
- ->willReturn ($ this ->testfilepath );
199
+ ->withConsecutive ([ $ this ->testfilename ], [ $ this -> testImageHiddenFilename ] )
200
+ ->willReturnOnConsecutiveCalls ($ this ->testfilepath , $ this -> testImageHiddenfilepath );
187
201
$ this ->mediaDirectoryMock ->expects ($ this ->any ())
188
202
->method ('getAbsolutePath ' )
189
- ->with ( $ this ->testfilepath )
190
- ->willReturn ($ this ->testfilepath );
203
+ ->withConsecutive ([ $ this ->testfilepath ], [ $ this -> testImageHiddenfilepath ] )
204
+ ->willReturnOnConsecutiveCalls ($ this ->testfilepath , $ this -> testImageHiddenfilepath );
191
205
$ this ->mediaDirectoryMock ->expects ($ this ->any ())
192
206
->method ('getRelativePath ' )
193
- ->with ($ this ->testfilepath )
194
- ->willReturn ($ this ->testfilepath );
207
+ ->willReturnOnConsecutiveCalls ($ this ->testfilepath , $ this ->testImageHiddenfilepath );
195
208
196
209
$ this ->viewMock ->expects ($ this ->any ())
197
210
->method ('getMediaEntities ' )
@@ -248,7 +261,7 @@ public function testResizeFromThemesMediaStorageDatabase()
248
261
->willReturn (false );
249
262
250
263
$ imageMock = $ this ->createMock (Image::class);
251
- $ this ->imageFactoryMock ->expects ($ this ->once ())
264
+ $ this ->imageFactoryMock ->expects ($ this ->any ())
252
265
->method ('create ' )
253
266
->willReturn ($ imageMock );
254
267
@@ -268,17 +281,17 @@ function () {
268
281
269
282
$ this ->mediaDirectoryMock ->expects ($ this ->any ())
270
283
->method ('isFile ' )
271
- ->with ( $ this ->testfilepath )
284
+ ->withConsecutive ([ $ this ->testfilepath ], [ $ this -> testImageHiddenfilepath ] )
272
285
->willReturn (true );
273
286
274
- $ this ->databaseMock ->expects ($ this ->once ())
287
+ $ this ->databaseMock ->expects ($ this ->any ())
275
288
->method ('saveFileToFilesystem ' )
276
- ->with ( $ this ->testfilepath );
277
- $ this ->databaseMock ->expects ($ this ->once ())
289
+ ->withConsecutive ([ $ this ->testfilepath ], [ $ this -> testImageHiddenfilepath ] );
290
+ $ this ->databaseMock ->expects ($ this ->any ())
278
291
->method ('saveFile ' )
279
- ->with ( $ this ->testfilepath );
292
+ ->withConsecutive ([ $ this ->testfilepath ], [ $ this -> testImageHiddenfilepath ] );
280
293
281
- $ generator = $ this ->service ->resizeFromThemes (['test-theme ' ]);
294
+ $ generator = $ this ->service ->resizeFromThemes (['test-theme ' ], true );
282
295
while ($ generator ->valid ()) {
283
296
$ resizeInfo = $ generator ->key ();
284
297
$ this ->assertEquals ('image.jpg ' , $ resizeInfo ['filename ' ]);
@@ -287,6 +300,73 @@ function () {
287
300
}
288
301
}
289
302
303
+ public function testResizeFromThemesHiddenImagesMediaStorageDatabase ()
304
+ {
305
+ $ this ->databaseMock ->expects ($ this ->any ())
306
+ ->method ('checkDbUsage ' )
307
+ ->willReturn (true );
308
+ $ this ->databaseMock ->expects ($ this ->any ())
309
+ ->method ('fileExists ' )
310
+ ->willReturn (false );
311
+
312
+ $ imageMock = $ this ->createMock (Image::class);
313
+ $ this ->imageFactoryMock ->expects ($ this ->any ())
314
+ ->method ('create ' )
315
+ ->willReturn ($ imageMock );
316
+
317
+ $ this ->productImageMock ->expects ($ this ->any ())
318
+ ->method ('getCountUsedProductImages ' )
319
+ ->willReturn (1 );
320
+ $ this ->productImageMock ->expects ($ this ->any ())
321
+ ->method ('getUsedProductImages ' )
322
+ ->willReturnCallback (
323
+ function () {
324
+ $ data = [[ 'filepath ' => $ this ->testfilename ]];
325
+ foreach ($ data as $ e ) {
326
+ yield $ e ;
327
+ }
328
+ }
329
+ );
330
+
331
+ $ this ->productImageMock ->expects ($ this ->any ())
332
+ ->method ('getCountAllProductImages ' )
333
+ ->willReturn (2 );
334
+ $ this ->productImageMock ->expects ($ this ->any ())
335
+ ->method ('getAllProductImages ' )
336
+ ->willReturnCallback (
337
+ function () {
338
+ $ data = [[ 'filepath ' => $ this ->testfilename ], [ 'filepath ' => $ this ->testImageHiddenFilename ]];
339
+ foreach ($ data as $ e ) {
340
+ yield $ e ;
341
+ }
342
+ }
343
+ );
344
+
345
+ $ this ->mediaDirectoryMock ->expects ($ this ->any ())
346
+ ->method ('isFile ' )
347
+ ->withConsecutive ([$ this ->testfilepath ], [$ this ->testImageHiddenfilepath ])
348
+ ->willReturn (true );
349
+
350
+ $ this ->databaseMock ->expects ($ this ->any ())
351
+ ->method ('saveFileToFilesystem ' )
352
+ ->withConsecutive ([$ this ->testfilepath ], [$ this ->testImageHiddenfilepath ]);
353
+ $ this ->databaseMock ->expects ($ this ->any ())
354
+ ->method ('saveFile ' )
355
+ ->withConsecutive ([$ this ->testfilepath ], [$ this ->testImageHiddenfilepath ]);
356
+
357
+ $ this ->assertEquals (2 , $ this ->service ->getCountProductImages ());
358
+ $ this ->assertEquals (1 , $ this ->service ->getCountProductImages (true ));
359
+
360
+ $ generator = $ this ->service ->resizeFromThemes (['test-theme ' ]);
361
+ while ($ generator ->valid ()) {
362
+ $ resizeInfo = $ generator ->key ();
363
+ $ this ->assertContains ($ resizeInfo ['filename ' ], [$ this ->testfilename , $ this ->testImageHiddenFilename ]);
364
+ $ this ->assertEmpty ($ resizeInfo ['error ' ]);
365
+ $ generator ->next ();
366
+ }
367
+
368
+ }
369
+
290
370
public function testResizeFromThemesUnsupportedImage ()
291
371
{
292
372
$ this ->databaseMock ->expects ($ this ->any ())
@@ -296,7 +376,7 @@ public function testResizeFromThemesUnsupportedImage()
296
376
->method ('fileExists ' )
297
377
->willReturn (false );
298
378
299
- $ this ->imageFactoryMock ->expects ($ this ->once ())
379
+ $ this ->imageFactoryMock ->expects ($ this ->any ())
300
380
->method ('create ' )
301
381
->willThrowException (new \InvalidArgumentException ('Unsupported image format. ' ));
302
382
@@ -316,10 +396,10 @@ function () {
316
396
317
397
$ this ->mediaDirectoryMock ->expects ($ this ->any ())
318
398
->method ('isFile ' )
319
- ->with ( $ this ->testfilepath )
399
+ ->withConsecutive ([ $ this ->testfilepath ], [ $ this -> testImageHiddenfilepath ] )
320
400
->willReturn (true );
321
401
322
- $ generator = $ this ->service ->resizeFromThemes (['test-theme ' ]);
402
+ $ generator = $ this ->service ->resizeFromThemes (['test-theme ' ], true );
323
403
while ($ generator ->valid ()) {
324
404
$ resizeInfo = $ generator ->key ();
325
405
$ this ->assertEquals ('Unsupported image format. ' , $ resizeInfo ['error ' ]);
0 commit comments