|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Zenstruck\Browser\Tests\Extension; |
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* @author Kevin Bond <[email protected]> |
|
7
|
|
|
*/ |
|
8
|
|
|
trait HtmlTests |
|
9
|
|
|
{ |
|
10
|
|
|
/** |
|
11
|
|
|
* @test |
|
12
|
|
|
*/ |
|
13
|
|
|
public function html_assertions(): void |
|
14
|
|
|
{ |
|
15
|
|
|
$this->browser() |
|
|
|
|
|
|
16
|
|
|
->visit('/page1') |
|
17
|
|
|
->assertSee('h1 title') |
|
18
|
|
|
->assertNotSee('invalid text') |
|
19
|
|
|
->assertSeeIn('h1', 'title') |
|
20
|
|
|
->assertNotSeeIn('h1', 'invalid text') |
|
21
|
|
|
->assertSeeElement('h1') |
|
22
|
|
|
->assertNotSeeElement('h2') |
|
23
|
|
|
->assertElementCount('ul li', 2) |
|
24
|
|
|
; |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @test |
|
29
|
|
|
*/ |
|
30
|
|
|
public function html_head_assertions(): void |
|
31
|
|
|
{ |
|
32
|
|
|
$this->browser() |
|
33
|
|
|
->visit('/page1') |
|
34
|
|
|
->assertSeeIn('title', 'meta title') |
|
35
|
|
|
->assertElementAttributeContains('meta[name="description"]', 'content', 'meta') |
|
36
|
|
|
->assertElementAttributeNotContains('meta[name="description"]', 'content', 'invalid') |
|
37
|
|
|
->assertElementAttributeContains('html', 'lang', 'en') |
|
38
|
|
|
; |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* @test |
|
43
|
|
|
*/ |
|
44
|
|
|
public function form_assertions(): void |
|
45
|
|
|
{ |
|
46
|
|
|
$this->browser() |
|
47
|
|
|
->visit('/page1') |
|
48
|
|
|
->assertFieldEquals('Input 1', 'input 1') |
|
49
|
|
|
->assertFieldEquals('input1', 'input 1') |
|
50
|
|
|
->assertFieldEquals('input_1', 'input 1') |
|
51
|
|
|
->assertFieldNotEquals('Input 1', 'invalid') |
|
52
|
|
|
->assertFieldNotEquals('input1', 'invalid') |
|
53
|
|
|
->assertFieldNotEquals('input_1', 'invalid') |
|
54
|
|
|
->assertChecked('Input 3') |
|
55
|
|
|
->assertChecked('input3') |
|
56
|
|
|
->assertChecked('input_3') |
|
57
|
|
|
->assertNotChecked('Input 2') |
|
58
|
|
|
->assertNotChecked('input2') |
|
59
|
|
|
->assertNotChecked('input_2') |
|
60
|
|
|
->assertSelected('Input 4', 'option 1') |
|
61
|
|
|
->assertSelected('input4', 'option 1') |
|
62
|
|
|
->assertSelected('input_4', 'option 1') |
|
63
|
|
|
->assertSelected('Input 7', 'option 1') |
|
64
|
|
|
->assertSelected('input7', 'option 1') |
|
65
|
|
|
->assertSelected('input_7[]', 'option 1') |
|
66
|
|
|
->assertSelected('Input 7', 'option 3') |
|
67
|
|
|
->assertSelected('input7', 'option 3') |
|
68
|
|
|
->assertSelected('input_7[]', 'option 3') |
|
69
|
|
|
->assertNotSelected('Input 4', 'option 2') |
|
70
|
|
|
->assertNotSelected('input4', 'option 2') |
|
71
|
|
|
->assertNotSelected('input_4', 'option 2') |
|
72
|
|
|
->assertNotSelected('Input 7', 'option 2') |
|
73
|
|
|
->assertNotSelected('input7', 'option 2') |
|
74
|
|
|
->assertNotSelected('input_7[]', 'option 2') |
|
75
|
|
|
; |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* @test |
|
80
|
|
|
*/ |
|
81
|
|
|
public function link_action(): void |
|
82
|
|
|
{ |
|
83
|
|
|
$this->browser() |
|
84
|
|
|
->visit('/page1') |
|
85
|
|
|
->follow('a link') |
|
86
|
|
|
->assertOn('/page2') |
|
87
|
|
|
->visit('/page1') |
|
88
|
|
|
->click('a link') |
|
89
|
|
|
->assertOn('/page2') |
|
90
|
|
|
; |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
/** |
|
94
|
|
|
* @test |
|
95
|
|
|
*/ |
|
96
|
|
|
public function form_actions_by_field_label(): void |
|
97
|
|
|
{ |
|
98
|
|
|
$this->browser() |
|
99
|
|
|
->visit('/page1') |
|
100
|
|
|
->fillField('Input 1', 'Kevin') |
|
101
|
|
|
->checkField('Input 2') |
|
102
|
|
|
->uncheckField('Input 3') |
|
103
|
|
|
->selectFieldOption('Input 4', 'option 2') |
|
104
|
|
|
->attachFile('Input 5', __FILE__) |
|
105
|
|
|
->selectFieldOptions('Input 6', ['option 1', 'option 3']) |
|
106
|
|
|
->click('Submit') |
|
107
|
|
|
->assertOn('/submit-form') |
|
108
|
|
|
->assertContains('"input_1":"Kevin"') |
|
109
|
|
|
->assertContains('"input_2":"on"') |
|
110
|
|
|
->assertNotContains('"input_3') |
|
111
|
|
|
->assertContains('"input_4":"option 2"') |
|
112
|
|
|
->assertContains(\sprintf('"input_5":"%s"', \pathinfo(__FILE__, PATHINFO_BASENAME))) |
|
113
|
|
|
->assertContains('"input_6":["option 1","option 3"]') |
|
114
|
|
|
; |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
|
/** |
|
118
|
|
|
* @test |
|
119
|
|
|
*/ |
|
120
|
|
|
public function form_actions_by_field_id(): void |
|
121
|
|
|
{ |
|
122
|
|
|
$this->browser() |
|
123
|
|
|
->visit('/page1') |
|
124
|
|
|
->fillField('input1', 'Kevin') |
|
125
|
|
|
->checkField('input2') |
|
126
|
|
|
->uncheckField('input3') |
|
127
|
|
|
->selectFieldOption('input4', 'option 2') |
|
128
|
|
|
->attachFile('input5', __FILE__) |
|
129
|
|
|
->selectFieldOptions('input6', ['option 1', 'option 3']) |
|
130
|
|
|
->click('Submit') |
|
131
|
|
|
->assertOn('/submit-form') |
|
132
|
|
|
->assertContains('"input_1":"Kevin"') |
|
133
|
|
|
->assertContains('"input_2":"on"') |
|
134
|
|
|
->assertNotContains('"input_3') |
|
135
|
|
|
->assertContains('"input_4":"option 2"') |
|
136
|
|
|
->assertContains(\sprintf('"input_5":"%s"', \pathinfo(__FILE__, PATHINFO_BASENAME))) |
|
137
|
|
|
->assertContains('"input_6":["option 1","option 3"]') |
|
138
|
|
|
; |
|
139
|
|
|
} |
|
140
|
|
|
|
|
141
|
|
|
/** |
|
142
|
|
|
* @test |
|
143
|
|
|
*/ |
|
144
|
|
|
public function form_actions_by_field_name(): void |
|
145
|
|
|
{ |
|
146
|
|
|
$this->browser() |
|
147
|
|
|
->visit('/page1') |
|
148
|
|
|
->fillField('input_1', 'Kevin') |
|
149
|
|
|
->checkField('input_2') |
|
150
|
|
|
->uncheckField('input_3') |
|
151
|
|
|
->selectFieldOption('input_4', 'option 2') |
|
152
|
|
|
->attachFile('input_5', __FILE__) |
|
153
|
|
|
->selectFieldOptions('input_6[]', ['option 1', 'option 3']) |
|
154
|
|
|
->click('Submit') |
|
155
|
|
|
->assertOn('/submit-form') |
|
156
|
|
|
->assertContains('"input_1":"Kevin"') |
|
157
|
|
|
->assertContains('"input_2":"on"') |
|
158
|
|
|
->assertNotContains('"input_3') |
|
159
|
|
|
->assertContains('"input_4":"option 2"') |
|
160
|
|
|
->assertContains(\sprintf('"input_5":"%s"', \pathinfo(__FILE__, PATHINFO_BASENAME))) |
|
161
|
|
|
->assertContains('"input_6":["option 1","option 3"]') |
|
162
|
|
|
; |
|
163
|
|
|
} |
|
164
|
|
|
|
|
165
|
|
|
/** |
|
166
|
|
|
* @test |
|
167
|
|
|
*/ |
|
168
|
|
|
public function form_actions_by_css_selector(): void |
|
169
|
|
|
{ |
|
170
|
|
|
$this->markTestIncomplete(); |
|
|
|
|
|
|
171
|
|
|
} |
|
172
|
|
|
|
|
173
|
|
|
/** |
|
174
|
|
|
* @test |
|
175
|
|
|
*/ |
|
176
|
|
|
public function can_dump_html_element(): void |
|
177
|
|
|
{ |
|
178
|
|
|
$output = self::catchVarDumperOutput(function() { |
|
179
|
|
|
$this->browser() |
|
180
|
|
|
->visit('/page1') |
|
181
|
|
|
->dump('p#link') |
|
182
|
|
|
; |
|
183
|
|
|
}); |
|
184
|
|
|
|
|
185
|
|
|
$this->assertCount(1, $output); |
|
|
|
|
|
|
186
|
|
|
$this->assertSame('<a href="/page2">a link</a> not a link', $output[0]); |
|
|
|
|
|
|
187
|
|
|
} |
|
188
|
|
|
|
|
189
|
|
|
/** |
|
190
|
|
|
* @test |
|
191
|
|
|
*/ |
|
192
|
|
|
public function if_dump_selector_matches_multiple_elements_all_are_dumped(): void |
|
193
|
|
|
{ |
|
194
|
|
|
$output = self::catchVarDumperOutput(function() { |
|
195
|
|
|
$this->browser() |
|
196
|
|
|
->visit('/page1') |
|
197
|
|
|
->dump('li') |
|
198
|
|
|
; |
|
199
|
|
|
}); |
|
200
|
|
|
|
|
201
|
|
|
$this->assertCount(2, $output); |
|
202
|
|
|
$this->assertSame('list 1', $output[0]); |
|
203
|
|
|
$this->assertSame('list 2', $output[1]); |
|
204
|
|
|
} |
|
205
|
|
|
|
|
206
|
|
|
/** |
|
207
|
|
|
* @test |
|
208
|
|
|
*/ |
|
209
|
|
|
public function can_follow_link_by_link_id(): void |
|
210
|
|
|
{ |
|
211
|
|
|
$this->markTestIncomplete(); |
|
212
|
|
|
} |
|
213
|
|
|
|
|
214
|
|
|
/** |
|
215
|
|
|
* @test |
|
216
|
|
|
*/ |
|
217
|
|
|
public function can_follow_link_by_link_title(): void |
|
218
|
|
|
{ |
|
219
|
|
|
$this->markTestIncomplete(); |
|
220
|
|
|
} |
|
221
|
|
|
|
|
222
|
|
|
/** |
|
223
|
|
|
* @test |
|
224
|
|
|
*/ |
|
225
|
|
|
public function can_follow_link_by_link_text(): void |
|
226
|
|
|
{ |
|
227
|
|
|
$this->markTestIncomplete(); |
|
228
|
|
|
} |
|
229
|
|
|
|
|
230
|
|
|
/** |
|
231
|
|
|
* @test |
|
232
|
|
|
*/ |
|
233
|
|
|
public function can_follow_link_by_image_alt(): void |
|
234
|
|
|
{ |
|
235
|
|
|
$this->markTestIncomplete(); |
|
236
|
|
|
} |
|
237
|
|
|
|
|
238
|
|
|
/** |
|
239
|
|
|
* @test |
|
240
|
|
|
*/ |
|
241
|
|
|
public function can_follow_link_by_css_selector(): void |
|
242
|
|
|
{ |
|
243
|
|
|
$this->markTestIncomplete(); |
|
244
|
|
|
} |
|
245
|
|
|
|
|
246
|
|
|
/** |
|
247
|
|
|
* @test |
|
248
|
|
|
*/ |
|
249
|
|
|
public function can_follow_button_by_id(): void |
|
250
|
|
|
{ |
|
251
|
|
|
$this->markTestIncomplete(); |
|
252
|
|
|
} |
|
253
|
|
|
|
|
254
|
|
|
/** |
|
255
|
|
|
* @test |
|
256
|
|
|
*/ |
|
257
|
|
|
public function can_follow_button_by_value(): void |
|
258
|
|
|
{ |
|
259
|
|
|
$this->markTestIncomplete(); |
|
260
|
|
|
} |
|
261
|
|
|
|
|
262
|
|
|
/** |
|
263
|
|
|
* @test |
|
264
|
|
|
*/ |
|
265
|
|
|
public function can_follow_button_by_text(): void |
|
266
|
|
|
{ |
|
267
|
|
|
$this->markTestIncomplete(); |
|
268
|
|
|
} |
|
269
|
|
|
|
|
270
|
|
|
/** |
|
271
|
|
|
* @test |
|
272
|
|
|
*/ |
|
273
|
|
|
public function can_follow_button_by_css_selector(): void |
|
274
|
|
|
{ |
|
275
|
|
|
$this->markTestIncomplete(); |
|
276
|
|
|
} |
|
277
|
|
|
|
|
278
|
|
|
/** |
|
279
|
|
|
* @test |
|
280
|
|
|
*/ |
|
281
|
|
|
public function can_click_button_by_id(): void |
|
282
|
|
|
{ |
|
283
|
|
|
$this->markTestIncomplete(); |
|
284
|
|
|
} |
|
285
|
|
|
|
|
286
|
|
|
/** |
|
287
|
|
|
* @test |
|
288
|
|
|
*/ |
|
289
|
|
|
public function can_click_button_by_value(): void |
|
290
|
|
|
{ |
|
291
|
|
|
$this->markTestIncomplete(); |
|
292
|
|
|
} |
|
293
|
|
|
|
|
294
|
|
|
/** |
|
295
|
|
|
* @test |
|
296
|
|
|
*/ |
|
297
|
|
|
public function can_click_button_by_text(): void |
|
298
|
|
|
{ |
|
299
|
|
|
$this->markTestIncomplete(); |
|
300
|
|
|
} |
|
301
|
|
|
|
|
302
|
|
|
/** |
|
303
|
|
|
* @test |
|
304
|
|
|
*/ |
|
305
|
|
|
public function can_click_button_by_css_selector(): void |
|
306
|
|
|
{ |
|
307
|
|
|
$this->markTestIncomplete(); |
|
308
|
|
|
} |
|
309
|
|
|
|
|
310
|
|
|
/** |
|
311
|
|
|
* @test |
|
312
|
|
|
*/ |
|
313
|
|
|
public function can_click_link_by_link_id(): void |
|
314
|
|
|
{ |
|
315
|
|
|
$this->markTestIncomplete(); |
|
316
|
|
|
} |
|
317
|
|
|
|
|
318
|
|
|
/** |
|
319
|
|
|
* @test |
|
320
|
|
|
*/ |
|
321
|
|
|
public function can_click_link_by_link_title(): void |
|
322
|
|
|
{ |
|
323
|
|
|
$this->markTestIncomplete(); |
|
324
|
|
|
} |
|
325
|
|
|
|
|
326
|
|
|
/** |
|
327
|
|
|
* @test |
|
328
|
|
|
*/ |
|
329
|
|
|
public function can_click_link_by_link_text(): void |
|
330
|
|
|
{ |
|
331
|
|
|
$this->markTestIncomplete(); |
|
332
|
|
|
} |
|
333
|
|
|
|
|
334
|
|
|
/** |
|
335
|
|
|
* @test |
|
336
|
|
|
*/ |
|
337
|
|
|
public function can_click_link_by_image_alt(): void |
|
338
|
|
|
{ |
|
339
|
|
|
$this->markTestIncomplete(); |
|
340
|
|
|
} |
|
341
|
|
|
|
|
342
|
|
|
/** |
|
343
|
|
|
* @test |
|
344
|
|
|
*/ |
|
345
|
|
|
public function can_click_link_by_css_selector(): void |
|
346
|
|
|
{ |
|
347
|
|
|
$this->markTestIncomplete(); |
|
348
|
|
|
} |
|
349
|
|
|
} |
|
350
|
|
|
|