Skip to content

Commit 28945cb

Browse files
Add test for different alignment
1 parent 0a0aa58 commit 28945cb

File tree

1 file changed

+64
-3
lines changed

1 file changed

+64
-3
lines changed

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

Lines changed: 64 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1324,21 +1324,82 @@ public function test_post_featured_image_block_with_different_image_size( string
13241324
*/
13251325
public function data_post_featured_image_block_image_sizes(): array {
13261326
return array(
1327-
'Return full or wideSize 1280px instead of medium size 300px' => array(
1327+
'Return medium image size 300px' => array(
13281328
'medium',
13291329
'sizes="(max-width: 300px) 100vw, 300px" ',
13301330
),
1331-
'Return full or wideSize 1280px instead of large size 1024px' => array(
1331+
'Return contentSize 620px instead of large size 1024px' => array(
13321332
'large',
13331333
'sizes="(max-width: 620px) 100vw, 620px" ',
13341334
),
1335-
'Return full or wideSize 1280px instead of full size 1080px' => array(
1335+
'Return contentSize 620px instead of full size 1080px' => array(
13361336
'full',
13371337
'sizes="(max-width: 620px) 100vw, 620px" ',
13381338
),
13391339
);
13401340
}
13411341

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+
13421403
/**
13431404
* Filter the theme.json data to include relative layout sizes.
13441405
*

0 commit comments

Comments
 (0)