From c5977389153277ec986cd682d838f5fc40808b8f Mon Sep 17 00:00:00 2001 From: Alejandro Celaya <alejandrocelaya@gmail.com> Date: Sun, 24 Dec 2023 10:13:19 +0100 Subject: [PATCH] Test how URLs are resolved in QrCodeAction --- module/Core/test/Action/QrCodeActionTest.php | 29 ++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/module/Core/test/Action/QrCodeActionTest.php b/module/Core/test/Action/QrCodeActionTest.php index f6850c1f..9a89ff47 100644 --- a/module/Core/test/Action/QrCodeActionTest.php +++ b/module/Core/test/Action/QrCodeActionTest.php @@ -230,6 +230,35 @@ class QrCodeActionTest extends TestCase ]; } + #[Test, DataProvider('provideEnabled')] + public function qrCodeIsResolvedBasedOnOptions(bool $enabledForDisabledShortUrls): void + { + + if ($enabledForDisabledShortUrls) { + $this->urlResolver->expects($this->once())->method('resolvePublicShortUrl')->willThrowException( + ShortUrlNotFoundException::fromNotFound(ShortUrlIdentifier::fromShortCodeAndDomain('')), + ); + $this->urlResolver->expects($this->never())->method('resolveEnabledShortUrl'); + } else { + $this->urlResolver->expects($this->once())->method('resolveEnabledShortUrl')->willThrowException( + ShortUrlNotFoundException::fromNotFound(ShortUrlIdentifier::fromShortCodeAndDomain('')), + ); + $this->urlResolver->expects($this->never())->method('resolvePublicShortUrl'); + } + + $options = new QrCodeOptions(enabledForDisabledShortUrls: $enabledForDisabledShortUrls); + $this->action($options)->process( + ServerRequestFactory::fromGlobals(), + $this->createMock(RequestHandlerInterface::class), + ); + } + + public static function provideEnabled(): iterable + { + yield 'always enabled' => [true]; + yield 'only enabled short URLs' => [false]; + } + public function action(?QrCodeOptions $options = null): QrCodeAction { return new QrCodeAction(