From bf1252068ed98da48b68dd3b020f2fe18339b6dc Mon Sep 17 00:00:00 2001 From: Victor Priceputu Date: Tue, 6 Sep 2022 10:12:14 +0100 Subject: [PATCH] #3015 - Add test for single file collections not working properly when copying media from another model. --- .../MediaConversions/MediaCollectionTest.php | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/tests/Feature/FileAdder/MediaConversions/MediaCollectionTest.php b/tests/Feature/FileAdder/MediaConversions/MediaCollectionTest.php index ba4225096..a84f24dde 100644 --- a/tests/Feature/FileAdder/MediaConversions/MediaCollectionTest.php +++ b/tests/Feature/FileAdder/MediaConversions/MediaCollectionTest.php @@ -225,6 +225,30 @@ public function registerMediaCollections(): void expect($model->getMedia('images'))->toHaveCount(1); }); +test('can copy the media to already populated single file collection', function () { + $testModel = new class () extends TestModelWithConversion { + public function registerMediaCollections(): void + { + $this + ->addMediaCollection('images') + ->singleFile(); + } + }; + + $model = $testModel::create(['name' => 'testmodel']); + + $model->addMedia($this->getTestJpg())->preservingOriginal()->toMediaCollection('images'); + $model->addMedia($this->getTestJpg())->preservingOriginal()->toMediaCollection('images'); + + expect($model->getMedia('images'))->toHaveCount(1); + + $media = $this->testModel->addMedia($this->getTestMp4())->preservingOriginal()->toMediaCollection(); + $media->copy($testModel, 'single_collection'); + + expect($model->getMedia('images'))->toHaveCount(1); + expect($model->getFirstMedia('images')->file_name)->toEqual($media->file_name); +}); + test('if the only keeps latest method is specified it will delete all other media and will only keep the latest n ones', function () { $testModel = new class () extends TestModelWithConversion { public function registerMediaCollections(): void