From 67c20c06c4c67bf4748fb08dfcf2f9bd571a362f Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Sun, 24 Dec 2023 09:43:31 +0100 Subject: [PATCH] Add config option to enable/disable QR codes for disables short URLs --- CHANGELOG.md | 17 ++++++++ config/config.php | 3 ++ ...nabledForDisabledShortUrlsConfigOption.php | 27 ++++++++++++ ...edForDisabledShortUrlsConfigOptionTest.php | 42 +++++++++++++++++++ 4 files changed, 89 insertions(+) create mode 100644 src/Config/Option/QrCode/EnabledForDisabledShortUrlsConfigOption.php create mode 100644 test/Config/Option/QrCode/EnabledForDisabledShortUrlsConfigOptionTest.php diff --git a/CHANGELOG.md b/CHANGELOG.md index ccb690c..5f4339f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,23 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com), and this project adheres to [Semantic Versioning](https://semver.org). +## [Unreleased] +### Added +* Add config option to enable/disable QR codes for disables short URLs. + +### Changed +* *Nothing* + +### Deprecated +* *Nothing* + +### Removed +* *Nothing* + +### Fixed +* *Nothing* + + ## [8.6.1] - 2023-12-17 ### Added * *Nothing* diff --git a/config/config.php b/config/config.php index 6b8ddc5..3febcae 100644 --- a/config/config.php +++ b/config/config.php @@ -91,6 +91,8 @@ 'QR codes > Default format' => Config\Option\QrCode\DefaultFormatConfigOption::class, 'QR codes > Default error correction' => Config\Option\QrCode\DefaultErrorCorrectionConfigOption::class, 'QR codes > Default round block size' => Config\Option\QrCode\DefaultRoundBlockSizeConfigOption::class, + 'QR codes > Enabled for disabled short URLs' + => Config\Option\QrCode\EnabledForDisabledShortUrlsConfigOption::class, ], 'APPLICATION' => [ 'Delete short URLs > Visits threshold' => Config\Option\Visit\VisitsThresholdConfigOption::class, @@ -186,6 +188,7 @@ Config\Option\QrCode\DefaultFormatConfigOption::class => InvokableFactory::class, Config\Option\QrCode\DefaultErrorCorrectionConfigOption::class => InvokableFactory::class, Config\Option\QrCode\DefaultRoundBlockSizeConfigOption::class => InvokableFactory::class, + Config\Option\QrCode\EnabledForDisabledShortUrlsConfigOption::class => InvokableFactory::class, ], ], diff --git a/src/Config/Option/QrCode/EnabledForDisabledShortUrlsConfigOption.php b/src/Config/Option/QrCode/EnabledForDisabledShortUrlsConfigOption.php new file mode 100644 index 0000000..674225e --- /dev/null +++ b/src/Config/Option/QrCode/EnabledForDisabledShortUrlsConfigOption.php @@ -0,0 +1,27 @@ +confirm( + 'Should Shlink be able to generate QR codes for short URLs which are not enabled? (Short URLs are not ' + . 'enabled if they have a "valid since" in the future, a "valid until" in the past, or reached the maximum ' + . 'amount of allowed visits)', + // Deprecated. Shlink 4.0.0 should change default value to `true` + false, + ); + } +} diff --git a/test/Config/Option/QrCode/EnabledForDisabledShortUrlsConfigOptionTest.php b/test/Config/Option/QrCode/EnabledForDisabledShortUrlsConfigOptionTest.php new file mode 100644 index 0000000..f9cbe2d --- /dev/null +++ b/test/Config/Option/QrCode/EnabledForDisabledShortUrlsConfigOptionTest.php @@ -0,0 +1,42 @@ +configOption = new EnabledForDisabledShortUrlsConfigOption(); + } + + #[Test] + public function returnsExpectedEnvVar(): void + { + self::assertEquals('QR_CODE_FOR_DISABLED_SHORT_URLS', $this->configOption->getEnvVar()); + } + + #[Test] + public function expectedQuestionIsAsked(): void + { + $io = $this->createMock(StyleInterface::class); + $io->expects($this->once())->method('confirm')->with( + 'Should Shlink be able to generate QR codes for short URLs which are not enabled? (Short URLs are not ' + . 'enabled if they have a "valid since" in the future, a "valid until" in the past, or reached the maximum ' + . 'amount of allowed visits)', + false, + )->willReturn(true); + + $answer = $this->configOption->ask($io, []); + + self::assertEquals(true, $answer); + } +}