From 4b7184ac85c14f43600b0f1ca90f06fab1ca2f4d Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Mon, 21 Sep 2020 22:54:05 +0200 Subject: [PATCH] Added tests for new QR code format --- module/Core/test/Action/QrCodeActionTest.php | 26 ++++++++++++++++++++ 1 file changed, 26 insertions(+) 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']; + } }