Skip to content

Commit f744083

Browse files
committed
Tests: Cover media dimension expansion.
Verify that `wp_expand_dimensions()` expands example dimensions to fit maximum bounds while preserving aspect ratio. Cover matching, landscape, portrait, square, and numeric-string inputs with explicit expected dimensions. Developed in: #15246 Props shailu25. See #65819. git-svn-id: https://develop.svn.wordpress.org/trunk@65080 602fd350-edb4-49c9-b593-d223f7449a82
1 parent ee32943 commit f744083

1 file changed

Lines changed: 46 additions & 0 deletions

File tree

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
3+
/**
4+
* Tests for wp_expand_dimensions().
5+
*
6+
* @group media
7+
*
8+
* @covers ::wp_expand_dimensions
9+
*/
10+
class Tests_Media_WpExpandDimensions extends WP_UnitTestCase {
11+
12+
/**
13+
* Tests that the example aspect ratio is expanded to the largest size within the max bounds.
14+
*
15+
* @ticket 65819
16+
*
17+
* @dataProvider data_expand_dimensions
18+
*
19+
* @param int|string $example_width Example width.
20+
* @param int|string $example_height Example height.
21+
* @param int|string $max_width Maximum width.
22+
* @param int|string $max_height Maximum height.
23+
* @param int[] $expected Expected width and height.
24+
*/
25+
public function test_expands_example_to_max_bounds( $example_width, $example_height, $max_width, $max_height, $expected ) {
26+
$this->assertSame(
27+
$expected,
28+
wp_expand_dimensions( $example_width, $example_height, $max_width, $max_height )
29+
);
30+
}
31+
32+
/**
33+
* Data provider.
34+
*
35+
* @return array[]
36+
*/
37+
public static function data_expand_dimensions() {
38+
return array(
39+
'matching 4:3 ratio fills the box' => array( 4, 3, 1024, 768, array( 1024, 768 ) ),
40+
'landscape 16:9 limited by width' => array( 16, 9, 1024, 768, array( 1024, 576 ) ),
41+
'portrait 9:16 limited by height' => array( 9, 16, 1024, 768, array( 432, 768 ) ),
42+
'square limited by shorter max side' => array( 1, 1, 800, 600, array( 600, 600 ) ),
43+
'numeric strings are cast to integers' => array( '16', '9', '1024', '768', array( 1024, 576 ) ),
44+
);
45+
}
46+
}

0 commit comments

Comments
 (0)