Skip to content

Commit

Permalink
Merge pull request #220 from acelaya-forks/feature/robots-allow-all
Browse files Browse the repository at this point in the history
Add support for ROBOTS_ALLOW_ALL_SHORT_URLS
  • Loading branch information
acelaya authored Apr 22, 2024
2 parents 2d84b37 + 26f9dab commit 11e66d8
Show file tree
Hide file tree
Showing 4 changed files with 86 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 `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);
}
}

0 comments on commit 11e66d8

Please sign in to comment.