|
1 | 1 | <?php declare(strict_types=1);
|
2 | 2 |
|
3 |
| -namespace Frosh\ThumbnailProcessor\TestsUnit\Service; |
| 3 | +namespace Frosh\ThumbnailProcessor\Tests\Unit\Service; |
4 | 4 |
|
5 | 5 | use Frosh\ThumbnailProcessor\Service\ConfigReader;
|
6 | 6 | use Frosh\ThumbnailProcessor\Service\ThumbnailUrlTemplate;
|
|
9 | 9 |
|
10 | 10 | class ThumbnailUrlTemplateTest extends TestCase
|
11 | 11 | {
|
12 |
| - /** |
| 12 | + /** |
13 | 13 | * @dataProvider getSalesChannelIds
|
14 | 14 | */
|
15 |
| - public function testGetUrl(?string $salesChannelId, string $mediaUrl, string $mediaPath, string $width): void |
| 15 | + public function testGetUrl(?string $salesChannelId, string $mediaUrl, string $mediaPath, string $width, ?\DateTimeInterface $date): void |
16 | 16 | {
|
17 | 17 | $configReader = $this->createMock(ConfigReader::class);
|
18 | 18 | $configReader->expects(static::once())
|
19 |
| - ->method('getConfig')->willReturn('{mediaUrl}/{mediaPath}?width={width}&uff'); |
| 19 | + ->method('getConfig')->willReturn('{mediaUrl}/{mediaPath}?width={width}&updatedAt={mediaUpdatedAt}&uff'); |
20 | 20 |
|
21 | 21 | $class = new ThumbnailUrlTemplate($configReader);
|
22 | 22 |
|
23 |
| - $url = $class->getUrl($mediaUrl, $mediaPath, $width); |
| 23 | + $url = $class->getUrl($mediaUrl, $mediaPath, $width, $date); |
24 | 24 |
|
25 |
| - static::assertSame(\sprintf('%s/%s?width=%s&uff', $mediaUrl, $mediaPath, $width), $url); |
| 25 | + static::assertSame(\sprintf('%s/%s?width=%s&updatedAt=%s&uff', $mediaUrl, $mediaPath, $width, $date?->getTimestamp() ?: '0'), $url); |
26 | 26 | }
|
27 | 27 |
|
28 | 28 | /**
|
29 | 29 | * @dataProvider getSalesChannelIds
|
30 | 30 | */
|
31 |
| - public function testGetUrlWithoutSetConfig(?string $salesChannelId, string $mediaUrl, string $mediaPath, string $width): void |
| 31 | + public function testGetUrlWithoutSetConfig(?string $salesChannelId, string $mediaUrl, string $mediaPath, string $width, ?\DateTimeInterface $date): void |
32 | 32 | {
|
33 | 33 | $configReader = $this->createMock(ConfigReader::class);
|
34 | 34 | $configReader->expects(static::once())
|
35 |
| - ->method('getConfig')->willReturn('{mediaUrl}/{mediaPath}?width={width}'); |
| 35 | + ->method('getConfig')->willReturn('{mediaUrl}/{mediaPath}?width={width}&updatedAt={mediaUpdatedAt}'); |
36 | 36 |
|
37 | 37 | $class = new ThumbnailUrlTemplate($configReader);
|
38 | 38 |
|
39 |
| - $url = $class->getUrl($mediaUrl, $mediaPath, $width); |
| 39 | + $url = $class->getUrl($mediaUrl, $mediaPath, $width, $date); |
40 | 40 |
|
41 |
| - static::assertSame(\sprintf('%s/%s?width=%s', $mediaUrl, $mediaPath, $width), $url); |
| 41 | + static::assertSame(\sprintf('%s/%s?width=%s&updatedAt=%s', $mediaUrl, $mediaPath, $width, $date?->getTimestamp() ?: '0'), $url); |
42 | 42 | }
|
43 | 43 |
|
44 | 44 | /**
|
45 | 45 | * @dataProvider getSalesChannelIds
|
46 | 46 | */
|
47 |
| - public function testGetUrlGetPatternOnce(?string $salesChannelId, string $mediaUrl, string $mediaPath, string $width): void |
| 47 | + public function testGetUrlGetPatternOnce(?string $salesChannelId, string $mediaUrl, string $mediaPath, string $width, ?\DateTimeInterface $date): void |
48 | 48 | {
|
49 | 49 | $configReader = $this->createMock(ConfigReader::class);
|
50 | 50 | $configReader->expects(static::once())
|
51 |
| - ->method('getConfig')->willReturn('{mediaUrl}/{mediaPath}?width={width}'); |
| 51 | + ->method('getConfig')->willReturn('{mediaUrl}/{mediaPath}?width={width}&updatedAt={mediaUpdatedAt}'); |
52 | 52 |
|
53 | 53 | $class = new ThumbnailUrlTemplate($configReader);
|
54 | 54 |
|
55 |
| - $class->getUrl($mediaUrl, $mediaPath, $width); |
| 55 | + $class->getUrl($mediaUrl, $mediaPath, $width, $date); |
56 | 56 |
|
57 |
| - $url = $class->getUrl($mediaUrl, $mediaPath, $width); |
| 57 | + $url = $class->getUrl($mediaUrl, $mediaPath, $width, $date); |
58 | 58 |
|
59 |
| - static::assertSame(\sprintf('%s/%s?width=%s', $mediaUrl, $mediaPath, $width), $url); |
| 59 | + static::assertSame(\sprintf('%s/%s?width=%s&updatedAt=%s', $mediaUrl, $mediaPath, $width, $date?->getTimestamp() ?: '0'), $url); |
60 | 60 | }
|
61 | 61 |
|
62 | 62 | /**
|
63 | 63 | * @return iterable<array{string|null, string, string, string}>
|
64 | 64 | */
|
65 | 65 | public static function getSalesChannelIds(): iterable
|
66 | 66 | {
|
67 |
| - yield [null, 'https://www.anywebpage.test', 'media/78/a1/myimage.jpg', '200']; |
68 |
| - yield [Uuid::randomHex(), 'https://www.anyotherwebpage.test', 'media/aa/a1/myimage.jpg', '300']; |
69 |
| - yield [Uuid::randomHex(), 'https://www.anyother2webpage.test', 'media/aa/bb/myimage.jpg', '700']; |
70 |
| - yield [Uuid::randomHex(), 'https://www.anyother3webpage.test', 'media/aa/cc/myimage.jpg', '900']; |
71 |
| - yield [Uuid::randomHex(), 'https://www.anyother4webpage.test', 'media/aa/dd/myimage.jpg', '1000']; |
| 67 | + yield [null, 'https://www.anywebpage.test', 'media/78/a1/myimage.jpg', '200', null]; |
| 68 | + yield [null, 'https://www.anyotherwebpage.test', 'media/78/a1/myimage.jpg', '200', new \DateTimeImmutable()]; |
| 69 | + yield [Uuid::randomHex(), 'https://www.anyother2webpage.test', 'media/aa/a1/myimage.jpg', '300', new \DateTimeImmutable()]; |
| 70 | + yield [Uuid::randomHex(), 'https://www.anyother3webpage.test', 'media/aa/bb/myimage.jpg', '700', null]; |
| 71 | + yield [Uuid::randomHex(), 'https://www.anyother4webpage.test', 'media/aa/cc/myimage.jpg', '900', new \DateTimeImmutable()]; |
| 72 | + yield [Uuid::randomHex(), 'https://www.anyother5webpage.test', 'media/aa/dd/myimage.jpg', '1000', null]; |
72 | 73 | }
|
73 | 74 | }
|
0 commit comments