diff --git a/module/Core/test/Action/QrCodeActionTest.php b/module/Core/test/Action/QrCodeActionTest.php index eb68f0e1..236288dd 100644 --- a/module/Core/test/Action/QrCodeActionTest.php +++ b/module/Core/test/Action/QrCodeActionTest.php @@ -81,4 +81,30 @@ class QrCodeActionTest extends TestCase $this->assertEquals(200, $resp->getStatusCode()); $delegate->handle(Argument::any())->shouldHaveBeenCalledTimes(0); } + + /** + * @test + * @dataProvider provideQueries + */ + public function imageIsReturnedWithExpectedContentTypeBasedOnProvidedFormat( + array $query, + string $expectedContentType + ): void { + $code = 'abc123'; + $this->urlResolver->resolveEnabledShortUrl(new ShortUrlIdentifier($code, ''))->willReturn(new ShortUrl('')); + $delegate = $this->prophesize(RequestHandlerInterface::class); + $req = (new ServerRequest())->withAttribute('shortCode', $code)->withQueryParams($query); + + $resp = $this->action->process($req, $delegate->reveal()); + + $this->assertEquals($expectedContentType, $resp->getHeaderLine('Content-Type')); + } + + public function provideQueries(): iterable + { + yield 'no format' => [[], 'image/png']; + yield 'png format' => [['format' => 'png'], 'image/png']; + yield 'svg format' => [['format' => 'svg'], 'image/svg+xml']; + yield 'unsupported format' => [['format' => 'jpg'], 'image/png']; + } }