-
-
Notifications
You must be signed in to change notification settings - Fork 109
Expand file tree
/
Copy pathAssertUrlTest.php
More file actions
260 lines (163 loc) · 8.25 KB
/
AssertUrlTest.php
File metadata and controls
260 lines (163 loc) · 8.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
<?php
declare(strict_types=1);
use PHPUnit\Framework\ExpectationFailedException;
it('may assert current URL matches expected URL', function (): void {
Route::get('/test-url', fn (): string => 'Test URL Page');
$page = visit('/test-url');
$page->assertUrlIs(url('/test-url'));
});
it('may assert current URL path using path-only notation', function (): void {
Route::get('/login', fn (): string => 'Login Page');
$page = visit('/login');
$page->assertUrlIs('/login');
});
it('may fail when asserting URL path using path-only notation but it does not match', function (): void {
Route::get('/login', fn (): string => 'Login Page');
$page = visit('/login');
$page->assertUrlIs('/wrong-path');
})->throws(ExpectationFailedException::class);
it('may fail when asserting URL matches but it does not', function (): void {
Route::get('/test-url', fn (): string => 'Test URL Page');
$page = visit('/test-url');
$page->assertUrlIs(url('/wrong-url'));
})->throws(ExpectationFailedException::class);
it('may assert URL scheme matches expected scheme', function (): void {
Route::get('/test-url', fn (): string => 'Test URL Page');
$page = visit('/test-url');
$page->assertSchemeIs('http');
});
it('may fail when asserting URL scheme matches but it does not', function (): void {
Route::get('/test-url', fn (): string => 'Test URL Page');
$page = visit('/test-url');
$page->assertSchemeIs('https');
})->throws(ExpectationFailedException::class);
it('may assert URL scheme does not match expected scheme', function (): void {
Route::get('/test-url', fn (): string => 'Test URL Page');
$page = visit('/test-url');
$page->assertSchemeIsNot('https');
});
it('may fail when asserting URL scheme does not match but it does', function (): void {
Route::get('/test-url', fn (): string => 'Test URL Page');
$page = visit('/test-url');
$page->assertSchemeIsNot('http');
})->throws(ExpectationFailedException::class);
it('may assert URL host matches expected host', function (): void {
Route::get('/test-url', fn (): string => 'Test URL Page');
$page = visit('/test-url');
// Extract the host from the current URL
$host = parse_url(url('/test-url'), PHP_URL_HOST);
$page->assertHostIs($host);
});
it('may fail when asserting URL host matches but it does not', function (): void {
Route::get('/test-url', fn (): string => 'Test URL Page');
$page = visit('/test-url');
$page->assertHostIs('wrong-host.com');
})->throws(ExpectationFailedException::class);
it('may assert URL host does not match expected host', function (): void {
Route::get('/test-url', fn (): string => 'Test URL Page');
$page = visit('/test-url');
$page->assertHostIsNot('wrong-host.com');
});
it('may fail when asserting URL host does not match but it does', function (): void {
Route::get('/test-url', fn (): string => 'Test URL Page');
$page = visit('/test-url');
// Extract the host from the current URL
$host = parse_url(url('/test-url'), PHP_URL_HOST);
$page->assertHostIsNot($host);
})->throws(ExpectationFailedException::class);
it('may assert URL path matches expected path', function (): void {
Route::get('/test-path', fn (): string => 'Test Path Page');
$page = visit('/test-path');
$page->assertPathIs('/test-path');
});
it('may assert URL path matches a route', function (): void {
Route::name('test.path')->get('/test-path', fn (): string => 'Test Path Page');
$page = visit('/test-path');
$page->assertRoute('test.path');
});
it('may fail when asserting URL path matches a route but it does not', function (): void {
Route::name('test.path')->get('/test-path', fn (): string => 'Test Path Page');
$page = visit('/wrong-path');
$page->assertRoute('test.path');
})->throws(ExpectationFailedException::class);
it('may assert URL path matches a route with paramters', function (): void {
Route::name('test.path')->get('/test-path/{slug}', fn ($slug): string => 'Test Path Page');
$page = visit('/test-path/example');
$page->assertRoute('test.path', ['slug' => 'example']);
});
it('may fail when asserting URL path matches a route but it has wrong parameters', function (): void {
Route::name('test.path')->get('/test-path/{slug}', fn ($slug): string => 'Test Path Page');
$page = visit('/test-path/wrong-slug');
$page->assertRoute('test.path', ['slug' => 'example']);
})->throws(ExpectationFailedException::class);
it('may fail when asserting URL path matches but it does not', function (): void {
Route::get('/test-path', fn (): string => 'Test Path Page');
$page = visit('/test-path');
$page->assertPathIs('/wrong-path');
})->throws(ExpectationFailedException::class);
it('may assert URL path does not match expected path', function (): void {
Route::get('/test-path', fn (): string => 'Test Path Page');
$page = visit('/test-path');
$page->assertPathIsNot('/wrong-path');
});
it('may fail when asserting URL path does not match but it does', function (): void {
Route::get('/test-path', fn (): string => 'Test Path Page');
$page = visit('/test-path');
$page->assertPathIsNot('/test-path');
})->throws(ExpectationFailedException::class);
it('may assert URL path begins with expected path', function (): void {
Route::get('/test/nested/path', fn (): string => 'Test Nested Path Page');
$page = visit('/test/nested/path');
$page->assertPathBeginsWith('/test');
});
it('may fail when asserting URL path begins with expected path but it does not', function (): void {
Route::get('/test/nested/path', fn (): string => 'Test Nested Path Page');
$page = visit('/test/nested/path');
$page->assertPathBeginsWith('/wrong');
})->throws(ExpectationFailedException::class);
it('may assert URL path ends with expected path', function (): void {
Route::get('/test/nested/path', fn (): string => 'Test Nested Path Page');
$page = visit('/test/nested/path');
$page->assertPathEndsWith('/path');
});
it('may fail when asserting URL path ends with expected path but it does not', function (): void {
Route::get('/test/nested/path', fn (): string => 'Test Nested Path Page');
$page = visit('/test/nested/path');
$page->assertPathEndsWith('/wrong');
})->throws(ExpectationFailedException::class);
it('may assert URL path contains expected string', function (): void {
Route::get('/test/nested/path', fn (): string => 'Test Nested Path Page');
$page = visit('/test/nested/path');
$page->assertPathContains('nested');
});
it('may fail when asserting URL path contains expected string but it does not', function (): void {
Route::get('/test/nested/path', fn (): string => 'Test Nested Path Page');
$page = visit('/test/nested/path');
$page->assertPathContains('wrong');
})->throws(ExpectationFailedException::class);
it('may assert URL has expected query string parameter', function (): void {
Route::get('/test-query', fn (): string => 'Test Query Page');
$page = visit('/test-query?param=value');
$page->assertQueryStringHas('param');
$page->assertQueryStringHas('param', 'value');
});
it('may fail when asserting URL has query string parameter but it does not', function (): void {
Route::get('/test-query', fn (): string => 'Test Query Page');
$page = visit('/test-query?param=value');
$page->assertQueryStringHas('missing');
})->throws(ExpectationFailedException::class);
it('may fail when asserting URL has query string parameter with specific value but it does not', function (): void {
Route::get('/test-query', fn (): string => 'Test Query Page');
$page = visit('/test-query?param=value');
$page->assertQueryStringHas('param', 'wrong');
})->throws(ExpectationFailedException::class);
it('may assert URL does not have expected query string parameter', function (): void {
Route::get('/test-query', fn (): string => 'Test Query Page');
$page = visit('/test-query?param=value');
$page->assertQueryStringMissing('missing');
});
it('may fail when asserting URL does not have query string parameter but it does', function (): void {
Route::get('/test-query', fn (): string => 'Test Query Page');
$page = visit('/test-query?param=value');
$page->assertQueryStringMissing('param');
})->throws(ExpectationFailedException::class);