|  | 
| 12 | 12 | namespace Symfony\Component\Form\Tests\Extension\Core\Type; | 
| 13 | 13 | 
 | 
| 14 | 14 | use Symfony\Component\Form\Form; | 
|  | 15 | +use Symfony\Component\Form\Tests\Fixtures\Author; | 
|  | 16 | +use Symfony\Component\Form\Tests\Fixtures\AuthorType; | 
| 15 | 17 | 
 | 
| 16 | 18 | class CollectionTypeTest extends \Symfony\Component\Form\Test\TypeTestCase | 
| 17 | 19 | { | 
| @@ -88,6 +90,78 @@ public function testResizedDownIfSubmittedWithMissingDataAndAllowDelete() | 
| 88 | 90 |         $this->assertEquals(array('foo@foo.com'), $form->getData()); | 
| 89 | 91 |     } | 
| 90 | 92 | 
 | 
|  | 93 | +    public function testResizedDownIfSubmittedWithEmptyDataAndDeleteEmpty() | 
|  | 94 | +    { | 
|  | 95 | +        $form = $this->factory->create('collection', null, array( | 
|  | 96 | +            'type' => 'text', | 
|  | 97 | +            'allow_delete' => true, | 
|  | 98 | +            'delete_empty' => true, | 
|  | 99 | +        )); | 
|  | 100 | + | 
|  | 101 | +        $form->setData(array('foo@foo.com', 'bar@bar.com')); | 
|  | 102 | +        $form->submit(array('foo@foo.com', '')); | 
|  | 103 | + | 
|  | 104 | +        $this->assertTrue($form->has('0')); | 
|  | 105 | +        $this->assertFalse($form->has('1')); | 
|  | 106 | +        $this->assertEquals('foo@foo.com', $form[0]->getData()); | 
|  | 107 | +        $this->assertEquals(array('foo@foo.com'), $form->getData()); | 
|  | 108 | +    } | 
|  | 109 | + | 
|  | 110 | +    public function testDontAddEmptyDataIfDeleteEmpty() | 
|  | 111 | +    { | 
|  | 112 | +        $form = $this->factory->create('collection', null, array( | 
|  | 113 | +            'type' => 'text', | 
|  | 114 | +            'allow_add' => true, | 
|  | 115 | +            'delete_empty' => true, | 
|  | 116 | +        )); | 
|  | 117 | + | 
|  | 118 | +        $form->setData(array('foo@foo.com')); | 
|  | 119 | +        $form->submit(array('foo@foo.com', '')); | 
|  | 120 | + | 
|  | 121 | +        $this->assertTrue($form->has('0')); | 
|  | 122 | +        $this->assertFalse($form->has('1')); | 
|  | 123 | +        $this->assertEquals('foo@foo.com', $form[0]->getData()); | 
|  | 124 | +        $this->assertEquals(array('foo@foo.com'), $form->getData()); | 
|  | 125 | +    } | 
|  | 126 | + | 
|  | 127 | +    public function testNoDeleteEmptyIfDeleteNotAllowed() | 
|  | 128 | +    { | 
|  | 129 | +        $form = $this->factory->create('collection', null, array( | 
|  | 130 | +            'type' => 'text', | 
|  | 131 | +            'allow_delete' => false, | 
|  | 132 | +            'delete_empty' => true, | 
|  | 133 | +        )); | 
|  | 134 | + | 
|  | 135 | +        $form->setData(array('foo@foo.com')); | 
|  | 136 | +        $form->submit(array('')); | 
|  | 137 | + | 
|  | 138 | +        $this->assertTrue($form->has('0')); | 
|  | 139 | +        $this->assertEquals('', $form[0]->getData()); | 
|  | 140 | +    } | 
|  | 141 | + | 
|  | 142 | +    public function testResizedDownIfSubmittedWithCompoundEmptyDataAndDeleteEmpty() | 
|  | 143 | +    { | 
|  | 144 | +        $form = $this->factory->create('collection', null, array( | 
|  | 145 | +            'type' => new AuthorType(), | 
|  | 146 | +            // If the field is not required, no new Author will be created if the | 
|  | 147 | +            // form is completely empty | 
|  | 148 | +            'options' => array('required' => false), | 
|  | 149 | +            'allow_add' => true, | 
|  | 150 | +            'delete_empty' => true, | 
|  | 151 | +        )); | 
|  | 152 | + | 
|  | 153 | +        $form->setData(array(new Author('first', 'last'))); | 
|  | 154 | +        $form->submit(array( | 
|  | 155 | +            array('firstName' => 's_first', 'lastName' => 's_last'), | 
|  | 156 | +            array('firstName' => '', 'lastName' => ''), | 
|  | 157 | +        )); | 
|  | 158 | + | 
|  | 159 | +        $this->assertTrue($form->has('0')); | 
|  | 160 | +        $this->assertFalse($form->has('1')); | 
|  | 161 | +        $this->assertEquals(new Author('s_first', 's_last'), $form[0]->getData()); | 
|  | 162 | +        $this->assertEquals(array(new Author('s_first', 's_last')), $form->getData()); | 
|  | 163 | +    } | 
|  | 164 | + | 
| 91 | 165 |     public function testNotResizedIfSubmittedWithExtraData() | 
| 92 | 166 |     { | 
| 93 | 167 |         $form = $this->factory->create('collection', null, array( | 
|  | 
0 commit comments