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;
|
2020-11-02 13:50:19 +03:00
|
|
|
use Prophecy\PhpUnit\ProphecyTrait;
|
2018-03-26 21:17:33 +03:00
|
|
|
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;
|
2020-01-26 21:21:51 +03:00
|
|
|
use Shlinkio\Shlink\Core\Service\ShortUrl\ShortUrlResolverInterface;
|
2021-07-15 18:23:09 +03:00
|
|
|
use Shlinkio\Shlink\Core\Visit\RequestTrackerInterface;
|
2018-03-26 21:17:33 +03:00
|
|
|
|
|
|
|
class PixelActionTest extends TestCase
|
|
|
|
{
|
2020-11-02 13:50:19 +03:00
|
|
|
use ProphecyTrait;
|
|
|
|
|
2019-12-30 00:27:00 +03:00
|
|
|
private PixelAction $action;
|
2020-01-26 21:21:51 +03:00
|
|
|
private ObjectProphecy $urlResolver;
|
2021-07-15 18:23:09 +03:00
|
|
|
private ObjectProphecy $requestTracker;
|
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);
|
2021-07-15 18:23:09 +03:00
|
|
|
$this->requestTracker = $this->prophesize(RequestTrackerInterface::class);
|
2018-03-26 21:17:33 +03:00
|
|
|
|
2021-07-15 18:23:09 +03:00
|
|
|
$this->action = new PixelAction($this->urlResolver->reveal(), $this->requestTracker->reveal());
|
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(
|
2021-01-30 16:18:44 +03:00
|
|
|
ShortUrl::withLongUrl('http://domain.com/foo/bar'),
|
2018-11-11 15:18:21 +03:00
|
|
|
)->shouldBeCalledOnce();
|
2021-07-15 18:23:09 +03:00
|
|
|
$this->requestTracker->trackIfApplicable(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
|
|
|
}
|
|
|
|
}
|