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.

28 lines
840 B

2 years ago
  1. <?php
  2. namespace Tests\iLaravel\Policies;
  3. use App\Models\ILaravel;
  4. use Tests\Bootstrap;
  5. class CustomMethodPolicyTest extends Bootstrap
  6. {
  7. function test_custom_method_policy_successful()
  8. {
  9. $this->modelWithPolicy('ilaravels', ['model:policyCheckCustom'])
  10. ->getJson(route('api.ilaravels.show', $this->one(ILaravel::class)))
  11. ->assertOk();
  12. }
  13. public function test_custom_method_policy_fail()
  14. {
  15. $mokModel = $this->mockModel(ILaravel::class);
  16. $mokModel->shouldReceive('resolveRouteBinding')->andReturnSelf();
  17. $mokModel->shouldReceive('policyCheckCustom')->andReturnFalse();
  18. $this->modelWithPolicy('ilaravels', ['model:policyCheckCustom'])
  19. ->getJson(route('api.ilaravels.show', $this->one(ILaravel::class)))
  20. ->assertForbidden();
  21. }
  22. }