2018-03-26 21:17:33 +03:00
|
|
|
<?php
|
2019-10-05 18:26:10 +03:00
|
|
|
|
2018-03-26 21:17:33 +03:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace ShlinkioTest\Shlink\Core\Action;
|
|
|
|
|
2020-01-01 23:11:53 +03:00
|
|
|
use Laminas\Diactoros\ServerRequest;
|
2018-03-26 21:17:33 +03:00
|
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
use Prophecy\Argument;
|
|
|
|
use Prophecy\Prophecy\ObjectProphecy;
|
2019-08-12 19:34:52 +03:00
|
|
|
use Psr\Http\Server\RequestHandlerInterface;
|
2018-03-26 21:17:33 +03:00
|
|
|
use Shlinkio\Shlink\Common\Response\PixelResponse;
|
|
|
|
use Shlinkio\Shlink\Core\Action\PixelAction;
|
2018-08-11 11:40:44 +03:00
|
|
|
use Shlinkio\Shlink\Core\Entity\ShortUrl;
|
2020-02-01 13:46:54 +03:00
|
|
|
use Shlinkio\Shlink\Core\Model\ShortUrlIdentifier;
|
2018-03-26 21:17:33 +03:00
|
|
|
use Shlinkio\Shlink\Core\Options\AppOptions;
|
2020-01-26 21:21:51 +03:00
|
|
|
use Shlinkio\Shlink\Core\Service\ShortUrl\ShortUrlResolverInterface;
|
2018-03-26 21:17:33 +03:00
|
|
|
use Shlinkio\Shlink\Core\Service\VisitsTracker;
|
|
|
|
|
|
|
|
class PixelActionTest extends TestCase
|
|
|
|
{
|
2019-12-30 00:27:00 +03:00
|
|
|
private PixelAction $action;
|
2020-01-26 21:21:51 +03:00
|
|
|
private ObjectProphecy $urlResolver;
|
2019-12-30 00:27:00 +03:00
|
|
|
private ObjectProphecy $visitTracker;
|
2018-03-26 21:17:33 +03:00
|
|
|
|
2019-02-16 12:53:45 +03:00
|
|
|
public function setUp(): void
|
2018-03-26 21:17:33 +03:00
|
|
|
{
|
2020-01-26 21:21:51 +03:00
|
|
|
$this->urlResolver = $this->prophesize(ShortUrlResolverInterface::class);
|
2018-03-26 21:17:33 +03:00
|
|
|
$this->visitTracker = $this->prophesize(VisitsTracker::class);
|
|
|
|
|
|
|
|
$this->action = new PixelAction(
|
2020-01-26 21:21:51 +03:00
|
|
|
$this->urlResolver->reveal(),
|
2018-03-26 21:17:33 +03:00
|
|
|
$this->visitTracker->reveal(),
|
2020-01-01 22:48:31 +03:00
|
|
|
new AppOptions(),
|
2018-03-26 21:17:33 +03:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-02-17 22:28:34 +03:00
|
|
|
/** @test */
|
2019-08-12 19:34:52 +03:00
|
|
|
public function imageIsReturned(): void
|
2018-03-26 21:17:33 +03:00
|
|
|
{
|
|
|
|
$shortCode = 'abc123';
|
2020-02-01 13:46:54 +03:00
|
|
|
$this->urlResolver->resolveEnabledShortUrl(new ShortUrlIdentifier($shortCode, ''))->willReturn(
|
2020-01-01 22:48:31 +03:00
|
|
|
new ShortUrl('http://domain.com/foo/bar'),
|
2018-11-11 15:18:21 +03:00
|
|
|
)->shouldBeCalledOnce();
|
|
|
|
$this->visitTracker->track(Argument::cetera())->shouldBeCalledOnce();
|
2018-03-26 21:17:33 +03:00
|
|
|
|
2018-12-26 01:01:30 +03:00
|
|
|
$request = (new ServerRequest())->withAttribute('shortCode', $shortCode);
|
2019-08-12 19:34:52 +03:00
|
|
|
$response = $this->action->process($request, $this->prophesize(RequestHandlerInterface::class)->reveal());
|
2018-03-26 21:17:33 +03:00
|
|
|
|
2020-10-04 01:35:14 +03:00
|
|
|
self::assertInstanceOf(PixelResponse::class, $response);
|
|
|
|
self::assertEquals(200, $response->getStatusCode());
|
|
|
|
self::assertEquals('image/gif', $response->getHeaderLine('content-type'));
|
2018-03-26 21:17:33 +03:00
|
|
|
}
|
|
|
|
}
|