From 8b9663aea096a63077a810947761a861e0836603 Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Sat, 2 Nov 2019 17:04:49 +0100 Subject: [PATCH] Created DeprecatedConfigParserTest --- .../src/Config/DeprecatedConfigParser.php | 6 +- .../Config/DeprecatedConfigParserTest.php | 95 +++++++++++++++++++ 2 files changed, 100 insertions(+), 1 deletion(-) create mode 100644 module/Core/test/Config/DeprecatedConfigParserTest.php diff --git a/module/Core/src/Config/DeprecatedConfigParser.php b/module/Core/src/Config/DeprecatedConfigParser.php index faa56c38..059c81a9 100644 --- a/module/Core/src/Config/DeprecatedConfigParser.php +++ b/module/Core/src/Config/DeprecatedConfigParser.php @@ -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; } diff --git a/module/Core/test/Config/DeprecatedConfigParserTest.php b/module/Core/test/Config/DeprecatedConfigParserTest.php new file mode 100644 index 00000000..be76ba80 --- /dev/null +++ b/module/Core/test/Config/DeprecatedConfigParserTest.php @@ -0,0 +1,95 @@ +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); + } +}