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

Feature/robots user agents #223

Merged
merged 2 commits into from
Jul 5, 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
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);
}
}
Loading