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.

56 lines
1.9 KiB

  1. <?php
  2. namespace Tests\Feature\Collection;
  3. use App\Models\Collection;
  4. use Tests\Bootstrap;
  5. class CollectionDeleteTest extends Bootstrap
  6. {
  7. public function test_collection_delete_success()
  8. {
  9. $this->modelWithPolicy('collections', ['permission:collections.delete'])
  10. ->loginAs(['collections.delete'])
  11. ->deleteJson(route("api.collections.destroy", $collection = $this->one(Collection::class)))
  12. ->assertOk();
  13. $this->loginAsAdmin()
  14. ->getJson(route("api.collections.show", $collection))
  15. ->assertNotFound();
  16. }
  17. public function test_collection_restore_success()
  18. {
  19. $this->modelWithPolicy('collections', ['permission:collections.restore'])
  20. ->loginAsUser(['collections.restore'])
  21. ->deleteJson(route("api.collections.destroy", $collection = $this->trashed(Collection::class)))
  22. ->assertOk();
  23. $this->loginAsAdmin()
  24. ->getJson(route("api.collections.show", $collection))
  25. ->assertOk();
  26. }
  27. public function test_collection_delete_forbidden()
  28. {
  29. $this->modelWithPolicy('collections', ['permission:collections.delete'])
  30. ->loginAs(['wrong.permission'])
  31. ->deleteJson(route("api.collections.destroy", $collection = $this->one(Collection::class)))
  32. ->assertForbidden();
  33. }
  34. public function test_collection_restore_forbidden()
  35. {
  36. $this->modelWithPolicy('collections', ['permission:collections.restore'])
  37. ->loginAs(['wrong.permission'])
  38. ->deleteJson(route("api.collections.destroy", $collection = $this->trashed(Collection::class)))
  39. ->assertForbidden();
  40. }
  41. public function test_collection_delete_notFound()
  42. {
  43. $this->loginAsAdmin()
  44. ->deleteJson(route("api.collections.destroy", 0))
  45. ->assertNotFound();
  46. }
  47. }