mirror of
https://github.com/friendica/friendica
synced 2024-12-23 05:20:15 +00:00
add unit tests for getScalingDimensions
This commit is contained in:
parent
c5b8abcaf0
commit
a20b876d67
1 changed files with 100 additions and 0 deletions
|
@ -96,4 +96,104 @@ class ImagesTest extends MockedTest
|
||||||
|
|
||||||
self::assertArraySubset($assertion, Images::getInfoFromURL($url));
|
self::assertArraySubset($assertion, Images::getInfoFromURL($url));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function dataScalingDimensions()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'landscape' => [
|
||||||
|
'width' => 640,
|
||||||
|
'height' => 480,
|
||||||
|
'max' => 320,
|
||||||
|
'assertion' => [
|
||||||
|
'width' => 320,
|
||||||
|
'height' => 240,
|
||||||
|
]
|
||||||
|
],
|
||||||
|
'wide_landscape' => [
|
||||||
|
'width' => 640,
|
||||||
|
'height' => 120,
|
||||||
|
'max' => 320,
|
||||||
|
'assertion' => [
|
||||||
|
'width' => 320,
|
||||||
|
'height' => 60,
|
||||||
|
]
|
||||||
|
],
|
||||||
|
'landscape_round_up' => [
|
||||||
|
'width' => 640,
|
||||||
|
'height' => 479,
|
||||||
|
'max' => 320,
|
||||||
|
'assertion' => [
|
||||||
|
'width' => 320,
|
||||||
|
'height' => 240,
|
||||||
|
]
|
||||||
|
],
|
||||||
|
'landscape_zero_height' => [
|
||||||
|
'width' => 640,
|
||||||
|
'height' => 1,
|
||||||
|
'max' => 160,
|
||||||
|
'assertion' => [
|
||||||
|
'width' => 160,
|
||||||
|
'height' => 1,
|
||||||
|
]
|
||||||
|
],
|
||||||
|
'portrait' => [
|
||||||
|
'width' => 480,
|
||||||
|
'height' => 640,
|
||||||
|
'max' => 320,
|
||||||
|
'assertion' => [
|
||||||
|
'width' => 240,
|
||||||
|
'height' => 320,
|
||||||
|
]
|
||||||
|
],
|
||||||
|
// For portrait with aspect ratio <= 16:9, constrain height
|
||||||
|
'portrait_16_9' => [
|
||||||
|
'width' => 1080,
|
||||||
|
'height' => 1920,
|
||||||
|
'max' => 320,
|
||||||
|
'assertion' => [
|
||||||
|
'width' => 180,
|
||||||
|
'height' => 320,
|
||||||
|
]
|
||||||
|
],
|
||||||
|
// For portrait with aspect ratio > 16:9, constrain width
|
||||||
|
'portrait_over_16_9_too_wide' => [
|
||||||
|
'width' => 1080,
|
||||||
|
'height' => 1921,
|
||||||
|
'max' => 320,
|
||||||
|
'assertion' => [
|
||||||
|
'width' => 320,
|
||||||
|
'height' => 570,
|
||||||
|
]
|
||||||
|
],
|
||||||
|
// For portrait with aspect ratio > 16:9, constrain width
|
||||||
|
'portrait_over_16_9_not_too_wide' => [
|
||||||
|
'width' => 1080,
|
||||||
|
'height' => 1921,
|
||||||
|
'max' => 1080,
|
||||||
|
'assertion' => [
|
||||||
|
'width' => 1080,
|
||||||
|
'height' => 1921,
|
||||||
|
]
|
||||||
|
],
|
||||||
|
'portrait_round_up' => [
|
||||||
|
'width' => 479,
|
||||||
|
'height' => 640,
|
||||||
|
'max' => 320,
|
||||||
|
'assertion' => [
|
||||||
|
'width' => 240,
|
||||||
|
'height' => 320,
|
||||||
|
]
|
||||||
|
],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test the Images::getScalingDimensions() method
|
||||||
|
*
|
||||||
|
* @dataProvider dataScalingDimensions
|
||||||
|
*/
|
||||||
|
public function testGetScalingDimensions(int $width, int $height, int $max, array $assertion)
|
||||||
|
{
|
||||||
|
self::assertArraySubset($assertion, Images::getScalingDimensions($width, $height, $max));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue