ensure media is ordered

This commit is contained in:
Philipp Lang 2023-03-10 14:52:17 +01:00
parent 61ed6e0a3d
commit f269864194
1 changed files with 19 additions and 0 deletions

View File

@ -3,6 +3,7 @@
namespace Zoomyboy\MedialibraryHelper\Tests\Feature; namespace Zoomyboy\MedialibraryHelper\Tests\Feature;
use Illuminate\Support\Facades\Storage; use Illuminate\Support\Facades\Storage;
use Spatie\MediaLibrary\MediaCollections\Models\Media;
test('it gets all medias', function () { test('it gets all medias', function () {
$this->auth()->registerModel(); $this->auth()->registerModel();
@ -19,6 +20,24 @@ test('it gets all medias', function () {
$response->assertJsonPath('1.icon', url('storage/filetypes/applicationpdf.svg')); $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 () { test('it gets media for single', function () {
$this->auth()->registerModel(); $this->auth()->registerModel();
$post = $this->newPost(); $post = $this->newPost();