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.

67 lines
2.0 KiB

  1. <?php
  2. namespace Tests\Feature\Collection;
  3. use App\Models\Collection;
  4. use Tests\Bootstrap;
  5. use App\Models\User;
  6. use Illuminate\Support\Arr;
  7. class CollectionUpdateTest extends Bootstrap
  8. {
  9. public function test_collection_update_success()
  10. {
  11. $this->modelWithPolicy('collections', ['permission:collections.update'])
  12. ->loginAs(['collections.update'])
  13. ->putJson(
  14. route("api.collections.update", $collection = $this->one(Collection::class)),
  15. $update = $this->make(Collection::class, withDependency: true)
  16. )
  17. ->assertOk();
  18. }
  19. /**
  20. * @testWith
  21. * ["name:gtString"]
  22. * ["name:numeric"]
  23. * ["name:null"]
  24. * ["path:gtString"]
  25. * ["path:numeric"]
  26. * ["public:string"]
  27. * ["disk:numeric"]
  28. * ["disk:null"]
  29. * ["disk:gtString"]
  30. * ["count:null"]
  31. * ["count:string"]
  32. * ["count:gt:100000"]
  33. *
  34. */
  35. public function test_collection_update_unprocessable($field)
  36. {
  37. $this->modelWithPolicy('collections', ['permission:collections.update'])
  38. ->loginAs(['collections.update'])->putJson(
  39. route("api.collections.update", $collection = $this->one(Collection::class)),
  40. $update = $this->make(collection::class, smash: $field, withDependency: true)
  41. )
  42. ->assertUnprocessable();
  43. }
  44. public function test_collection_update_forbidden()
  45. {
  46. $this->modelWithPolicy('collections', ['permission:collections.update'])
  47. ->loginAs(['wrong.permission'])
  48. ->putJson(
  49. route("api.collections.update", $collection = $this->one(Collection::class)),
  50. []
  51. )
  52. ->assertForbidden();
  53. }
  54. public function test_collection_update_not_found()
  55. {
  56. $this->loginAsUser(['collections.update'])
  57. ->putJson(route("api.collections.update", 0), [])
  58. ->assertNotFound();
  59. }
  60. }