Fix Dom Crawler select option with empty value
This commit is contained in:
parent
192e821211
commit
58276a274e
@ -259,7 +259,8 @@ class ChoiceFormField extends FormField
|
|||||||
{
|
{
|
||||||
$option = array();
|
$option = array();
|
||||||
|
|
||||||
$defaultValue = (isset($node->nodeValue) && !empty($node->nodeValue)) ? $node->nodeValue : '1';
|
$defaultDefaultValue = 'select' === $this->node->nodeName ? '' : '1';
|
||||||
|
$defaultValue = (isset($node->nodeValue) && !empty($node->nodeValue)) ? $node->nodeValue : $defaultDefaultValue;
|
||||||
$option['value'] = $node->hasAttribute('value') ? $node->getAttribute('value') : $defaultValue;
|
$option['value'] = $node->hasAttribute('value') ? $node->getAttribute('value') : $defaultValue;
|
||||||
$option['disabled'] = $node->hasAttribute('disabled');
|
$option['disabled'] = $node->hasAttribute('disabled');
|
||||||
|
|
||||||
|
@ -336,6 +336,14 @@ class ChoiceFormFieldTest extends FormFieldTestCase
|
|||||||
$this->assertEquals('foo', $field->getValue(), '->select() changes the selected option');
|
$this->assertEquals('foo', $field->getValue(), '->select() changes the selected option');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testSelectWithEmptyValue()
|
||||||
|
{
|
||||||
|
$node = $this->createSelectNodeWithEmptyOption(array('' => true, 'Female' => false, 'Male' => false));
|
||||||
|
$field = new ChoiceFormField($node);
|
||||||
|
|
||||||
|
$this->assertSame('', $field->getValue());
|
||||||
|
}
|
||||||
|
|
||||||
protected function createSelectNode($options, $attributes = array(), $selectedAttrText = 'selected')
|
protected function createSelectNode($options, $attributes = array(), $selectedAttrText = 'selected')
|
||||||
{
|
{
|
||||||
$document = new \DOMDocument();
|
$document = new \DOMDocument();
|
||||||
|
Reference in New Issue
Block a user