-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathEventsTest.php
181 lines (159 loc) · 6.62 KB
/
EventsTest.php
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
<?php
declare(strict_types=1);
namespace Behat\Mink\Tests\Driver\Custom;
use Behat\Mink\Tests\Driver\Js\EventsTest as BaseEventsTest;
use Behat\Mink\Tests\Driver\TestCase;
/**
* @see BaseEventsTest
*/
class EventsTest extends TestCase
{
/**
* @group mouse-events
*/
public function testClick(): void
{
$this->getSession()->visit($this->pathTo('/js_test.html'));
$clicker = $this->getAssertSession()->elementExists('css', '.elements div#clicker');
$this->assertEquals('not clicked', $clicker->getText());
$clicker->click();
$this->assertEquals('single clicked', $clicker->getText());
}
/**
* @group mouse-events
*/
public function testDoubleClick(): void
{
$this->getSession()->visit($this->pathTo('/js_test.html'));
$clicker = $this->getAssertSession()->elementExists('css', '.elements div#clicker');
$this->assertEquals('not clicked', $clicker->getText());
$clicker->doubleClick();
$this->assertEquals('double clicked', $clicker->getText());
}
/**
* @group mouse-events
*/
public function testRightClick(): void
{
$this->getSession()->visit($this->pathTo('/js_test.html'));
$clicker = $this->getAssertSession()->elementExists('css', '.elements div#clicker');
$this->assertEquals('not clicked', $clicker->getText());
$clicker->rightClick();
$this->assertEquals('right clicked', $clicker->getText());
}
/**
* @group mouse-events
*/
public function testFocus(): void
{
$this->getSession()->visit($this->pathTo('/js_test.html'));
$focusBlurDetector = $this->getAssertSession()->elementExists('css', '.elements input#focus-blur-detector');
$this->assertEquals('no action detected', $focusBlurDetector->getValue());
$focusBlurDetector->focus();
$this->assertEquals('focused', $focusBlurDetector->getValue());
}
/**
* @group mouse-events
* @depends testFocus
*/
public function testBlur(): void
{
$this->getSession()->visit($this->pathTo('/js_test.html'));
$focusBlurDetector = $this->getAssertSession()->elementExists('css', '.elements input#focus-blur-detector');
$this->assertEquals('no action detected', $focusBlurDetector->getValue());
$focusBlurDetector->focus();
$focusBlurDetector->blur();
$this->assertEquals('blured', $focusBlurDetector->getValue());
}
/**
* @group mouse-events
*/
public function testMouseOver(): void
{
$this->getSession()->visit($this->pathTo('/js_test.html'));
$mouseOverDetector = $this->getAssertSession()->elementExists('css', '.elements div#mouseover-detector');
$this->assertEquals('no mouse action detected', $mouseOverDetector->getText());
$mouseOverDetector->mouseOver();
$this->assertEquals('mouse overed', $mouseOverDetector->getText());
}
// /**
// * @param KeyModifier::*|null $modifier
// *
// * @dataProvider provideKeyboardEventsModifiers
// */
// public function testKeyboardEvents(?string $modifier, string $eventProperties): void
// {
// $this->getSession()->visit($this->pathTo('/js_test.html'));
// $webAssert = $this->getAssertSession();
//
// $input1 = $webAssert->elementExists('css', '.elements input.input.first');
// $input2 = $webAssert->elementExists('css', '.elements input.input.second');
// $input3 = $webAssert->elementExists('css', '.elements input.input.third');
// $event = $webAssert->elementExists('css', '.elements .text-event');
//
// $input1->keyDown('u', $modifier);
// $this->assertEquals('key downed:' . $eventProperties, $event->getText());
//
// $input2->keyPress('r', $modifier);
// $this->assertEquals('key pressed:114 / ' . $eventProperties, $event->getText());
//
// $input2->keyPress('R', $modifier);
// $this->assertEquals('key pressed:82 / ' . $eventProperties, $event->getText());
//
// $input2->keyPress('0', $modifier);
// $this->assertEquals('key pressed:48 / ' . $eventProperties, $event->getText());
//
// $input3->keyUp(78, $modifier);
// $this->assertEquals('key upped:78 / ' . $eventProperties, $event->getText());
// }
//
// public static function provideKeyboardEventsModifiers(): iterable
// {
// return [
// 'none' => [null, '0 / 0 / 0 / 0'],
// 'alt' => [KeyModifier::ALT, '1 / 0 / 0 / 0'],
// // jQuery considers ctrl as being a metaKey in the normalized event
// 'ctrl' => [KeyModifier::CTRL, '0 / 1 / 0 / 1'],
// 'shift' => [KeyModifier::SHIFT, '0 / 0 / 1 / 0'],
// 'meta' => [KeyModifier::META, '0 / 0 / 0 / 1'],
// ];
// }
/**
* @dataProvider provideKeyboardEventsModifiers
*/
public function testKeyboardEvents($modifier, $eventProperties)
{
// we use custom html file cause when using keyUp then we cannot release key and modifier at once
// which will break base test
file_put_contents(
__DIR__.'/../../vendor/mink/driver-testsuite/web-fixtures/js_test_custom.html',
file_get_contents(__DIR__.'/web-fixtures/js_test.html')
);
$this->getSession()->visit($this->pathTo('/js_test_custom.html'));
$webAssert = $this->getAssertSession();
$input1 = $webAssert->elementExists('css', '.elements input.input.first');
$input2 = $webAssert->elementExists('css', '.elements input.input.second');
$input3 = $webAssert->elementExists('css', '.elements input.input.third');
$event = $webAssert->elementExists('css', '.elements .text-event');
$input1->keyDown('u', $modifier);
$this->assertStringContainsString('key downed:'.$eventProperties, $event->getText());
$input2->keyPress('r', $modifier);
if ('shift' === $modifier) {
$this->assertStringContainsString('key pressed:82 / '.$eventProperties, $event->getText());
} else {
$this->assertStringContainsString('key pressed:114 / '.$eventProperties, $event->getText());
}
$input3->keyUp(78, $modifier);
$this->assertStringContainsString('key upped:78 / '.$eventProperties, $event->getText());
}
public function provideKeyboardEventsModifiers()
{
return array(
'none' => array(null, '0 / 0 / 0 / 0'),
'alt' => array('alt', '1 / 0 / 0 / 0'),
'ctrl' => array('ctrl', '0 / 1 / 0 / 1'),
'shift' => array('shift', '0 / 0 / 1 / 0'),
'meta' => array('meta', '0 / 0 / 0 / 1'),
);
}
}