You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
47 lines
1.7 KiB
47 lines
1.7 KiB
<?php
|
|
|
|
namespace Tests\Feature;
|
|
|
|
use App\Image\ImageProcessor;
|
|
use App\Models\Collection;
|
|
use App\Models\File;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Illuminate\Foundation\Testing\WithFaker;
|
|
use Illuminate\Support\Facades\Storage;
|
|
use Tests\Bootstrap;
|
|
use Tests\TestCase;
|
|
|
|
class FileDeleteTest extends Bootstrap
|
|
{
|
|
// public function test_user_with_permission_can_not_delete_file()
|
|
// {
|
|
// $this->assertFalse("it's not mohammad's fault, I'm waiting for dynamic policy");
|
|
// }
|
|
|
|
public function test_user_with_permission_can_delete_file()
|
|
{
|
|
$file = $this->one(File::class, dependencyAttributes: ['withImage' => true]);
|
|
$collection = Collection::find($file->collection_id);
|
|
$response = $this->loginAs()->deleteJson(route('api.files.destroy', ['collection_name' => $collection->name, 'uuid' => $file->uuid, 'extention' => $collection->ext]));
|
|
$response->assertok();
|
|
}
|
|
|
|
public function test_file_restore_success()
|
|
{
|
|
$this->modelWithPolicy('collections', ['permission:collections.restore'])
|
|
->loginAsUser(['collections.restore'])
|
|
->deleteJson(route("api.collections.destroy", $collection = $this->trashed(Collection::class, dependencyAttributes: ['withImage' => true])))
|
|
->assertOk();
|
|
|
|
$this->loginAsAdmin()
|
|
->getJson(route("api.collections.show", $collection))
|
|
->assertOk();
|
|
}
|
|
|
|
public function test_file_delete_notFound()
|
|
{
|
|
$this->loginAsAdmin()
|
|
->deleteJson(route("api.files.destroy", ['collection_name' => 'not found', 'uuid' => 'wrong uuid', 'extention' => 'wrong ext']))
|
|
->assertNotFound();
|
|
}
|
|
}
|