merged 2.0

This commit is contained in:
Fabien Potencier 2011-09-21 20:14:11 +02:00
commit dd8e1e0fdb
3 changed files with 38 additions and 1 deletions

View File

@ -207,7 +207,7 @@ class ChoiceFormField extends FormField
$found = false;
foreach ($this->xpath->query('descendant::option', $this->node) as $option) {
$this->options[] = $option->getAttribute('value');
$this->options[] = $option->hasAttribute('value') ? $option->getAttribute('value') : $option->nodeValue;
if ($option->getAttribute('selected')) {
$found = true;

View File

@ -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;
}
}

View File

@ -89,6 +89,14 @@ class TranslatorTest extends \PHPUnit_Framework_TestCase
$this->assertEquals('bar (en)', $translator->trans('bar'));
}
public function testTransNonExistentWithFallback()
{
$translator = new Translator('fr', new MessageSelector());
$translator->setFallbackLocale('en');
$translator->addLoader('array', new ArrayLoader());
$this->assertEquals('non-existent', $translator->trans('non-existent'));
}
/**
* @expectedException RuntimeException
*/