|
@@ -28,6 +28,14 @@ class ChoiceFieldTest extends \PHPUnit_Framework_TestCase
|
|
|
)
|
|
|
);
|
|
|
|
|
|
+ protected $numericChoices = array(
|
|
|
+ 0 => 'Bernhard',
|
|
|
+ 1 => 'Fabien',
|
|
|
+ 2 => 'Kris',
|
|
|
+ 3 => 'Jon',
|
|
|
+ 4 => 'Roman',
|
|
|
+ );
|
|
|
+
|
|
|
public function testConfigureChoicesWithArrayObject()
|
|
|
{
|
|
|
$choices = new \ArrayObject($this->choices);
|
|
@@ -266,6 +274,30 @@ EOF;
|
|
|
$this->assertEquals('b', $field->getDisplayedData());
|
|
|
}
|
|
|
|
|
|
+ public function testBindSingleExpandedNumericChoices()
|
|
|
+ {
|
|
|
+ $field = new ChoiceField('name', array(
|
|
|
+ 'multiple' => false,
|
|
|
+ 'expanded' => true,
|
|
|
+ 'choices' => $this->numericChoices,
|
|
|
+ ));
|
|
|
+
|
|
|
+ $field->bind('1');
|
|
|
+
|
|
|
+ $this->assertSame(1, $field->getData());
|
|
|
+ $this->assertSame(null, $field[0]->getData());
|
|
|
+ $this->assertSame(true, $field[1]->getData());
|
|
|
+ $this->assertSame(null, $field[2]->getData());
|
|
|
+ $this->assertSame(null, $field[3]->getData());
|
|
|
+ $this->assertSame(null, $field[4]->getData());
|
|
|
+ $this->assertSame('', $field[0]->getDisplayedData());
|
|
|
+ $this->assertSame('1', $field[1]->getDisplayedData());
|
|
|
+ $this->assertSame('', $field[2]->getDisplayedData());
|
|
|
+ $this->assertSame('', $field[3]->getDisplayedData());
|
|
|
+ $this->assertSame('', $field[4]->getDisplayedData());
|
|
|
+ $this->assertSame(array(0 => '', 1 => '1', 2 => '', 3 => '', 4 => ''), $field->getDisplayedData());
|
|
|
+ }
|
|
|
+
|
|
|
public function testRenderSingleExpanded()
|
|
|
{
|
|
|
$field = new ChoiceField('name', array(
|
|
@@ -364,6 +396,30 @@ EOF;
|
|
|
$this->assertSame(array('a' => '1', 'b' => '1', 'c' => '', 'd' => '', 'e' => ''), $field->getDisplayedData());
|
|
|
}
|
|
|
|
|
|
+ public function testBindMultipleExpandedNumericChoices()
|
|
|
+ {
|
|
|
+ $field = new ChoiceField('name', array(
|
|
|
+ 'multiple' => true,
|
|
|
+ 'expanded' => true,
|
|
|
+ 'choices' => $this->numericChoices,
|
|
|
+ ));
|
|
|
+
|
|
|
+ $field->bind(array(1 => 1, 2 => 2));
|
|
|
+
|
|
|
+ $this->assertSame(array(1, 2), $field->getData());
|
|
|
+ $this->assertSame(null, $field[0]->getData());
|
|
|
+ $this->assertSame(true, $field[1]->getData());
|
|
|
+ $this->assertSame(true, $field[2]->getData());
|
|
|
+ $this->assertSame(null, $field[3]->getData());
|
|
|
+ $this->assertSame(null, $field[4]->getData());
|
|
|
+ $this->assertSame('', $field[0]->getDisplayedData());
|
|
|
+ $this->assertSame('1', $field[1]->getDisplayedData());
|
|
|
+ $this->assertSame('1', $field[2]->getDisplayedData());
|
|
|
+ $this->assertSame('', $field[3]->getDisplayedData());
|
|
|
+ $this->assertSame('', $field[4]->getDisplayedData());
|
|
|
+ $this->assertSame(array(0 => '', 1 => '1', 2 => '1', 3 => '', 4 => ''), $field->getDisplayedData());
|
|
|
+ }
|
|
|
+
|
|
|
public function testRenderMultipleExpanded()
|
|
|
{
|
|
|
$field = new ChoiceField('name', array(
|