Fixed order event
This commit is contained in:
parent
fb15678d4e
commit
8a4dc77cfa
|
@ -29,6 +29,8 @@ class OrderController
|
|||
|
||||
Media::setNewOrder($request->order);
|
||||
|
||||
$model->getMediaCollection($collectionName)->runCallback('after', $model->fresh());
|
||||
|
||||
return MediaData::collection($model->getMedia($collectionName));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,11 @@
|
|||
|
||||
namespace Zoomyboy\MedialibraryHelper\Tests\Feature;
|
||||
|
||||
use Illuminate\Support\Facades\Event;
|
||||
use Zoomyboy\MedialibraryHelper\Tests\Events\MediaChange;
|
||||
|
||||
test('it can reorder media', function () {
|
||||
Event::fake();
|
||||
$this->auth()->registerModel();
|
||||
$post = $this->newPost();
|
||||
$post->addMedia($this->pdfFile()->getPathname())->preservingOriginal()->toMediaCollection('images');
|
||||
|
@ -20,6 +24,7 @@ test('it can reorder media', function () {
|
|||
$response->assertJsonPath('1.id', $order->get(1));
|
||||
$response->assertJsonPath('2.id', $order->get(2));
|
||||
$this->assertEquals($order, $post->fresh()->getMedia('images')->pluck('id'));
|
||||
Event::assertDispatched(MediaChange::class, fn ($event) => $event->model->is($post));
|
||||
});
|
||||
|
||||
test('images should belong to same model', function () {
|
||||
|
|
|
@ -29,7 +29,7 @@ class Post extends Model implements HasMedia
|
|||
$this->addMediaConversion('tiny')->width(200)->height(200);
|
||||
});
|
||||
|
||||
$this->addMediaCollection('images');
|
||||
$this->addMediaCollection('images')->after(fn ($model) => Event::dispatch(new MediaChange($model)));
|
||||
|
||||
$this->addMediaCollection('singleForced')->singleFile()->forceFileName(function ($model, $name) {
|
||||
return $name.' '.now()->format('Y-m-d');
|
||||
|
|
Loading…
Reference in New Issue