Fix Dom Crawler select option with empty value

This commit is contained in:
Matt Wells 2016-04-06 11:37:55 +01:00
parent 192e821211
commit 58276a274e
2 changed files with 10 additions and 1 deletions

View File

@ -259,7 +259,8 @@ class ChoiceFormField extends FormField
{
$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['disabled'] = $node->hasAttribute('disabled');

View File

@ -336,6 +336,14 @@ class ChoiceFormFieldTest extends FormFieldTestCase
$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')
{
$document = new \DOMDocument();