Added tests for new QR code format

This commit is contained in:
Alejandro Celaya 2020-09-21 22:54:05 +02:00
parent 55d9f2a4a1
commit 4b7184ac85

View file

@ -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'];
}
}