Passed
Pull Request — 1.x (#15)
by Kevin
33:03 queued 30:38
created

HtmlTests::can_follow_button_by_value()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
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()
0 ignored issues
show
Bug introduced by
It seems like browser() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

15
        $this->/** @scrutinizer ignore-call */ 
16
               browser()
Loading history...
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 form_actions_by_field_label(): void
82
    {
83
        $this->browser()
84
            ->visit('/page1')
85
            ->fillField('Input 1', 'Kevin')
86
            ->checkField('Input 2')
87
            ->uncheckField('Input 3')
88
            ->selectFieldOption('Input 4', 'option 2')
89
            ->attachFile('Input 5', __FILE__)
90
            ->selectFieldOptions('Input 6', ['option 1', 'option 3'])
91
            ->click('Submit')
92
            ->assertOn('/submit-form')
93
            ->assertContains('"input_1":"Kevin"')
94
            ->assertContains('"input_2":"on"')
95
            ->assertNotContains('"input_3')
96
            ->assertContains('"input_4":"option 2"')
97
            ->assertContains(\sprintf('"input_5":"%s"', \pathinfo(__FILE__, PATHINFO_BASENAME)))
98
            ->assertContains('"input_6":["option 1","option 3"]')
99
        ;
100
    }
101
102
    /**
103
     * @test
104
     */
105
    public function form_actions_by_field_id(): void
106
    {
107
        $this->browser()
108
            ->visit('/page1')
109
            ->fillField('input1', 'Kevin')
110
            ->checkField('input2')
111
            ->uncheckField('input3')
112
            ->selectFieldOption('input4', 'option 2')
113
            ->attachFile('input5', __FILE__)
114
            ->selectFieldOptions('input6', ['option 1', 'option 3'])
115
            ->click('Submit')
116
            ->assertOn('/submit-form')
117
            ->assertContains('"input_1":"Kevin"')
118
            ->assertContains('"input_2":"on"')
119
            ->assertNotContains('"input_3')
120
            ->assertContains('"input_4":"option 2"')
121
            ->assertContains(\sprintf('"input_5":"%s"', \pathinfo(__FILE__, PATHINFO_BASENAME)))
122
            ->assertContains('"input_6":["option 1","option 3"]')
123
        ;
124
    }
125
126
    /**
127
     * @test
128
     */
129
    public function form_actions_by_field_name(): void
130
    {
131
        $this->browser()
132
            ->visit('/page1')
133
            ->fillField('input_1', 'Kevin')
134
            ->checkField('input_2')
135
            ->uncheckField('input_3')
136
            ->selectFieldOption('input_4', 'option 2')
137
            ->attachFile('input_5', __FILE__)
138
            ->selectFieldOptions('input_6[]', ['option 1', 'option 3'])
139
            ->click('Submit')
140
            ->assertOn('/submit-form')
141
            ->assertContains('"input_1":"Kevin"')
142
            ->assertContains('"input_2":"on"')
143
            ->assertNotContains('"input_3')
144
            ->assertContains('"input_4":"option 2"')
145
            ->assertContains(\sprintf('"input_5":"%s"', \pathinfo(__FILE__, PATHINFO_BASENAME)))
146
            ->assertContains('"input_6":["option 1","option 3"]')
147
        ;
148
    }
149
150
    /**
151
     * @test
152
     */
153
    public function form_actions_by_css_selector(): void
154
    {
155
        $this->markTestIncomplete();
0 ignored issues
show
Bug introduced by
It seems like markTestIncomplete() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

155
        $this->/** @scrutinizer ignore-call */ 
156
               markTestIncomplete();
Loading history...
156
    }
157
158
    /**
159
     * @test
160
     */
161
    public function can_dump_html_element(): void
162
    {
163
        $output = self::catchVarDumperOutput(function() {
164
            $this->browser()
165
                ->visit('/page1')
166
                ->dump('p#link')
167
            ;
168
        });
169
170
        $this->assertCount(1, $output);
0 ignored issues
show
Bug introduced by
It seems like assertCount() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

170
        $this->/** @scrutinizer ignore-call */ 
171
               assertCount(1, $output);
Loading history...
171
        $this->assertSame('<a href="/page2">a link</a> not a link', $output[0]);
0 ignored issues
show
Bug introduced by
It seems like assertSame() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

171
        $this->/** @scrutinizer ignore-call */ 
172
               assertSame('<a href="/page2">a link</a> not a link', $output[0]);
Loading history...
172
    }
173
174
    /**
175
     * @test
176
     */
177
    public function if_dump_selector_matches_multiple_elements_all_are_dumped(): void
178
    {
179
        $output = self::catchVarDumperOutput(function() {
180
            $this->browser()
181
                ->visit('/page1')
182
                ->dump('li')
183
            ;
184
        });
185
186
        $this->assertCount(2, $output);
187
        $this->assertSame('list 1', $output[0]);
188
        $this->assertSame('list 2', $output[1]);
189
    }
190
191
    /**
192
     * @test
193
     */
194
    public function can_follow_link_by_link_id(): void
195
    {
196
        $this->markTestIncomplete();
197
    }
198
199
    /**
200
     * @test
201
     */
202
    public function can_follow_link_by_link_title(): void
203
    {
204
        $this->markTestIncomplete();
205
    }
206
207
    /**
208
     * @test
209
     */
210
    public function can_follow_link_by_link_text(): void
211
    {
212
        $this->markTestIncomplete();
213
    }
214
215
    /**
216
     * @test
217
     */
218
    public function can_follow_link_by_image_alt(): void
219
    {
220
        $this->markTestIncomplete();
221
    }
222
223
    /**
224
     * @test
225
     */
226
    public function can_follow_link_by_css_selector(): void
227
    {
228
        $this->markTestIncomplete();
229
    }
230
231
    /**
232
     * @test
233
     */
234
    public function can_follow_button_by_id(): void
235
    {
236
        $this->markTestIncomplete();
237
    }
238
239
    /**
240
     * @test
241
     */
242
    public function can_follow_button_by_value(): void
243
    {
244
        $this->markTestIncomplete();
245
    }
246
247
    /**
248
     * @test
249
     */
250
    public function can_follow_button_by_text(): void
251
    {
252
        $this->markTestIncomplete();
253
    }
254
255
    /**
256
     * @test
257
     */
258
    public function can_follow_button_by_css_selector(): void
259
    {
260
        $this->markTestIncomplete();
261
    }
262
263
    /**
264
     * @test
265
     */
266
    public function can_click_button_by_id(): void
267
    {
268
        $this->markTestIncomplete();
269
    }
270
271
    /**
272
     * @test
273
     */
274
    public function can_click_button_by_value(): void
275
    {
276
        $this->markTestIncomplete();
277
    }
278
279
    /**
280
     * @test
281
     */
282
    public function can_click_button_by_text(): void
283
    {
284
        $this->markTestIncomplete();
285
    }
286
287
    /**
288
     * @test
289
     */
290
    public function can_click_button_by_css_selector(): void
291
    {
292
        $this->markTestIncomplete();
293
    }
294
295
    /**
296
     * @test
297
     */
298
    public function can_click_link_by_link_id(): void
299
    {
300
        $this->markTestIncomplete();
301
    }
302
303
    /**
304
     * @test
305
     */
306
    public function can_click_link_by_link_title(): void
307
    {
308
        $this->markTestIncomplete();
309
    }
310
311
    /**
312
     * @test
313
     */
314
    public function can_click_link_by_link_text(): void
315
    {
316
        $this->markTestIncomplete();
317
    }
318
319
    /**
320
     * @test
321
     */
322
    public function can_click_link_by_image_alt(): void
323
    {
324
        $this->markTestIncomplete();
325
    }
326
327
    /**
328
     * @test
329
     */
330
    public function can_click_link_by_css_selector(): void
331
    {
332
        $this->markTestIncomplete();
333
    }
334
}
335