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

  1. <?php
  2. namespace Tests\Feature;
  3. use App\Image\ImageProcessor;
  4. use App\Models\Collection;
  5. use App\Models\File;
  6. use Illuminate\Foundation\Testing\RefreshDatabase;
  7. use Illuminate\Foundation\Testing\WithFaker;
  8. use Illuminate\Support\Facades\Storage;
  9. use Tests\Bootstrap;
  10. use Tests\TestCase;
  11. class FileDeleteTest extends Bootstrap
  12. {
  13. // public function test_user_with_permission_can_not_delete_file()
  14. // {
  15. // $this->assertFalse("it's not mohammad's fault, I'm waiting for dynamic policy");
  16. // }
  17. public function test_user_with_permission_can_delete_file()
  18. {
  19. $file = $this->one(File::class, dependencyAttributes: ['withImage' => true]);
  20. $collection = Collection::find($file->collection_id);
  21. $response = $this->loginAs()->deleteJson(route('api.files.destroy', ['collection_name' => $collection->name, 'uuid' => $file->uuid, 'extention' => $collection->ext]));
  22. $response->assertok();
  23. }
  24. public function test_file_restore_success()
  25. {
  26. $this->modelWithPolicy('collections', ['permission:collections.restore'])
  27. ->loginAsUser(['collections.restore'])
  28. ->deleteJson(route("api.collections.destroy", $collection = $this->trashed(Collection::class, dependencyAttributes: ['withImage' => true])))
  29. ->assertOk();
  30. $this->loginAsAdmin()
  31. ->getJson(route("api.collections.show", $collection))
  32. ->assertOk();
  33. }
  34. public function test_file_delete_notFound()
  35. {
  36. $this->loginAsAdmin()
  37. ->deleteJson(route("api.files.destroy", ['collection_name' => 'not found', 'uuid' => 'wrong uuid', 'extention' => 'wrong ext']))
  38. ->assertNotFound();
  39. }
  40. }