From 7174f6e89b142956fcc9149fd0687452e8715e5e Mon Sep 17 00:00:00 2001 From: Tim Van Dijck Date: Fri, 15 Nov 2024 16:41:43 +0100 Subject: [PATCH] Revert "Correctly filtering conversions which will be applied to media in different collections of the same subject." This reverts commit bb26bf6ebcc124e323ff6524fb42d776b23fcbfa. --- src/Conversions/ConversionCollection.php | 10 +- .../ConversionCollectionConversionsTest.php | 99 ------------------- 2 files changed, 3 insertions(+), 106 deletions(-) delete mode 100644 tests/Conversions/ConversionCollectionConversionsTest.php diff --git a/src/Conversions/ConversionCollection.php b/src/Conversions/ConversionCollection.php index de499a758..2b57a110c 100644 --- a/src/Conversions/ConversionCollection.php +++ b/src/Conversions/ConversionCollection.php @@ -38,9 +38,7 @@ public function setMedia(Media $media): self public function getByName(string $name): Conversion { - $conversion = $this - ->getConversions($this->media->collection_name) - ->first(fn (Conversion $conversion) => $conversion->getName() === $name); + $conversion = $this->first(fn (Conversion $conversion) => $conversion->getName() === $name); if (! $conversion) { throw InvalidConversion::unknownName($name); @@ -91,9 +89,7 @@ public function getConversions(string $collectionName = ''): self return $this; } - return $this - ->filter(fn (Conversion $conversion) => $conversion->shouldBePerformedOn($collectionName)) - ->values(); + return $this->filter(fn (Conversion $conversion) => $conversion->shouldBePerformedOn($collectionName)); } protected function addManipulationToConversion(Manipulations $manipulations, string $conversionName): void @@ -117,7 +113,7 @@ protected function addManipulationToConversion(Manipulations $manipulations, str if ($conversionName === '*') { $this->each( - fn (Conversion $conversion) => $conversion->addAsFirstManipulations(clone $manipulations), + fn (Conversion $conversion) => $conversion->addAsFirstManipulations(clone $manipulations) ); } } diff --git a/tests/Conversions/ConversionCollectionConversionsTest.php b/tests/Conversions/ConversionCollectionConversionsTest.php deleted file mode 100644 index 37ac67e5a..000000000 --- a/tests/Conversions/ConversionCollectionConversionsTest.php +++ /dev/null @@ -1,99 +0,0 @@ -model = (new class extends TestModel - { - public function registerMediaConversions(?Media $media = null): void - { - $this - ->addMediaConversion('preview') - ->fit(Fit::Crop, 50, 50) - ->performOnCollections('avatar') - ->format('png') - ->nonQueued(); - - $this - ->addMediaConversion('preview') - ->fit(Fit::Crop, 300, 100) - ->performOnCollections('signature') - ->format('jpeg') - ->nonQueued(); - - $this - ->addMediaConversion('web') - ->format('webp') - ->nonQueued(); - } - - public function registerMediaCollections(): void - { - $this->addMediaCollection('avatar')->acceptsMimeTypes(['image/png'])->singleFile(); - $this->addMediaCollection('signature')->acceptsMimeTypes(['image/jpeg'])->singleFile(); - } - })::create(['name' => 'testmodel']); - - $avatarMedia = $this->model - ->addMedia($this->getTestPng()) - ->preservingOriginal() - ->toMediaCollection('avatar'); - $avatarMedia->save(); - - $signatureMedia = $this->model - ->addMedia($this->getTestJpg()) - ->preservingOriginal() - ->toMediaCollection('signature'); - $signatureMedia->save(); - - $this->avatarMedia = $avatarMedia->refresh(); - $this->signatureMedia = $signatureMedia->refresh(); -}); - -it('will apply correct conversions for media in different collections', function () { - $conversionCollection = ConversionCollection::createForMedia($this->avatarMedia); - /** @var ConversionCollection $conversions */ - $conversions = $conversionCollection->getConversions('avatar'); - - expect($conversions->count())->toBe(2) - ->and($conversions->first()->getName())->toBe('preview') - ->and($conversions->first()->getResultExtension())->toBe('png') - ->and($conversions->first()->getManipulations()->toArray())->toMatchArray([ - 'fit' => [Fit::Crop, 50, 50], - 'format' => ['png'], - ]) - ->and($conversions->last()->getName())->toBe('web') - ->and($conversions->last()->getResultExtension())->toBe('webp') - ->and($conversions->last()->getManipulations()->toArray())->toMatchArray([ - 'format' => ['webp'], - ]); - - $conversionCollection = ConversionCollection::createForMedia($this->signatureMedia); - /** @var ConversionCollection $conversions */ - $conversions = $conversionCollection->getConversions('signature'); - - expect($conversions->count())->toBe(2) - ->and($conversions->first()->getName())->toBe('preview') - ->and($conversions->first()->getResultExtension())->toBe('jpeg') - ->and($conversions->first()->getManipulations()->toArray())->toMatchArray([ - 'fit' => [Fit::Crop, 300, 100], - 'format' => ['jpeg'], - ]) - ->and($conversions->last()->getName())->toBe('web') - ->and($conversions->last()->getResultExtension())->toBe('webp') - ->and($conversions->last()->getManipulations()->toArray())->toMatchArray([ - 'format' => ['webp'], - ]); -}); - -it('will generate correct filenames for media in different collections but with identically named conversions', function () { - expect($this->model->getFirstMediaUrl('avatar', 'preview'))->toEndWith('.png'); - expect($this->model->getFirstMediaUrl('avatar', 'web'))->toEndWith('.webp'); - - expect($this->model->getFirstMediaUrl('signature', 'preview'))->toEndWith('.jpeg'); - expect($this->model->getFirstMediaUrl('signature', 'web'))->toEndWith('.webp'); -});