From 26f9dab58e33e6509a553998c3609c8f23e5668a Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Mon, 22 Apr 2024 09:14:09 +0200 Subject: [PATCH] Add support for ROBOTS_ALLOW_ALL_SHORT_URLS --- CHANGELOG.md | 17 ++++++++ config/config.php | 3 ++ .../RobotsAllowAllShortUrlsConfigOption.php | 25 +++++++++++ ...obotsAllowAllShortUrlsConfigOptionTest.php | 41 +++++++++++++++++++ 4 files changed, 86 insertions(+) create mode 100644 src/Config/Option/UrlShortener/RobotsAllowAllShortUrlsConfigOption.php create mode 100644 test/Config/Option/UrlShortener/RobotsAllowAllShortUrlsConfigOptionTest.php diff --git a/CHANGELOG.md b/CHANGELOG.md index 4026134..7199071 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 `ROBOTS_ALLOW_ALL_SHORT_URLS` config option. + +### Changed +* *Nothing* + +### Deprecated +* *Nothing* + +### Removed +* *Nothing* + +### Fixed +* *Nothing* + + ## [9.1.0] - 2024-04-14 ### Added * Add `MEMORY_LIMIT` config option. diff --git a/config/config.php b/config/config.php index 855af5d..4d04dcc 100644 --- a/config/config.php +++ b/config/config.php @@ -64,6 +64,8 @@ => Config\Option\UrlShortener\EnableMultiSegmentSlugsConfigOption::class, 'URL shortener > Trailing slashes' => Config\Option\UrlShortener\EnableTrailingSlashConfigOption::class, 'URL shortener > Mode' => Config\Option\UrlShortener\ShortUrlModeConfigOption::class, + 'URL shortener > robots.txt allow all' + => Config\Option\UrlShortener\RobotsAllowAllShortUrlsConfigOption::class, 'GeoLite2 license key' => Config\Option\UrlShortener\GeoLiteLicenseKeyConfigOption::class, 'Redirects > Status code (301/302)' => Config\Option\UrlShortener\RedirectStatusCodeConfigOption::class, 'Redirects > Caching life time' => Config\Option\UrlShortener\RedirectCacheLifeTimeConfigOption::class, @@ -148,6 +150,7 @@ Config\Option\UrlShortener\EnableMultiSegmentSlugsConfigOption::class => InvokableFactory::class, Config\Option\UrlShortener\EnableTrailingSlashConfigOption::class => InvokableFactory::class, Config\Option\UrlShortener\ShortUrlModeConfigOption::class => InvokableFactory::class, + Config\Option\UrlShortener\RobotsAllowAllShortUrlsConfigOption::class => InvokableFactory::class, Config\Option\Redis\RedisServersConfigOption::class => InvokableFactory::class, Config\Option\Redis\RedisSentinelServiceConfigOption::class => InvokableFactory::class, Config\Option\Redis\RedisPubSubConfigOption::class => InvokableFactory::class, diff --git a/src/Config/Option/UrlShortener/RobotsAllowAllShortUrlsConfigOption.php b/src/Config/Option/UrlShortener/RobotsAllowAllShortUrlsConfigOption.php new file mode 100644 index 0000000..7eccfec --- /dev/null +++ b/src/Config/Option/UrlShortener/RobotsAllowAllShortUrlsConfigOption.php @@ -0,0 +1,25 @@ +confirm( + 'Do you want all short URLs to be crawlable/allowed by the robots.txt file? ' + . 'You can still allow them individually, regardless of this.', + default: false, + ); + } +} diff --git a/test/Config/Option/UrlShortener/RobotsAllowAllShortUrlsConfigOptionTest.php b/test/Config/Option/UrlShortener/RobotsAllowAllShortUrlsConfigOptionTest.php new file mode 100644 index 0000000..ca3d987 --- /dev/null +++ b/test/Config/Option/UrlShortener/RobotsAllowAllShortUrlsConfigOptionTest.php @@ -0,0 +1,41 @@ +configOption = new RobotsAllowAllShortUrlsConfigOption(); + } + + #[Test] + public function returnsExpectedEnvVar(): void + { + self::assertEquals('ROBOTS_ALLOW_ALL_SHORT_URLS', $this->configOption->getEnvVar()); + } + + #[Test] + public function expectedQuestionIsAsked(): void + { + $io = $this->createMock(StyleInterface::class); + $io->expects($this->once())->method('confirm')->with( + 'Do you want all short URLs to be crawlable/allowed by the robots.txt file? ' + . 'You can still allow them individually, regardless of this.', + false, + )->willReturn(true); + + $answer = $this->configOption->ask($io, []); + + self::assertTrue($answer); + } +}