@@ -52,6 +52,34 @@ public function set_up(): void {
52
52
wp_clean_theme_json_cache ();
53
53
}
54
54
55
+ /**
56
+ * Test that AUTO_SIZES_CONSTRAINTS contains all expected keys.
57
+ */
58
+ public function test_auto_sizes_constraints_keys_exist (): void {
59
+ $ expected_keys = array ( 'full ' , 'wide ' , 'left ' , 'right ' , 'default ' , 'center ' );
60
+ $ constraints = defined ( 'AUTO_SIZES_CONSTRAINTS ' ) ? constant ( 'AUTO_SIZES_CONSTRAINTS ' ) : $ GLOBALS ['AUTO_SIZES_CONSTRAINTS ' ];
61
+ $ this ->assertIsArray ( $ constraints );
62
+ foreach ( $ expected_keys as $ key ) {
63
+ $ this ->assertArrayHasKey ( $ key , $ constraints , "Key ' {$ key }' not found in AUTO_SIZES_CONSTRAINTS. " );
64
+ }
65
+ }
66
+
67
+ /**
68
+ * Test that AUTO_SIZES_CONSTRAINTS values are as expected.
69
+ */
70
+ public function test_auto_sizes_constraints_values (): void {
71
+ $ expected = array (
72
+ 'full ' => 0 ,
73
+ 'wide ' => 1 ,
74
+ 'left ' => 2 ,
75
+ 'right ' => 2 ,
76
+ 'default ' => 3 ,
77
+ 'center ' => 3 ,
78
+ );
79
+ $ constraints = defined ( 'AUTO_SIZES_CONSTRAINTS ' ) ? constant ( 'AUTO_SIZES_CONSTRAINTS ' ) : $ GLOBALS ['AUTO_SIZES_CONSTRAINTS ' ];
80
+ $ this ->assertEquals ( $ expected , $ constraints );
81
+ }
82
+
55
83
/**
56
84
* Test that if disable responsive image then it will not add sizes attribute.
57
85
*/
@@ -1276,6 +1304,7 @@ public static function data_image_block_with_parent_columns_and_its_parent_group
1276
1304
* Test that the image block in a two-column layout renders the correct sizes attribute.
1277
1305
*
1278
1306
* @cover ::auto_sizes_filter_image_tag
1307
+ * @cover ::auto_sizes_filter_render_block_context
1279
1308
*/
1280
1309
public function test_image_block_in_two_column_layout_renders_correct_sizes_attribute (): void {
1281
1310
// Skip test for WordPress versions below 6.8.
@@ -1303,6 +1332,7 @@ public function test_image_block_in_two_column_layout_renders_correct_sizes_attr
1303
1332
* Test that the image block in a three-column layout renders the correct sizes attribute.
1304
1333
*
1305
1334
* @cover ::auto_sizes_filter_image_tag
1335
+ * @cover ::auto_sizes_filter_render_block_context
1306
1336
*/
1307
1337
public function test_image_block_in_three_column_layout_renders_correct_sizes_attribute (): void {
1308
1338
// Skip test for WordPress versions below 6.8.
@@ -1457,6 +1487,19 @@ public static function data_post_featured_image_block_alignment(): array {
1457
1487
);
1458
1488
}
1459
1489
1490
+ /**
1491
+ * Test that auto_sizes_get_featured_image_attachment_id() returns 0 when post_id is not found.
1492
+ *
1493
+ * @covers ::auto_sizes_get_featured_image_attachment_id
1494
+ */
1495
+ public function test_auto_sizes_get_featured_image_attachment_id_returns_zero_for_zero_post_id (): void {
1496
+ $ this ->assertSame (
1497
+ 0 ,
1498
+ auto_sizes_get_featured_image_attachment_id ( 0 ),
1499
+ 'Should return 0 when post_id is not found. '
1500
+ );
1501
+ }
1502
+
1460
1503
/**
1461
1504
* Filter the theme.json data to include relative layout sizes.
1462
1505
*
0 commit comments