@@ -335,4 +335,79 @@ function () {
335335 $ this ->assertSame ( 'image_additional_generated_error ' , $ result ->get_error_code () );
336336 }
337337
338+ /**
339+ * Returns an empty array when the overwritten with empty array by webp_uploads_upload_image_mime_transforms filter.
340+ *
341+ * @test
342+ */
343+ public function it_should_return_empty_array_when_filter_returns_empty_array () {
344+ add_filter ( 'webp_uploads_upload_image_mime_transforms ' , '__return_empty_array ' );
345+
346+ $ transforms = webp_uploads_get_upload_image_mime_transforms ();
347+
348+ $ this ->assertIsArray ( $ transforms );
349+ $ this ->assertSame ( array (), $ transforms );
350+ }
351+
352+ /**
353+ * Returns default transforms when the overwritten with non array type by webp_uploads_upload_image_mime_transforms filter.
354+ *
355+ * @test
356+ */
357+ public function it_should_return_default_transforms_when_filter_returns_non_array_type () {
358+ add_filter (
359+ 'webp_uploads_upload_image_mime_transforms ' ,
360+ function () {
361+ return ;
362+ }
363+ );
364+
365+ $ default_transforms = array (
366+ 'image/jpeg ' => array ( 'image/jpeg ' , 'image/webp ' ),
367+ 'image/webp ' => array ( 'image/webp ' , 'image/jpeg ' ),
368+ );
369+
370+ $ transforms = webp_uploads_get_upload_image_mime_transforms ();
371+
372+ $ this ->assertIsArray ( $ transforms );
373+ $ this ->assertSame ( $ default_transforms , $ transforms );
374+ }
375+
376+ /**
377+ * Returns transforms array with fallback to original mime with invalid transforms array.
378+ *
379+ * @test
380+ */
381+ public function it_should_return_fallback_transforms_when_overwritten_invalid_transforms () {
382+ add_filter (
383+ 'webp_uploads_upload_image_mime_transforms ' ,
384+ function () {
385+ return array ( 'image/jpeg ' => array () );
386+ }
387+ );
388+
389+ $ transforms = webp_uploads_get_upload_image_mime_transforms ();
390+
391+ $ this ->assertIsArray ( $ transforms );
392+ $ this ->assertSame ( array ( 'image/jpeg ' => array ( 'image/jpeg ' ) ), $ transforms );
393+ }
394+
395+ /**
396+ * Returns custom transforms array when overwritten by webp_uploads_upload_image_mime_transforms filter.
397+ *
398+ * @test
399+ */
400+ public function it_should_return_custom_transforms_when_overwritten_by_filter () {
401+ add_filter (
402+ 'webp_uploads_upload_image_mime_transforms ' ,
403+ function () {
404+ return array ( 'image/jpeg ' => array ( 'image/jpeg ' , 'image/webp ' ) );
405+ }
406+ );
407+
408+ $ transforms = webp_uploads_get_upload_image_mime_transforms ();
409+
410+ $ this ->assertIsArray ( $ transforms );
411+ $ this ->assertSame ( array ( 'image/jpeg ' => array ( 'image/jpeg ' , 'image/webp ' ) ), $ transforms );
412+ }
338413}
0 commit comments