@@ -1290,6 +1290,55 @@ public function test_post_featured_image_block_without_featured_image(): void {
1290
1290
wp_reset_postdata ();
1291
1291
}
1292
1292
1293
+ /**
1294
+ * Test that the post featured image block renders correctly with different image sizes.
1295
+ *
1296
+ * @dataProvider data_post_featured_image_block_image_sizes
1297
+ *
1298
+ * @param string $image_size Image size.
1299
+ * @param string $expected Expected output.
1300
+ */
1301
+ public function test_post_featured_image_block_with_different_image_size ( string $ image_size , string $ expected ): void {
1302
+ update_post_meta ( self ::$ post_id , '_thumbnail_id ' , self ::$ image_id );
1303
+
1304
+ $ block_content = '<!-- wp:post-featured-image {"sizeSlug":" ' . $ image_size . '"} /--> ' ;
1305
+
1306
+ // Set up global $post so 'the_content' filter works as expected.
1307
+ global $ post ;
1308
+ $ post = get_post ( self ::$ post_id );
1309
+ setup_postdata ( $ post );
1310
+
1311
+ $ result = apply_filters ( 'the_content ' , $ block_content );
1312
+
1313
+ // Check that the featured image block renders the image and has a sizes attribute.
1314
+ $ this ->assertStringContainsString ( 'wp-block-post-featured-image ' , $ result );
1315
+ $ this ->assertStringContainsString ( $ expected , $ result );
1316
+
1317
+ wp_reset_postdata ();
1318
+ }
1319
+
1320
+ /**
1321
+ * Data provider.
1322
+ *
1323
+ * @return array<array<string>> The image sizes.
1324
+ */
1325
+ public function data_post_featured_image_block_image_sizes (): array {
1326
+ return array (
1327
+ 'Return full or wideSize 1280px instead of medium size 300px ' => array (
1328
+ 'medium ' ,
1329
+ 'sizes="(max-width: 300px) 100vw, 300px" ' ,
1330
+ ),
1331
+ 'Return full or wideSize 1280px instead of large size 1024px ' => array (
1332
+ 'large ' ,
1333
+ 'sizes="(max-width: 620px) 100vw, 620px" ' ,
1334
+ ),
1335
+ 'Return full or wideSize 1280px instead of full size 1080px ' => array (
1336
+ 'full ' ,
1337
+ 'sizes="(max-width: 620px) 100vw, 620px" ' ,
1338
+ ),
1339
+ );
1340
+ }
1341
+
1293
1342
/**
1294
1343
* Filter the theme.json data to include relative layout sizes.
1295
1344
*
0 commit comments