Skip to content

Commit aec096a

Browse files
Add unit test coverage for AUTO_SIZES_CONSTRAINTS
1 parent 434fb10 commit aec096a

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,34 @@ public function set_up(): void {
5252
wp_clean_theme_json_cache();
5353
}
5454

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+
5583
/**
5684
* Test that if disable responsive image then it will not add sizes attribute.
5785
*/

0 commit comments

Comments
 (0)