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
2.4 KiB

2 years ago
  1. {!! $sol !!}
  2. namespace Tests\Feature\{{class_basename($model)}};
  3. use App\Models\{{class_basename($model)}};
  4. use Tests\Bootstrap;
  5. class {{class_basename($model)}}DeleteTest extends Bootstrap
  6. {
  7. public function test_{{lcfirst(class_basename($model))}}_delete_success()
  8. {
  9. $this->modelWithPolicy('{{$model->getTable()}}', ['permission:{{$model->getTable()}}.delete'])
  10. ->loginAs(['{{$model->getTable()}}.delete'])
  11. ->deleteJson(route("api.{{$model->getTable()}}.delete", ${{lcfirst(class_basename($model))}} = $this->one({{class_basename($model)}}::class)))
  12. ->assertOk();
  13. $this->loginAsAdmin()
  14. ->getJson(route("api.{{$model->getTable()}}.show", ${{lcfirst(class_basename($model))}}))
  15. ->assertNotFound();
  16. }
  17. public function test_{{lcfirst(class_basename($model))}}_restore_success()
  18. {
  19. $this->modelWithPolicy('{{$model->getTable()}}', ['permission:{{$model->getTable()}}.restore'])
  20. ->loginAsUser(['{{$model->getTable()}}.restore'])
  21. ->deleteJson(route("api.{{$model->getTable()}}.delete", ${{lcfirst(class_basename($model))}} = $this->trashed({{class_basename($model)}}::class)))
  22. ->assertOk();
  23. $this->loginAsAdmin()
  24. ->getJson(route("api.{{$model->getTable()}}.show", ${{lcfirst(class_basename($model))}}))
  25. ->assertOk();
  26. }
  27. public function test_{{lcfirst(class_basename($model))}}_delete_forbidden()
  28. {
  29. $this->modelWithPolicy('{{$model->getTable()}}', ['permission:{{$model->getTable()}}.delete'])
  30. ->loginAs(['wrong.permission'])
  31. ->deleteJson(route("api.{{$model->getTable()}}.delete", ${{lcfirst(class_basename($model))}} = $this->one({{class_basename($model)}}::class)))
  32. ->assertForbidden();
  33. }
  34. public function test_{{lcfirst(class_basename($model))}}_restore_forbidden()
  35. {
  36. $this->modelWithPolicy('{{$model->getTable()}}', ['permission:{{$model->getTable()}}.restore'])
  37. ->loginAs(['wrong.permission'])
  38. ->deleteJson(route("api.{{$model->getTable()}}.delete", ${{lcfirst(class_basename($model))}} = $this->trashed({{class_basename($model)}}::class)))
  39. ->assertForbidden();
  40. }
  41. public function test_{{lcfirst(class_basename($model))}}_delete_notFound()
  42. {
  43. $this->loginAsAdmin()
  44. ->deleteJson(route("api.{{$model->getTable()}}.delete", 0))
  45. ->assertNotFound();
  46. }
  47. }