|
| 1 | +<?php |
| 2 | + |
| 3 | +/** |
| 4 | + * @copyright Copyright (C) Ibexa AS. All rights reserved. |
| 5 | + * @license For full copyright and license information view LICENSE file distributed with this source code. |
| 6 | + */ |
| 7 | +declare(strict_types=1); |
| 8 | + |
| 9 | +namespace Ibexa\Tests\Bundle\Core\Imagine\VariationPathGenerator; |
| 10 | + |
| 11 | +use Ibexa\Bundle\Core\Imagine\Filter\FilterConfiguration; |
| 12 | +use Ibexa\Bundle\Core\Imagine\VariationPathGenerator; |
| 13 | +use Ibexa\Bundle\Core\Imagine\VariationPathGenerator\WebpFormatVariationPathGenerator; |
| 14 | +use PHPUnit\Framework\TestCase; |
| 15 | + |
| 16 | +final class WebpFormatVariationPathGeneratorTest extends TestCase |
| 17 | +{ |
| 18 | + /** @var \Ibexa\Bundle\Core\Imagine\VariationPathGenerator|\PHPUnit\Framework\MockObject\MockObject */ |
| 19 | + private VariationPathGenerator $innerVariationPathGenerator; |
| 20 | + |
| 21 | + /** @var \Ibexa\Bundle\Core\Imagine\Filter\FilterConfiguration|\PHPUnit\Framework\MockObject\MockObject */ |
| 22 | + private FilterConfiguration $filterConfiguration; |
| 23 | + |
| 24 | + protected function setUp(): void |
| 25 | + { |
| 26 | + $this->innerVariationPathGenerator = $this->createMock(VariationPathGenerator::class); |
| 27 | + $this->filterConfiguration = $this->createMock(FilterConfiguration::class); |
| 28 | + } |
| 29 | + |
| 30 | + public function testGetVariationPath(): void |
| 31 | + { |
| 32 | + $this->innerVariationPathGenerator |
| 33 | + ->method('getVariationPath') |
| 34 | + ->willReturn('tmp/variation/test.jpeg'); |
| 35 | + |
| 36 | + $this->filterConfiguration |
| 37 | + ->method('get') |
| 38 | + ->with('large') |
| 39 | + ->willReturn([ |
| 40 | + 'format' => 'webp', |
| 41 | + ]); |
| 42 | + |
| 43 | + $generator = new WebpFormatVariationPathGenerator( |
| 44 | + $this->innerVariationPathGenerator, |
| 45 | + $this->filterConfiguration |
| 46 | + ); |
| 47 | + |
| 48 | + self::assertEquals( |
| 49 | + 'tmp/variation/test.jpeg.webp', |
| 50 | + $generator->getVariationPath('tmp/original/test.jpeg', 'large') |
| 51 | + ); |
| 52 | + } |
| 53 | + |
| 54 | + public function testGetVariationNonWebpVariation(): void |
| 55 | + { |
| 56 | + $this->innerVariationPathGenerator |
| 57 | + ->method('getVariationPath') |
| 58 | + ->willReturn('tmp/variation/test.jpeg'); |
| 59 | + |
| 60 | + $this->filterConfiguration |
| 61 | + ->method('get') |
| 62 | + ->with('large') |
| 63 | + ->willReturn([ |
| 64 | + 'format' => 'jpeg', |
| 65 | + ]); |
| 66 | + |
| 67 | + $generator = new WebpFormatVariationPathGenerator( |
| 68 | + $this->innerVariationPathGenerator, |
| 69 | + $this->filterConfiguration |
| 70 | + ); |
| 71 | + |
| 72 | + self::assertEquals( |
| 73 | + 'tmp/variation/test.jpeg', |
| 74 | + $generator->getVariationPath('tmp/original/test.jpeg', 'large') |
| 75 | + ); |
| 76 | + } |
| 77 | +} |
0 commit comments