@@ -1087,4 +1087,36 @@ public function test_it_should_generate_fallback_images_for_all_sizes_when_gener
10871087
10881088 wp_delete_attachment ( $ attachment_id );
10891089 }
1090+
1091+ /**
1092+ * Convert WebP to AVIF on uploads.
1093+ */
1094+ public function test_that_it_should_convert_webp_to_avif_on_upload (): void {
1095+ // Ensure the AVIF MIME type is supported; skip the test if not.
1096+ if ( ! webp_uploads_mime_type_supported ( 'image/avif ' ) ) {
1097+ $ this ->markTestSkipped ( 'Mime type image/avif is not supported. ' );
1098+ }
1099+
1100+ $ this ->set_image_output_type ( 'avif ' );
1101+
1102+ $ attachment_id = self ::factory ()->attachment ->create_upload_object ( TESTS_PLUGIN_DIR . '/tests/data/images/balloons.webp ' );
1103+
1104+ // There should be a AVIF source, but no WebP source for the full image.
1105+ $ this ->assertImageNotHasSource ( $ attachment_id , 'image/webp ' );
1106+ $ this ->assertImageHasSource ( $ attachment_id , 'image/avif ' );
1107+
1108+ $ metadata = wp_get_attachment_metadata ( $ attachment_id );
1109+
1110+ // The full image should be a AVIF.
1111+ $ this ->assertArrayHasKey ( 'file ' , $ metadata );
1112+ $ this ->assertStringEndsWith ( $ metadata ['sources ' ]['image/avif ' ]['file ' ], $ metadata ['file ' ] );
1113+ $ this ->assertStringEndsWith ( $ metadata ['sources ' ]['image/avif ' ]['file ' ], get_attached_file ( $ attachment_id ) );
1114+
1115+ // There should be a AVIF source, but no WebP source for all sizes.
1116+ foreach ( array_keys ( $ metadata ['sizes ' ] ) as $ size_name ) {
1117+ $ this ->assertImageNotHasSizeSource ( $ attachment_id , $ size_name , 'image/webp ' );
1118+ $ this ->assertImageHasSizeSource ( $ attachment_id , $ size_name , 'image/avif ' );
1119+ }
1120+ wp_delete_attachment ( $ attachment_id );
1121+ }
10901122}
0 commit comments