@@ -15,6 +15,12 @@ class Tests_Improve_Calculate_Sizes extends WP_UnitTestCase {
15
15
*/
16
16
public static $ image_id ;
17
17
18
+ /**
19
+ * Post ID.
20
+ *
21
+ * @var int
22
+ */
23
+ public static $ post_id ;
18
24
/**
19
25
* Set up the environment for the tests.
20
26
*/
@@ -24,6 +30,13 @@ public static function set_up_before_class(): void {
24
30
switch_theme ( 'twentytwentyfour ' );
25
31
26
32
self ::$ image_id = self ::factory ()->attachment ->create_upload_object ( TESTS_PLUGIN_DIR . '/tests/data/images/leaves.jpg ' );
33
+
34
+ self ::$ post_id = self ::factory ()->post ->create (
35
+ array (
36
+ 'post_status ' => 'publish ' ,
37
+ 'post_name ' => 'test-post ' ,
38
+ )
39
+ );
27
40
}
28
41
29
42
public function set_up (): void {
@@ -1259,6 +1272,24 @@ public function data_image_block_with_parent_columns_and_its_parent_group_block(
1259
1272
);
1260
1273
}
1261
1274
1275
+ /**
1276
+ * Verifies that the post featured image block does not render when no featured image is set for the post.
1277
+ */
1278
+ public function test_post_featured_image_block_without_featured_image (): void {
1279
+ $ block_content = '<!-- wp:post-featured-image /--> ' ;
1280
+
1281
+ // Set up global $post so 'the_content' filter works as expected.
1282
+ global $ post ;
1283
+ $ post = get_post ( self ::$ post_id );
1284
+ setup_postdata ( $ post );
1285
+
1286
+ $ result = apply_filters ( 'the_content ' , $ block_content );
1287
+
1288
+ $ this ->assertStringContainsString ( '' , $ result );
1289
+
1290
+ wp_reset_postdata ();
1291
+ }
1292
+
1262
1293
/**
1263
1294
* Filter the theme.json data to include relative layout sizes.
1264
1295
*
0 commit comments