|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +use AceOfAces\LaravelImageTransformUrl\Enums\AllowedMimeTypes; |
| 6 | +use AceOfAces\LaravelImageTransformUrl\Tests\TestCase; |
| 7 | + |
| 8 | +beforeEach(function () { |
| 9 | + Cache::flush(); |
| 10 | + Storage::fake(config()->string('image-transform-url.cache.disk')); |
| 11 | +}); |
| 12 | + |
| 13 | +it('can convert from jpeg to all other allowed mime types', function () { |
| 14 | + $allowedMimeTypes = collect(AllowedMimeTypes::withExtension())->filter( |
| 15 | + fn ($allowed) => $allowed['mime'] !== 'image/jpeg' |
| 16 | + ); |
| 17 | + |
| 18 | + foreach ($allowedMimeTypes as $allowed) { |
| 19 | + /** @var TestCase $this */ |
| 20 | + $response = $this->get(route('image.transform', [ |
| 21 | + 'options' => 'format=' . $allowed['extension'], |
| 22 | + 'path' => 'cat.jpg', |
| 23 | + ])); |
| 24 | + |
| 25 | + expect($response)->toBeImage([ |
| 26 | + 'mime' => $allowed['mime'], |
| 27 | + ]); |
| 28 | + } |
| 29 | +}); |
| 30 | + |
| 31 | +it('can convert from gif to all other allowed mime types', function () { |
| 32 | + $allowedMimeTypes = collect(AllowedMimeTypes::withExtension())->filter( |
| 33 | + fn ($allowed) => $allowed['mime'] !== 'image/gif' |
| 34 | + ); |
| 35 | + |
| 36 | + foreach ($allowedMimeTypes as $allowed) { |
| 37 | + /** @var TestCase $this */ |
| 38 | + $response = $this->get(route('image.transform', [ |
| 39 | + 'options' => 'format=' . $allowed['extension'], |
| 40 | + 'path' => 'cat-kiss.gif', |
| 41 | + ])); |
| 42 | + |
| 43 | + expect($response)->toBeImage([ |
| 44 | + 'mime' => $allowed['mime'], |
| 45 | + ]); |
| 46 | + } |
| 47 | +}); |
| 48 | + |
| 49 | +it('can convert from png to all other allowed mime types', function () { |
| 50 | + $allowedMimeTypes = collect(AllowedMimeTypes::withExtension())->filter( |
| 51 | + fn ($allowed) => $allowed['mime'] !== 'image/png' |
| 52 | + ); |
| 53 | + |
| 54 | + foreach ($allowedMimeTypes as $allowed) { |
| 55 | + /** @var TestCase $this */ |
| 56 | + $response = $this->get(route('image.transform', [ |
| 57 | + 'options' => 'format=' . $allowed['extension'], |
| 58 | + 'path' => 'cat.png', |
| 59 | + ])); |
| 60 | + |
| 61 | + expect($response)->toBeImage([ |
| 62 | + 'mime' => $allowed['mime'], |
| 63 | + ]); |
| 64 | + } |
| 65 | +}); |
| 66 | +it('can convert from webp to all other allowed mime types', function () { |
| 67 | + $allowedMimeTypes = collect(AllowedMimeTypes::withExtension())->filter( |
| 68 | + fn ($allowed) => $allowed['mime'] !== 'image/webp' |
| 69 | + ); |
| 70 | + |
| 71 | + foreach ($allowedMimeTypes as $allowed) { |
| 72 | + /** @var TestCase $this */ |
| 73 | + $response = $this->get(route('image.transform', [ |
| 74 | + 'options' => 'format=' . $allowed['extension'], |
| 75 | + 'path' => 'cat.webp', |
| 76 | + ])); |
| 77 | + |
| 78 | + expect($response)->toBeImage([ |
| 79 | + 'mime' => $allowed['mime'], |
| 80 | + ]); |
| 81 | + } |
| 82 | +}); |
0 commit comments