-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for ROBOTS_ALLOW_ALL_SHORT_URLS
- Loading branch information
Showing
4 changed files
with
86 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
src/Config/Option/UrlShortener/RobotsAllowAllShortUrlsConfigOption.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
); | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
test/Config/Option/UrlShortener/RobotsAllowAllShortUrlsConfigOptionTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |