Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for ROBOTS_ALLOW_ALL_SHORT_URLS #220

Merged
merged 1 commit into from
Apr 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 `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.
Expand Down
3 changes: 3 additions & 0 deletions config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

declare(strict_types=1);

namespace Shlinkio\Shlink\Installer\Config\Option\UrlShortener;

use Shlinkio\Shlink\Installer\Config\Option\BaseConfigOption;
use Symfony\Component\Console\Style\StyleInterface;

class RobotsAllowAllShortUrlsConfigOption extends BaseConfigOption
{
public function getEnvVar(): string
{
return 'ROBOTS_ALLOW_ALL_SHORT_URLS';
}

public function ask(StyleInterface $io, array $currentOptions): bool
{
return $io->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,
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

declare(strict_types=1);

namespace ShlinkioTest\Shlink\Installer\Config\Option\UrlShortener;

use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;
use Shlinkio\Shlink\Installer\Config\Option\UrlShortener\RobotsAllowAllShortUrlsConfigOption;
use Symfony\Component\Console\Style\StyleInterface;

class RobotsAllowAllShortUrlsConfigOptionTest extends TestCase
{
private RobotsAllowAllShortUrlsConfigOption $configOption;

public function setUp(): void
{
$this->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);
}
}
Loading