medialibrary-helper/tests/Feature/DestroyTest.php

36 lines
1.5 KiB
PHP
Raw Permalink Normal View History

2023-03-08 00:04:00 +01:00
<?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);
});