@@ -1324,21 +1324,82 @@ public function test_post_featured_image_block_with_different_image_size( string
1324
1324
*/
1325
1325
public function data_post_featured_image_block_image_sizes (): array {
1326
1326
return array (
1327
- 'Return full or wideSize 1280px instead of medium size 300px ' => array (
1327
+ 'Return medium image size 300px ' => array (
1328
1328
'medium ' ,
1329
1329
'sizes="(max-width: 300px) 100vw, 300px" ' ,
1330
1330
),
1331
- 'Return full or wideSize 1280px instead of large size 1024px ' => array (
1331
+ 'Return contentSize 620px instead of large size 1024px ' => array (
1332
1332
'large ' ,
1333
1333
'sizes="(max-width: 620px) 100vw, 620px" ' ,
1334
1334
),
1335
- 'Return full or wideSize 1280px instead of full size 1080px ' => array (
1335
+ 'Return contentSize 620px instead of full size 1080px ' => array (
1336
1336
'full ' ,
1337
1337
'sizes="(max-width: 620px) 100vw, 620px" ' ,
1338
1338
),
1339
1339
);
1340
1340
}
1341
1341
1342
+ /**
1343
+ * Test that the post featured image block renders correctly with different alignment.
1344
+ *
1345
+ * @dataProvider data_post_featured_image_block_alignment
1346
+ *
1347
+ * @param string $alignment Alignment of the image.
1348
+ * @param string $expected Expected output.
1349
+ */
1350
+ public function test_post_featured_image_block_with_different_alignment ( string $ alignment , string $ expected ): void {
1351
+ update_post_meta ( self ::$ post_id , '_thumbnail_id ' , self ::$ image_id );
1352
+
1353
+ $ block_content = '<!-- wp:post-featured-image {"align":" ' . $ alignment . '"} /--> ' ;
1354
+
1355
+ // Set up global $post so 'the_content' filter works as expected.
1356
+ global $ post ;
1357
+ $ post = get_post ( self ::$ post_id );
1358
+ setup_postdata ( $ post );
1359
+
1360
+ $ result = apply_filters ( 'the_content ' , $ block_content );
1361
+
1362
+ // Check that the featured image block renders the image and has a sizes attribute.
1363
+ $ this ->assertStringContainsString ( 'wp-block-post-featured-image ' , $ result );
1364
+ $ this ->assertStringContainsString ( $ expected , $ result );
1365
+
1366
+ wp_reset_postdata ();
1367
+ }
1368
+
1369
+ /**
1370
+ * Data provider.
1371
+ *
1372
+ * @return array<array<string>> The image sizes.
1373
+ */
1374
+ public function data_post_featured_image_block_alignment (): array {
1375
+ return array (
1376
+ 'Return contentSize 620px instead of image size 1080px, block default alignment ' => array (
1377
+ '' ,
1378
+ 'sizes="(max-width: 620px) 100vw, 620px" ' ,
1379
+ ),
1380
+ 'Return wideSize 1280px instead of image size 1080px, block wide alignment ' => array (
1381
+ 'wide ' ,
1382
+ 'sizes="(max-width: 1280px) 100vw, 1280px" ' ,
1383
+ ),
1384
+ 'Return full size instead of image size 1080px, block full alignment ' => array (
1385
+ 'full ' ,
1386
+ 'sizes="100vw" ' ,
1387
+ ),
1388
+ 'Return image size 1080px, block left alignment ' => array (
1389
+ 'left ' ,
1390
+ 'sizes="(max-width: 1080px) 100vw, 1080px" ' ,
1391
+ ),
1392
+ 'Return image size 1080px, block right alignment ' => array (
1393
+ 'right ' ,
1394
+ 'sizes="(max-width: 1080px) 100vw, 1080px" ' ,
1395
+ ),
1396
+ 'Return contentSize 620px instead of image size 1080px, block center alignment ' => array (
1397
+ 'center ' ,
1398
+ 'sizes="(max-width: 620px) 100vw, 620px" ' ,
1399
+ ),
1400
+ );
1401
+ }
1402
+
1342
1403
/**
1343
1404
* Filter the theme.json data to include relative layout sizes.
1344
1405
*
0 commit comments