36 lines
1.5 KiB
PHP
36 lines
1.5 KiB
PHP
|
<?php
|
||
|
|
||
|
namespace Zoomyboy\MedialibraryHelper\Tests\Feature;
|
||
|
|
||
|
test('it deletes multiple media', function () {
|
||
|
$this->auth()->registerModel();
|
||
|
$post = $this->newPost();
|
||
|
$post->addMedia($this->pdfFile()->getPathname())->withCustomProperties(['test' => 'old'])->preservingOriginal()->toMediaCollection('multipleForced');
|
||
|
$post->addMedia($this->pdfFile()->getPathname())->withCustomProperties(['test' => 'old'])->preservingOriginal()->toMediaCollection('multipleForced');
|
||
|
$media = $post->getFirstMedia('multipleForced');
|
||
|
|
||
|
$this->deleteJson("/mediaupload/{$media->id}")->assertStatus(200);
|
||
|
|
||
|
$this->assertCount(1, $post->fresh()->getMedia('multipleForced'));
|
||
|
});
|
||
|
|
||
|
test('it deletes single media', function () {
|
||
|
$this->auth()->registerModel();
|
||
|
$post = $this->newPost();
|
||
|
$post->addMedia($this->pdfFile()->getPathname())->withCustomProperties(['test' => 'old'])->preservingOriginal()->toMediaCollection('defaultSingleFile');
|
||
|
$media = $post->getFirstMedia('defaultSingleFile');
|
||
|
|
||
|
$this->deleteJson("/mediaupload/{$media->id}")->assertStatus(200);
|
||
|
|
||
|
$this->assertCount(0, $post->fresh()->getMedia('defaultSingleFile'));
|
||
|
});
|
||
|
|
||
|
test('it needs authorization', function () {
|
||
|
$this->auth(['destroyMedia' => false])->registerModel();
|
||
|
$post = $this->newPost();
|
||
|
$post->addMedia($this->pdfFile()->getPathname())->withCustomProperties(['test' => 'old'])->preservingOriginal()->toMediaCollection('defaultSingleFile');
|
||
|
$media = $post->getFirstMedia('defaultSingleFile');
|
||
|
|
||
|
$this->deleteJson("/mediaupload/{$media->id}")->assertStatus(403);
|
||
|
});
|