|
4 | 4 |
|
5 | 5 | use Exception; |
6 | 6 | use Illuminate\Auth\Access\AuthorizationException; |
| 7 | +use Illuminate\Auth\Access\Response; |
7 | 8 | use Illuminate\Container\Container; |
8 | 9 | use Illuminate\Contracts\Translation\Translator; |
9 | 10 | use Illuminate\Contracts\Validation\Factory as ValidationFactoryContract; |
@@ -101,6 +102,19 @@ public function testValidateMethodThrowsWhenAuthorizationFails() |
101 | 102 | $this->createRequest([], FoundationTestFormRequestForbiddenStub::class)->validateResolved(); |
102 | 103 | } |
103 | 104 |
|
| 105 | + public function testValidateThrowsExceptionFromAuthorizationResponse() |
| 106 | + { |
| 107 | + $this->expectException(AuthorizationException::class); |
| 108 | + $this->expectExceptionMessage('foo'); |
| 109 | + |
| 110 | + $this->createRequest([], FoundationTestFormRequestForbiddenWithResponseStub::class)->validateResolved(); |
| 111 | + } |
| 112 | + |
| 113 | + public function testValidateDoesntThrowExceptionFromResponseAllowed() |
| 114 | + { |
| 115 | + $this->createRequest([], FoundationTestFormRequestPassesWithResponseStub::class)->validateResolved(); |
| 116 | + } |
| 117 | + |
104 | 118 | public function testPrepareForValidationRunsBeforeValidation() |
105 | 119 | { |
106 | 120 | $this->createRequest([], FoundationTestFormRequestHooks::class)->validateResolved(); |
@@ -322,3 +336,24 @@ public function passedValidation() |
322 | 336 | $this->replace(['name' => 'Adam']); |
323 | 337 | } |
324 | 338 | } |
| 339 | + |
| 340 | +class FoundationTestFormRequestForbiddenWithResponseStub extends FormRequest |
| 341 | +{ |
| 342 | + public function authorize() |
| 343 | + { |
| 344 | + return Response::deny('foo'); |
| 345 | + } |
| 346 | +} |
| 347 | + |
| 348 | +class FoundationTestFormRequestPassesWithResponseStub extends FormRequest |
| 349 | +{ |
| 350 | + public function rules() |
| 351 | + { |
| 352 | + return []; |
| 353 | + } |
| 354 | + |
| 355 | + public function authorize() |
| 356 | + { |
| 357 | + return Response::allow('baz'); |
| 358 | + } |
| 359 | +} |
0 commit comments