Преглед на файлове

[Form] ChoiceField tests for numeric choices

Jeremy Mikola преди 15 години
родител
ревизия
e52cf7afe0
променени са 1 файла, в които са добавени 56 реда и са изтрити 0 реда
  1. 56 0
      tests/Symfony/Tests/Component/Form/ChoiceFieldTest.php

+ 56 - 0
tests/Symfony/Tests/Component/Form/ChoiceFieldTest.php

@@ -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(