move_detect/cloud/tests/ImageProcessorTest.php

28 lines
1 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Tests;
use App\Ingest\ImageProcessor;
use PHPUnit\Framework\TestCase;
final class ImageProcessorTest extends TestCase
{
private function tinyJpegBase64(): string {
$im = imagecreatetruecolor(8, 8);
ob_start(); imagejpeg($im); $bytes = ob_get_clean();
return base64_encode($bytes);
}
public function testReencodeProducesJpeg(): void {
$r = ImageProcessor::reencode($this->tinyJpegBase64());
$this->assertTrue($r['ok']);
$this->assertSame("\xFF\xD8", substr($r['bytes'], 0, 2)); // JPEG magic
$this->assertSame(32, strlen($r['uuid']));
$this->assertSame(64, strlen($r['hash']));
}
public function testRejectsNonImage(): void {
$r = ImageProcessor::reencode(base64_encode("not an image <?php echo 1; ?>"));
$this->assertFalse($r['ok']);
}
public function testRejectsBadBase64(): void {
$this->assertFalse(ImageProcessor::reencode('%%%not-base64%%%')['ok']);
}
}