|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Zenstruck\Browser\Tests\Extension; |
|
4
|
|
|
|
|
5
|
|
|
use Zenstruck\Browser\Extension\Http\HttpOptions; |
|
6
|
|
|
use Zenstruck\Browser\Tests\Fixture\CustomHttpOptions; |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* @author Kevin Bond <[email protected]> |
|
10
|
|
|
*/ |
|
11
|
|
|
trait HttpTests |
|
12
|
|
|
{ |
|
13
|
|
|
/** |
|
14
|
|
|
* @test |
|
15
|
|
|
*/ |
|
16
|
|
|
public function exceptions_are_caught_by_default(): void |
|
17
|
|
|
{ |
|
18
|
|
|
$this->browser() |
|
|
|
|
|
|
19
|
|
|
->visit('/exception') |
|
20
|
|
|
->assertStatus(500) |
|
21
|
|
|
; |
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* @test |
|
26
|
|
|
*/ |
|
27
|
|
|
public function response_header_assertions(): void |
|
28
|
|
|
{ |
|
29
|
|
|
$this->browser() |
|
30
|
|
|
->visit('/page1') |
|
31
|
|
|
->assertHeaderEquals('Content-Type', 'text/html; charset=UTF-8') |
|
32
|
|
|
->assertHeaderContains('Content-Type', 'text/html') |
|
33
|
|
|
; |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* @test |
|
38
|
|
|
*/ |
|
39
|
|
|
public function http_method_actions(): void |
|
40
|
|
|
{ |
|
41
|
|
|
$this->browser() |
|
42
|
|
|
->get('/http-method') |
|
43
|
|
|
->assertSuccessful() |
|
44
|
|
|
->assertContains('"method":"GET"') |
|
45
|
|
|
->post('/http-method') |
|
46
|
|
|
->assertSuccessful() |
|
47
|
|
|
->assertContains('"method":"POST"') |
|
48
|
|
|
->delete('/http-method') |
|
49
|
|
|
->assertSuccessful() |
|
50
|
|
|
->assertContains('"method":"DELETE"') |
|
51
|
|
|
->put('/http-method') |
|
52
|
|
|
->assertSuccessful() |
|
53
|
|
|
->assertContains('"method":"PUT"') |
|
54
|
|
|
->assertContains('"ajax":false') |
|
55
|
|
|
->post('/http-method', [ |
|
56
|
|
|
'json' => ['foo' => 'bar'], |
|
57
|
|
|
'headers' => ['X-Foo' => 'Bar'], |
|
58
|
|
|
'ajax' => true, |
|
59
|
|
|
]) |
|
60
|
|
|
->assertContains('"content-type":["application\/json"]') |
|
61
|
|
|
->assertContains('"x-foo":["Bar"]') |
|
62
|
|
|
->assertContains('"content":"{\u0022foo\u0022:\u0022bar\u0022}"') |
|
63
|
|
|
->assertContains('"ajax":true') |
|
64
|
|
|
->post('/http-method', HttpOptions::jsonAjax(['foo' => 'bar'])->withHeader('X-Foo', 'Bar')) |
|
65
|
|
|
->assertContains('"content-type":["application\/json"]') |
|
66
|
|
|
->assertContains('"x-foo":["Bar"]') |
|
67
|
|
|
->assertContains('"content":"{\u0022foo\u0022:\u0022bar\u0022}"') |
|
68
|
|
|
->assertContains('"ajax":true') |
|
69
|
|
|
->post('/http-method', CustomHttpOptions::api('my-token')) |
|
70
|
|
|
->assertContains('"content-type":["application\/json"]') |
|
71
|
|
|
->assertContains('"x-token":["my-token"]') |
|
72
|
|
|
; |
|
73
|
|
|
} |
|
74
|
|
|
} |
|
75
|
|
|
|