Skip to content

Commit

Permalink
Fix manipulations not applying to non default collections
Browse files Browse the repository at this point in the history
  • Loading branch information
MrMeshok committed Apr 24, 2024
1 parent 4557739 commit 89c0f95
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Conversions/ConversionCollection.php
Expand Up @@ -96,7 +96,7 @@ protected function addManipulationToConversion(Manipulations $manipulations, str
{
/** @var Conversion|null $conversion */
$conversion = $this->first(function (Conversion $conversion) use ($conversionName) {
if (! in_array($this->media->collection_name, $conversion->getPerformOnCollections())) {
if (! $conversion->shouldBePerformedOn($this->media->collection_name)) {
return false;
}

Expand Down
32 changes: 32 additions & 0 deletions tests/Conversions/ConversionCollectionTest.php
Expand Up @@ -19,8 +19,17 @@
$secondMedia->manipulations = ['thumb' => ['greyscale' => [], 'height' => [20]]];
$secondMedia->save();

$avatarMedia = $this->testModelWithConversion
->addMedia($this->getTestJpg())
->preservingOriginal()
->toMediaCollection('avatar');

$avatarMedia->manipulations = ['thumb' => ['greyscale' => [], 'height' => [10]]];
$avatarMedia->save();

$this->media = $media->fresh();
$this->secondMedia = $media->fresh();
$this->avatarMedia = $avatarMedia->fresh();
});

it('will prepend the manipulation saved on the model and the wildmark manipulations', function () {
Expand Down Expand Up @@ -75,6 +84,29 @@
], $manipulations);
});

it('will prepend the manipulation saved on the model with non default collection', function () {
$conversionCollection = ConversionCollection::createForMedia($this->avatarMedia);

$conversion = $conversionCollection->getConversions()[0];

expect($conversion->getName())->toEqual('thumb');

$manipulations = $conversion
->getManipulations()
->toArray();

$this->assertArrayHasKey('optimize', $manipulations);

unset($manipulations['optimize']);

$this->assertEquals([
'greyscale' => [],
'height' => [10],
'format' => ['jpg'],
'width' => [50],
], $manipulations);
});

it('will apply the manipulation on the equally named conversion of every model', function () {
$mediaItems = [$this->media, $this->secondMedia];
$manipulations = [];
Expand Down

0 comments on commit 89c0f95

Please sign in to comment.