mirror of
https://github.com/Vateron-Media/XC_VM.git
synced 2026-10-03 12:02:29 +02:00
The cs-fix pass (758a9cab) typed ImageUtils::validateURL()'s URL and
StreamSorter::formatTitle()'s title as non-nullable strings, but both
come from nullable columns (streams.stream_icon / stream_display_name,
streams_series.title / cover, …). get_live_streams passed a channel's
NULL stream_icon straight in, so one channel without an icon turned the
line's entire live list into a TypeError page — and the same for any of
the ~100 validateURL() callers (series covers, backdrops, episode
images, admin and reseller views) and a title-less stream or series.
Both now take null as '' (unit-tested). player_api also no longer hands
filterLoaded() a null when the categories cache file is missing.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Y4P9p5BXijMoGXd31tN6Zp
58 lines
2.0 KiB
PHP
58 lines
2.0 KiB
PHP
<?php
|
|
|
|
use XcVm\Core\Util\ImageUtils;
|
|
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 testValidateUrlTakesAMissingImage() {
|
|
// A stream with no icon has a NULL stream_icon; get_live_streams passed it
|
|
// straight in and died with a TypeError for the whole list.
|
|
$this->assertSame('', ImageUtils::validateURL(null));
|
|
}
|
|
|
|
public function testValidateUrlKeepsAPlainUrl() {
|
|
$this->assertSame('http://example.com/logo.png', ImageUtils::validateURL('http://example.com/logo.png'));
|
|
$this->assertSame('', ImageUtils::validateURL(''));
|
|
}
|
|
|
|
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'));
|
|
}
|
|
|
|
/**
|
|
* Callers hand over optional columns (a stream without an icon, a movie
|
|
* without a backdrop). What cannot be downloaded comes back unchanged —
|
|
* null included; it used to end the save with a TypeError.
|
|
*/
|
|
public function testDownloadImageReturnsWhatItCannotDownload() {
|
|
$this->assertNull(ImageUtils::downloadImage(null, 1));
|
|
$this->assertSame('', ImageUtils::downloadImage(''));
|
|
$this->assertSame('/images/local.png', ImageUtils::downloadImage('/images/local.png', 2));
|
|
}
|
|
}
|