From cf736ccde38465dce8355c7ff2d9d69ef2deded6 Mon Sep 17 00:00:00 2001 From: stealth35 Date: Tue, 20 Sep 2011 18:30:35 +0200 Subject: [PATCH] [DomCrawler] Add test for ChoiceFormField without value --- .../DomCrawler/Field/ChoiceFormFieldTest.php | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/tests/Symfony/Tests/Component/DomCrawler/Field/ChoiceFormFieldTest.php b/tests/Symfony/Tests/Component/DomCrawler/Field/ChoiceFormFieldTest.php index 3864c815ab..928973bdef 100644 --- a/tests/Symfony/Tests/Component/DomCrawler/Field/ChoiceFormFieldTest.php +++ b/tests/Symfony/Tests/Component/DomCrawler/Field/ChoiceFormFieldTest.php @@ -262,6 +262,14 @@ class ChoiceFormFieldTest extends FormFieldTestCase $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(); @@ -283,4 +291,25 @@ class ChoiceFormFieldTest extends FormFieldTestCase 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; + } }