forked from minkphp/driver-testsuite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRadioTest.php
123 lines (92 loc) · 3.15 KB
/
RadioTest.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
<?php
namespace Behat\Mink\Tests\Driver\Form;
use Behat\Mink\Exception\DriverException;
use Behat\Mink\Tests\Driver\TestCase;
final class RadioTest extends TestCase
{
/**
* @before
*/
protected function visitPage(): void
{
$this->getSession()->visit($this->pathTo('radio.html'));
}
public function testIsChecked(): void
{
$option = $this->findById('first');
$option2 = $this->findById('second');
$this->assertTrue($option->isChecked());
$this->assertFalse($option2->isChecked());
$option2->selectOption('updated');
$this->assertFalse($option->isChecked());
$this->assertTrue($option2->isChecked());
}
public function testSelectOption(): void
{
$option = $this->findById('first');
$this->assertEquals('set', $option->getValue());
$option->selectOption('updated');
$this->assertEquals('updated', $option->getValue());
$option->selectOption('set');
$this->assertEquals('set', $option->getValue());
}
public function testValueIsNullIfNoSelectedOption(): void
{
$option = $this->findById('empty');
self::assertNull($option->getValue());
}
public function testSetValue(): void
{
$option = $this->findById('first');
$this->assertEquals('set', $option->getValue());
$option->setValue('updated');
$this->assertEquals('updated', $option->getValue());
$this->assertFalse($option->isChecked());
}
public function testSameNameInMultipleForms(): void
{
$option1 = $this->findById('reused_form1');
$option2 = $this->findById('reused_form2');
$this->assertEquals('test2', $option1->getValue());
$this->assertEquals('test3', $option2->getValue());
$option1->selectOption('test');
$this->assertEquals('test', $option1->getValue());
$this->assertEquals('test3', $option2->getValue());
}
/**
* @see https://github.com/Behat/MinkSahiDriver/issues/32
*/
public function testSetValueXPathEscaping(): void
{
$session = $this->getSession();
$session->visit($this->pathTo('/advanced_form.html'));
$page = $session->getPage();
$sex = $page->find('xpath', '//*[@name = "sex"]' . "\n|\n" . '//*[@id = "sex"]');
$this->assertNotNull($sex, 'xpath with line ending works');
$sex->setValue('m');
$this->assertEquals('m', $sex->getValue(), 'no double xpath escaping during radio button value change');
}
public function testSetArrayValue(): void
{
$option = $this->findById('first');
$this->expectException(DriverException::class);
$option->setValue(['bad']);
}
/**
* @dataProvider provideBooleanValues
*/
public function testSetBooleanValue(bool $value): void
{
$option = $this->findById('first');
$this->expectException(DriverException::class);
$option->setValue($value);
}
/**
* @return iterable<array{bool}>
*/
public static function provideBooleanValues(): iterable
{
yield [true];
yield [false];
}
}