Skip to content

Commit

Permalink
Merge pull request #209 from acelaya-forks/feature/enable-qr-codes
Browse files Browse the repository at this point in the history
Add config option to enable/disable QR codes for disables short URLs
  • Loading branch information
acelaya authored Dec 24, 2023
2 parents ff4c09c + 67c20c0 commit 62aae8d
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 0 deletions.
17 changes: 17 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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*
Expand Down
3 changes: 3 additions & 0 deletions config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
],
],

Expand Down
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,
);
}
}
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);
}
}

0 comments on commit 62aae8d

Please sign in to comment.