2026-06-22 18:47:50 +03:00
|
|
|
<?php
|
|
|
|
|
|
2026-06-24 22:35:33 +03:00
|
|
|
use XcVm\Core\Util\ImageUtils;
|
2026-06-22 18:47:50 +03:00
|
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @covers ImageUtils
|
|
|
|
|
*/
|
|
|
|
|
final class ImageUtilsTest extends TestCase {
|
|
|
|
|
|
|
|
|
|
public function testKeepAspectRatioDownscales() {
|
|
|
|
|
$size = ImageUtils::getImageSizeKeepAspectRatio(1000, 500, 100, 100);
|
|
|
|
|
$this->assertEquals(100, $size['width']);
|
|
|
|
|
$this->assertEquals(50, $size['height']);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testKeepAspectRatioDoesNotUpscale() {
|
|
|
|
|
$size = ImageUtils::getImageSizeKeepAspectRatio(50, 50, 100, 100);
|
|
|
|
|
$this->assertEquals(50, $size['width']);
|
|
|
|
|
$this->assertEquals(50, $size['height']);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testKeepAspectRatioTreatsZeroMaxAsUnbounded() {
|
|
|
|
|
$size = ImageUtils::getImageSizeKeepAspectRatio(200, 100, 0, 50);
|
|
|
|
|
$this->assertEquals(100, $size['width']);
|
|
|
|
|
$this->assertEquals(50, $size['height']);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testIsAbsoluteUrl() {
|
|
|
|
|
$this->assertTrue(ImageUtils::isAbsoluteUrl('http://example.com/a.png'));
|
|
|
|
|
$this->assertTrue(ImageUtils::isAbsoluteUrl('https://example.com/a.png'));
|
|
|
|
|
$this->assertFalse(ImageUtils::isAbsoluteUrl('/relative/a.png'));
|
|
|
|
|
$this->assertFalse(ImageUtils::isAbsoluteUrl('a.png'));
|
|
|
|
|
}
|
|
|
|
|
}
|