Skip to content

Commit

Permalink
Merge pull request #223 from acelaya-forks/feature/robots-user-agents
Browse files Browse the repository at this point in the history
Feature/robots user agents
  • Loading branch information
acelaya authored Jul 5, 2024
2 parents f7e3343 + 1c1cb75 commit ccda72e
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 11 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com), and this
## [Unreleased]
### Added
* Add `ROBOTS_ALLOW_ALL_SHORT_URLS` config option.
* Add `ROBOTS_USER_AGENTS` config option.

### Changed
* Update to PHPUnit 11
Expand Down
10 changes: 5 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
"laminas/laminas-config-aggregator": "^1.15",
"laminas/laminas-servicemanager": "^3.22",
"laminas/laminas-stdlib": "^3.19",
"shlinkio/shlink-config": "^3.0 || ^2.5",
"symfony/console": "^7.0 || ^6.4",
"symfony/filesystem": "^7.0 || ^6.4",
"symfony/process": "^7.0 || ^6.4"
"shlinkio/shlink-config": "^3.0",
"symfony/console": "^7.1",
"symfony/filesystem": "^7.1",
"symfony/process": "^7.1"
},
"require-dev": {
"devster/ubench": "^2.1",
Expand All @@ -29,7 +29,7 @@
"phpunit/phpunit": "^11.1",
"roave/security-advisories": "dev-master",
"shlinkio/php-coding-standard": "~2.3.0",
"symfony/var-dumper": "^7.0 || ^6.4"
"symfony/var-dumper": "^7.1"
},
"autoload": {
"psr-4": {
Expand Down
8 changes: 5 additions & 3 deletions config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,6 @@
=> 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 @@ -98,6 +96,10 @@
'QR codes > Enabled for disabled short URLs'
=> Config\Option\QrCode\EnabledForDisabledShortUrlsConfigOption::class,
],
'ROBOTS' => [
'Robots.txt > allow all' => Config\Option\Robots\RobotsAllowAllShortUrlsConfigOption::class,
'Robots.txt > user agents' => Config\Option\Robots\RobotsUserAgentsConfigOption::class,
],
'APPLICATION' => [
'Delete short URLs > Visits threshold' => Config\Option\Visit\VisitsThresholdConfigOption::class,
'Base path' => Config\Option\BasePathConfigOption::class,
Expand Down Expand Up @@ -150,7 +152,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\Robots\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
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

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

use Shlinkio\Shlink\Installer\Config\Option\BaseConfigOption;
use Symfony\Component\Console\Style\StyleInterface;
Expand Down
23 changes: 23 additions & 0 deletions src/Config/Option/Robots/RobotsUserAgentsConfigOption.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

declare(strict_types=1);

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

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

class RobotsUserAgentsConfigOption extends BaseConfigOption
{
public function getEnvVar(): string
{
return 'ROBOTS_USER_AGENTS';
}

public function ask(StyleInterface $io, array $currentOptions): ?string
{
return $io->ask(
'Provide a comma-separated list of user agents for your robots.txt file. Defaults to all user agents (*)',
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

declare(strict_types=1);

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

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

class RobotsAllowAllShortUrlsConfigOptionTest extends TestCase
Expand Down
39 changes: 39 additions & 0 deletions test/Config/Option/Robots/RobotsUserAgentsConfigOptionTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

declare(strict_types=1);

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

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

class RobotsUserAgentsConfigOptionTest extends TestCase
{
private RobotsUserAgentsConfigOption $configOption;

public function setUp(): void
{
$this->configOption = new RobotsUserAgentsConfigOption();
}

#[Test]
public function returnsExpectedEnvVar(): void
{
self::assertEquals('ROBOTS_USER_AGENTS', $this->configOption->getEnvVar());
}

#[Test]
public function expectedQuestionIsAsked(): void
{
$io = $this->createMock(StyleInterface::class);
$io->expects($this->once())->method('ask')->with(
'Provide a comma-separated list of user agents for your robots.txt file. Defaults to all user agents (*)',
)->willReturn('foo,bar');

$answer = $this->configOption->ask($io, []);

self::assertEquals('foo,bar', $answer);
}
}

0 comments on commit ccda72e

Please sign in to comment.