Skip to content

Commit 814f00e

Browse files
Add basic test for featured image block
1 parent ad00f45 commit 814f00e

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

plugins/auto-sizes/tests/test-improve-calculate-sizes.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ class Tests_Improve_Calculate_Sizes extends WP_UnitTestCase {
1515
*/
1616
public static $image_id;
1717

18+
/**
19+
* Post ID.
20+
*
21+
* @var int
22+
*/
23+
public static $post_id;
1824
/**
1925
* Set up the environment for the tests.
2026
*/
@@ -24,6 +30,13 @@ public static function set_up_before_class(): void {
2430
switch_theme( 'twentytwentyfour' );
2531

2632
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+
);
2740
}
2841

2942
public function set_up(): void {
@@ -1259,6 +1272,24 @@ public function data_image_block_with_parent_columns_and_its_parent_group_block(
12591272
);
12601273
}
12611274

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+
12621293
/**
12631294
* Filter the theme.json data to include relative layout sizes.
12641295
*

0 commit comments

Comments
 (0)