2021-05-22 00:15:34 -05:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace ShlinkioTest\Shlink\Core\Action;
|
|
|
|
|
|
|
|
use Laminas\Diactoros\ServerRequestFactory;
|
2022-10-12 11:23:36 -05:00
|
|
|
use PHPUnit\Framework\MockObject\MockObject;
|
2021-05-22 00:15:34 -05:00
|
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
use Shlinkio\Shlink\Core\Action\RobotsAction;
|
|
|
|
use Shlinkio\Shlink\Core\Crawling\CrawlingHelperInterface;
|
|
|
|
|
|
|
|
class RobotsActionTest extends TestCase
|
|
|
|
{
|
|
|
|
private RobotsAction $action;
|
2022-10-24 12:53:13 -05:00
|
|
|
private MockObject & CrawlingHelperInterface $helper;
|
2021-05-22 00:15:34 -05:00
|
|
|
|
|
|
|
protected function setUp(): void
|
|
|
|
{
|
2022-10-12 11:23:36 -05:00
|
|
|
$this->helper = $this->createMock(CrawlingHelperInterface::class);
|
|
|
|
$this->action = new RobotsAction($this->helper);
|
2021-05-22 00:15:34 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
* @dataProvider provideShortCodes
|
|
|
|
*/
|
|
|
|
public function buildsRobotsLinesFromCrawlableShortCodes(array $shortCodes, string $expected): void
|
|
|
|
{
|
2022-10-12 11:23:36 -05:00
|
|
|
$this->helper
|
|
|
|
->expects($this->once())
|
|
|
|
->method('listCrawlableShortCodes')
|
|
|
|
->willReturn($shortCodes);
|
2021-05-22 00:15:34 -05:00
|
|
|
|
|
|
|
$response = $this->action->handle(ServerRequestFactory::fromGlobals());
|
|
|
|
|
|
|
|
self::assertEquals(200, $response->getStatusCode());
|
|
|
|
self::assertEquals($expected, $response->getBody()->__toString());
|
|
|
|
self::assertEquals('text/plain', $response->getHeaderLine('Content-Type'));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function provideShortCodes(): iterable
|
|
|
|
{
|
|
|
|
yield 'three short codes' => [['foo', 'bar', 'baz'], <<<ROBOTS
|
|
|
|
# For more information about the robots.txt standard, see:
|
|
|
|
# https://www.robotstxt.org/orig.html
|
|
|
|
|
|
|
|
User-agent: *
|
|
|
|
Allow: /foo
|
|
|
|
Allow: /bar
|
|
|
|
Allow: /baz
|
|
|
|
Disallow: /
|
|
|
|
ROBOTS];
|
|
|
|
yield 'five short codes' => [['foo', 'bar', 'some', 'thing', 'baz'], <<<ROBOTS
|
|
|
|
# For more information about the robots.txt standard, see:
|
|
|
|
# https://www.robotstxt.org/orig.html
|
|
|
|
|
|
|
|
User-agent: *
|
|
|
|
Allow: /foo
|
|
|
|
Allow: /bar
|
|
|
|
Allow: /some
|
|
|
|
Allow: /thing
|
|
|
|
Allow: /baz
|
|
|
|
Disallow: /
|
|
|
|
ROBOTS];
|
|
|
|
yield 'no short codes' => [[], <<<ROBOTS
|
|
|
|
# For more information about the robots.txt standard, see:
|
|
|
|
# https://www.robotstxt.org/orig.html
|
|
|
|
|
|
|
|
User-agent: *
|
|
|
|
Disallow: /
|
|
|
|
ROBOTS];
|
|
|
|
}
|
|
|
|
}
|