2018-03-26 13:17:33 -05:00
|
|
|
<?php
|
2019-10-05 10:26:10 -05:00
|
|
|
|
2018-03-26 13:17:33 -05:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace ShlinkioTest\Shlink\Core\Action;
|
|
|
|
|
2020-01-01 14:11:53 -06:00
|
|
|
use Laminas\Diactoros\ServerRequest;
|
2022-10-21 11:32:34 -05:00
|
|
|
use PHPUnit\Framework\MockObject\MockObject;
|
2018-03-26 13:17:33 -05:00
|
|
|
use PHPUnit\Framework\TestCase;
|
2019-08-12 11:34:52 -05:00
|
|
|
use Psr\Http\Server\RequestHandlerInterface;
|
2018-03-26 13:17:33 -05:00
|
|
|
use Shlinkio\Shlink\Common\Response\PixelResponse;
|
|
|
|
use Shlinkio\Shlink\Core\Action\PixelAction;
|
2022-09-23 12:03:32 -05:00
|
|
|
use Shlinkio\Shlink\Core\ShortUrl\Entity\ShortUrl;
|
2022-09-23 11:05:17 -05:00
|
|
|
use Shlinkio\Shlink\Core\ShortUrl\Model\ShortUrlIdentifier;
|
2022-09-23 11:42:38 -05:00
|
|
|
use Shlinkio\Shlink\Core\ShortUrl\ShortUrlResolverInterface;
|
2021-07-15 10:23:09 -05:00
|
|
|
use Shlinkio\Shlink\Core\Visit\RequestTrackerInterface;
|
2018-03-26 13:17:33 -05:00
|
|
|
|
|
|
|
class PixelActionTest extends TestCase
|
|
|
|
{
|
2019-12-29 15:27:00 -06:00
|
|
|
private PixelAction $action;
|
2022-10-24 12:53:13 -05:00
|
|
|
private MockObject & ShortUrlResolverInterface $urlResolver;
|
|
|
|
private MockObject & RequestTrackerInterface $requestTracker;
|
2018-03-26 13:17:33 -05:00
|
|
|
|
2022-09-11 05:02:49 -05:00
|
|
|
protected function setUp(): void
|
2018-03-26 13:17:33 -05:00
|
|
|
{
|
2022-10-21 11:32:34 -05:00
|
|
|
$this->urlResolver = $this->createMock(ShortUrlResolverInterface::class);
|
|
|
|
$this->requestTracker = $this->createMock(RequestTrackerInterface::class);
|
2018-03-26 13:17:33 -05:00
|
|
|
|
2022-10-21 11:32:34 -05:00
|
|
|
$this->action = new PixelAction($this->urlResolver, $this->requestTracker);
|
2018-03-26 13:17:33 -05:00
|
|
|
}
|
|
|
|
|
2019-02-17 13:28:34 -06:00
|
|
|
/** @test */
|
2019-08-12 11:34:52 -05:00
|
|
|
public function imageIsReturned(): void
|
2018-03-26 13:17:33 -05:00
|
|
|
{
|
|
|
|
$shortCode = 'abc123';
|
2022-10-21 11:32:34 -05:00
|
|
|
$this->urlResolver->expects($this->once())->method('resolveEnabledShortUrl')->with(
|
2022-10-23 11:15:57 -05:00
|
|
|
ShortUrlIdentifier::fromShortCodeAndDomain($shortCode, ''),
|
2022-10-21 11:32:34 -05:00
|
|
|
)->willReturn(ShortUrl::withLongUrl('http://domain.com/foo/bar'));
|
|
|
|
$this->requestTracker->expects($this->once())->method('trackIfApplicable')->withAnyParameters();
|
2018-03-26 13:17:33 -05:00
|
|
|
|
2018-12-25 16:01:30 -06:00
|
|
|
$request = (new ServerRequest())->withAttribute('shortCode', $shortCode);
|
2022-10-21 11:32:34 -05:00
|
|
|
$response = $this->action->process($request, $this->createMock(RequestHandlerInterface::class));
|
2018-03-26 13:17:33 -05:00
|
|
|
|
2020-10-03 17:35:14 -05:00
|
|
|
self::assertInstanceOf(PixelResponse::class, $response);
|
|
|
|
self::assertEquals(200, $response->getStatusCode());
|
|
|
|
self::assertEquals('image/gif', $response->getHeaderLine('content-type'));
|
2018-03-26 13:17:33 -05:00
|
|
|
}
|
|
|
|
}
|