-
-
Notifications
You must be signed in to change notification settings - Fork 546
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test coverage for XMLHttpRequest behaviour and ensure its run
- Loading branch information
1 parent
085847d
commit 4fe64f5
Showing
2 changed files
with
29 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -934,12 +934,8 @@ public function it_removes_any_uploaded_assets_when_a_listener_throws_a_validati | |
} | ||
|
||
#[Test] | ||
public function it_renders_exceptions_thrown_during_precognitive_requests_as_standard_laravel_errors() | ||
public function it_renders_exceptions_thrown_during_json_requests_as_standard_laravel_errors() | ||
{ | ||
if (! method_exists($this, 'withPrecognition')) { | ||
$this->markTestSkipped(); | ||
} | ||
|
||
Event::listen(function (\Statamic\Events\FormSubmitted $event) { | ||
throw ValidationException::withMessages(['some' => 'error']); | ||
}); | ||
|
@@ -957,4 +953,28 @@ public function it_renders_exceptions_thrown_during_precognitive_requests_as_sta | |
$this->assertArrayHasKey('errors', $json); | ||
$this->assertSame($json['errors'], ['some' => ['error']]); | ||
} | ||
|
||
#[Test] | ||
public function it_renders_exceptions_thrown_during_xml_http_requests_in_statamic_error_format() | ||
{ | ||
Event::listen(function (\Statamic\Events\FormSubmitted $event) { | ||
throw ValidationException::withMessages(['some' => 'error']); | ||
}); | ||
|
||
$response = $this | ||
->withHeaders([ | ||
'X-Requested-With' => 'XMLHttpRequest', | ||
]) | ||
->postJson('/!/forms/contact', [ | ||
'name' => 'Name', | ||
'email' => '[email protected]', | ||
'message' => 'This is a message', | ||
]); | ||
|
||
$json = $response->json(); | ||
|
||
$this->assertArrayHasKey('error', $json); | ||
$this->assertArrayHasKey('errors', $json); | ||
$this->assertSame($json['error'], ['some' => 'error']); | ||
} | ||
} |