mirror of
https://github.com/shlinkio/shlink.git
synced 2024-12-29 02:11:10 -06:00
Created DeprecatedConfigParserTest
This commit is contained in:
parent
b59f4e2805
commit
8b9663aea0
@ -21,8 +21,12 @@ class DeprecatedConfigParser
|
||||
}
|
||||
|
||||
$oldRedirectEnabled = $config['url_shortener']['not_found_short_url']['enable_redirection'] ?? false;
|
||||
if (! $oldRedirectEnabled) {
|
||||
return $config;
|
||||
}
|
||||
|
||||
$oldRedirectValue = $config['url_shortener']['not_found_short_url']['redirect_to'] ?? null;
|
||||
$config['not_found_redirects']['invalid_short_url'] = $oldRedirectEnabled ? $oldRedirectValue : null;
|
||||
$config['not_found_redirects']['invalid_short_url'] = $oldRedirectValue;
|
||||
|
||||
return $config;
|
||||
}
|
||||
|
95
module/Core/test/Config/DeprecatedConfigParserTest.php
Normal file
95
module/Core/test/Config/DeprecatedConfigParserTest.php
Normal file
@ -0,0 +1,95 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace ShlinkioTest\Shlink\Core\Config;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Shlinkio\Shlink\Core\Config\DeprecatedConfigParser;
|
||||
|
||||
use function array_merge;
|
||||
|
||||
class DeprecatedConfigParserTest extends TestCase
|
||||
{
|
||||
/** @var DeprecatedConfigParser */
|
||||
private $postProcessor;
|
||||
|
||||
public function setUp(): void
|
||||
{
|
||||
$this->postProcessor = new DeprecatedConfigParser();
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function returnsConfigAsIsIfNewValueIsDefined(): void
|
||||
{
|
||||
$config = [
|
||||
'not_found_redirects' => [
|
||||
'invalid_short_url' => 'somewhere',
|
||||
],
|
||||
];
|
||||
|
||||
$result = ($this->postProcessor)($config);
|
||||
|
||||
$this->assertEquals($config, $result);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function doesNotProvideNewConfigIfOldOneIsDefinedButDisabled(): void
|
||||
{
|
||||
$config = [
|
||||
'url_shortener' => [
|
||||
'not_found_short_url' => [
|
||||
'enable_redirection' => false,
|
||||
'redirect_to' => 'somewhere',
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
$result = ($this->postProcessor)($config);
|
||||
|
||||
$this->assertEquals($config, $result);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function mapsOldConfigToNewOneWhenOldOneIsEnabled(): void
|
||||
{
|
||||
$config = [
|
||||
'url_shortener' => [
|
||||
'not_found_short_url' => [
|
||||
'enable_redirection' => true,
|
||||
'redirect_to' => 'somewhere',
|
||||
],
|
||||
],
|
||||
];
|
||||
$expected = array_merge($config, [
|
||||
'not_found_redirects' => [
|
||||
'invalid_short_url' => 'somewhere',
|
||||
],
|
||||
]);
|
||||
|
||||
$result = ($this->postProcessor)($config);
|
||||
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function definesNewConfigAsNullIfOldOneIsEnabledWithNoRedirectValue(): void
|
||||
{
|
||||
$config = [
|
||||
'url_shortener' => [
|
||||
'not_found_short_url' => [
|
||||
'enable_redirection' => true,
|
||||
],
|
||||
],
|
||||
];
|
||||
$expected = array_merge($config, [
|
||||
'not_found_redirects' => [
|
||||
'invalid_short_url' => null,
|
||||
],
|
||||
]);
|
||||
|
||||
$result = ($this->postProcessor)($config);
|
||||
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user