Deprecate QR code generation endpoint

This commit is contained in:
Alejandro Celaya
2025-04-22 08:41:58 +02:00
parent 851929ebef
commit b15e832cf4
10 changed files with 61 additions and 45 deletions

View File

@@ -9,7 +9,6 @@ use Laminas\Diactoros\ServerRequest;
use Laminas\Diactoros\ServerRequestFactory;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\Attributes\TestWith;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use Psr\Http\Message\ServerRequestInterface;
@@ -286,30 +285,6 @@ class QrCodeActionTest extends TestCase
);
}
#[Test]
#[TestWith([[], '4696E5'])] // The logo has Shlink's brand color
#[TestWith([['logo' => 'invalid'], '4696E5'])] // Invalid `logo` values are ignored. Default logo is still rendered
#[TestWith([['logo' => 'disable'], '000000'])] // No logo will be added if explicitly disabled
public function logoIsAddedToQrCodeIfOptionIsDefined(array $query, string $expectedColor): void
{
$logoUrl = 'https://avatars.githubusercontent.com/u/20341790?v=4'; // Shlink's logo
$code = 'abc123';
$req = ServerRequestFactory::fromGlobals()
->withAttribute('shortCode', $code)
->withQueryParams($query);
$this->urlResolver->method('resolveEnabledShortUrl')->willReturn(ShortUrl::withLongUrl('https://shlink.io'));
$handler = $this->createMock(RequestHandlerInterface::class);
$resp = $this->action(new QrCodeOptions(size: 250, logoUrl: $logoUrl))->process($req, $handler);
$image = imagecreatefromstring($resp->getBody()->__toString());
self::assertNotFalse($image);
// At around 100x100 px we can already find the logo, if present
$resultingColor = imagecolorat($image, 100, 100);
self::assertEquals(hexdec($expectedColor), $resultingColor);
}
public static function provideEnabled(): iterable
{
yield 'always enabled' => [true];