Skip to content

Commit

Permalink
[DomCrawler] Add test for ChoiceFormField without value
Browse files Browse the repository at this point in the history
  • Loading branch information
stealth35 committed Sep 20, 2011
1 parent bca551e commit cf736cc
Showing 1 changed file with 29 additions and 0 deletions.
Expand Up @@ -262,6 +262,14 @@ public function testSelect()
$this->assertEquals('foo', $field->getValue(), '->select() changes the selected option');
}

public function testOptionWithNoValue()
{
$node = $this->createSelectNodeWithEmptyOption(array('foo' => false, 'bar' => false));
$field = new ChoiceFormField($node);
$field->select('foo');
$this->assertEquals('foo', $field->getValue(), '->select() changes the selected option');
}

protected function createSelectNode($options, $attributes = array())
{
$document = new \DOMDocument();
Expand All @@ -283,4 +291,25 @@ protected function createSelectNode($options, $attributes = array())

return $node;
}

protected function createSelectNodeWithEmptyOption($options, $attributes = array())
{
$document = new \DOMDocument();
$node = $document->createElement('select');

foreach ($attributes as $name => $value) {
$node->setAttribute($name, $value);
}
$node->setAttribute('name', 'name');

foreach ($options as $value => $selected) {
$option = $document->createElement('option', $value);
if ($selected) {
$option->setAttribute('selected', 'selected');
}
$node->appendChild($option);
}

return $node;
}
}

0 comments on commit cf736cc

Please sign in to comment.