medialibrary-helper/tests/Feature/ReorderTest.php

41 lines
1.7 KiB
PHP
Raw Permalink Normal View History

2023-03-12 21:43:57 +01:00
<?php
namespace Zoomyboy\MedialibraryHelper\Tests\Feature;
test('it can reorder media', function () {
$this->auth()->registerModel();
$post = $this->newPost();
$post->addMedia($this->pdfFile()->getPathname())->preservingOriginal()->toMediaCollection('images');
$post->addMedia($this->pdfFile()->getPathname())->preservingOriginal()->toMediaCollection('images');
$post->addMedia($this->pdfFile()->getPathname())->preservingOriginal()->toMediaCollection('images');
$order = $post->getMedia('images')->pluck('id');
$order->prepend($order->pop());
$response = $this->patchJson("/mediaupload/post/{$post->id}/images", [
'order' => $order,
]);
$response->assertStatus(200);
$response->assertJsonPath('0.id', $order->get(0));
$response->assertJsonPath('1.id', $order->get(1));
$response->assertJsonPath('2.id', $order->get(2));
$this->assertEquals($order, $post->fresh()->getMedia('images')->pluck('id'));
});
test('images should belong to same model', function () {
$this->auth()->registerModel();
$post = $this->newPost();
$firstMedia = $post->addMedia($this->pdfFile()->getPathname())->preservingOriginal()->toMediaCollection('images');
$post = $this->newPost();
$secondMedia = $post->addMedia($this->pdfFile()->getPathname())->preservingOriginal()->toMediaCollection('images');
$thirdMedia = $post->addMedia($this->pdfFile()->getPathname())->preservingOriginal()->toMediaCollection('images');
$response = $this->patchJson("/mediaupload/post/{$post->id}/images", [
'order' => [$firstMedia->id, $secondMedia->id, $thirdMedia->id],
]);
$response->assertJsonValidationErrors('order');
});