From f269864194287846b5b53306e9b32b2cb2224acd Mon Sep 17 00:00:00 2001 From: Philipp Lang Date: Fri, 10 Mar 2023 14:52:17 +0100 Subject: [PATCH] ensure media is ordered --- tests/Feature/IndexTest.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/tests/Feature/IndexTest.php b/tests/Feature/IndexTest.php index 5f51989..90e0888 100644 --- a/tests/Feature/IndexTest.php +++ b/tests/Feature/IndexTest.php @@ -3,6 +3,7 @@ namespace Zoomyboy\MedialibraryHelper\Tests\Feature; use Illuminate\Support\Facades\Storage; +use Spatie\MediaLibrary\MediaCollections\Models\Media; test('it gets all medias', function () { $this->auth()->registerModel(); @@ -19,6 +20,24 @@ test('it gets all medias', function () { $response->assertJsonPath('1.icon', url('storage/filetypes/applicationpdf.svg')); }); +test('it gets media in order', function () { + $this->auth()->registerModel(); + $post = $this->newPost(); + $firstMedia = $post->addMedia($this->pdfFile()->getPathname())->withCustomProperties(['test' => 'old'])->preservingOriginal()->toMediaCollection('images'); + $secondMedia = $post->addMedia($this->pdfFile()->getPathname())->withCustomProperties(['test' => 'old'])->preservingOriginal()->toMediaCollection('images'); + $thirdMedia = $post->addMedia($this->pdfFile()->getPathname())->withCustomProperties(['test' => 'old'])->preservingOriginal()->toMediaCollection('images'); + $order = $post->getMedia('images')->pluck('id'); + $order->prepend($order->pop()); + Media::setNewOrder($order->toArray()); + + $response = $this->getJson("/mediaupload/post/{$post->id}/images"); + + $response->assertStatus(200); + $response->assertJsonPath('0.id', $thirdMedia->id); + $response->assertJsonPath('1.id', $firstMedia->id); + $response->assertJsonPath('2.id', $secondMedia->id); +}); + test('it gets media for single', function () { $this->auth()->registerModel(); $post = $this->newPost();