public function ChoiceFormFieldTest::testSelects in Zircon Profile 8.0
Same name and namespace in other branches
- 8 vendor/symfony/dom-crawler/Tests/Field/ChoiceFormFieldTest.php \Symfony\Component\DomCrawler\Tests\Field\ChoiceFormFieldTest::testSelects()
File
- vendor/
symfony/ dom-crawler/ Tests/ Field/ ChoiceFormFieldTest.php, line 83
Class
Namespace
Symfony\Component\DomCrawler\Tests\FieldCode
public function testSelects() {
$node = $this
->createSelectNode(array(
'foo' => false,
'bar' => false,
));
$field = new ChoiceFormField($node);
$this
->assertTrue($field
->hasValue(), '->hasValue() returns true for selects');
$this
->assertEquals('foo', $field
->getValue(), '->getValue() returns the first option if none are selected');
$this
->assertFalse($field
->isMultiple(), '->isMultiple() returns false when no multiple attribute is defined');
$node = $this
->createSelectNode(array(
'foo' => false,
'bar' => true,
));
$field = new ChoiceFormField($node);
$this
->assertEquals('bar', $field
->getValue(), '->getValue() returns the selected option');
$field
->setValue('foo');
$this
->assertEquals('foo', $field
->getValue(), '->setValue() changes the selected option');
try {
$field
->setValue('foobar');
$this
->fail('->setValue() throws an \\InvalidArgumentException if the value is not one of the selected options');
} catch (\InvalidArgumentException $e) {
$this
->assertTrue(true, '->setValue() throws an \\InvalidArgumentException if the value is not one of the selected options');
}
try {
$field
->setValue(array(
'foobar',
));
$this
->fail('->setValue() throws an \\InvalidArgumentException if the value is an array');
} catch (\InvalidArgumentException $e) {
$this
->assertTrue(true, '->setValue() throws an \\InvalidArgumentException if the value is an array');
}
}