-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #209 from acelaya-forks/feature/enable-qr-codes
Add config option to enable/disable QR codes for disables short URLs
- Loading branch information
Showing
4 changed files
with
89 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
src/Config/Option/QrCode/EnabledForDisabledShortUrlsConfigOption.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Shlinkio\Shlink\Installer\Config\Option\QrCode; | ||
|
||
use Shlinkio\Shlink\Installer\Config\Option\BaseConfigOption; | ||
use Symfony\Component\Console\Style\StyleInterface; | ||
|
||
class EnabledForDisabledShortUrlsConfigOption extends BaseConfigOption | ||
{ | ||
public function getEnvVar(): string | ||
{ | ||
return 'QR_CODE_FOR_DISABLED_SHORT_URLS'; | ||
} | ||
|
||
public function ask(StyleInterface $io, array $currentOptions): bool | ||
{ | ||
return $io->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, | ||
); | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
test/Config/Option/QrCode/EnabledForDisabledShortUrlsConfigOptionTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace ShlinkioTest\Shlink\Installer\Config\Option\QrCode; | ||
|
||
use PHPUnit\Framework\Attributes\Test; | ||
use PHPUnit\Framework\TestCase; | ||
use Shlinkio\Shlink\Installer\Config\Option\QrCode\EnabledForDisabledShortUrlsConfigOption; | ||
use Symfony\Component\Console\Style\StyleInterface; | ||
|
||
class EnabledForDisabledShortUrlsConfigOptionTest extends TestCase | ||
{ | ||
private EnabledForDisabledShortUrlsConfigOption $configOption; | ||
|
||
public function setUp(): void | ||
{ | ||
$this->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); | ||
} | ||
} |