Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit aa5e45b

Browse files
committed
add tests for previous commit to avoid regressions
1 parent 0baa2e9 commit aa5e45b

File tree

2 files changed

+69
-0
lines changed

2 files changed

+69
-0
lines changed

src/Symfony/Component/Form/Tests/Extension/Core/Type/CheckboxTypeTest.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,4 +170,38 @@ public function provideCustomModelTransformerData()
170170
array('unchecked', false),
171171
);
172172
}
173+
174+
public function testSubmitNullWithEmptyDataTrueWhenNested()
175+
{
176+
$form = $this->factory->create('form')
177+
->add('agree', 'checkbox', array(
178+
'empty_data' => true,
179+
));
180+
181+
$form->submit(null);
182+
183+
$this->assertTrue($form->get('agree')->getData());
184+
$this->assertSame('1', $form->get('agree')->getViewData());
185+
186+
$view = $form->get('agree')->createView();
187+
188+
$this->assertTrue($view->vars['checked']);
189+
}
190+
191+
public function testSubmitNullWithEmptyDataFalseWhenNested()
192+
{
193+
$form = $this->factory->create('form')
194+
->add('agree', 'checkbox', array(
195+
'empty_data' => false,
196+
));
197+
198+
$form->submit(null);
199+
200+
$this->assertFalse($form->get('agree')->getData());
201+
$this->assertEmpty($form->get('agree')->getViewData());
202+
203+
$view = $form->get('agree')->createView();
204+
205+
$this->assertFalse($view->vars['checked']);
206+
}
173207
}

src/Symfony/Component/Form/Tests/Extension/Core/Type/IntegerTypeTest.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,39 @@ public function testSubmitCastsToInteger()
3232
$this->assertSame(1, $form->getData());
3333
$this->assertSame('1', $form->getViewData());
3434
}
35+
36+
public function testSubmitNull()
37+
{
38+
$form = $this->factory->create('integer');
39+
40+
$form->submit(null);
41+
42+
$this->assertNull($form->getData());
43+
$this->assertSame('', $form->getViewData());
44+
}
45+
46+
public function testSubmitNullWithEmptyData()
47+
{
48+
$form = $this->factory->create('integer', null, array(
49+
'empty_data' => 1,
50+
));
51+
52+
$form->submit(null);
53+
54+
$this->assertSame(1, $form->getData());
55+
$this->assertSame('1', $form->getViewData());
56+
}
57+
58+
public function testSubmitNullWithEmptyDataWhenNested()
59+
{
60+
$form = $this->factory->create('form')
61+
->add('age', 'integer', array(
62+
'empty_data' => 1,
63+
));
64+
65+
$form->submit(null);
66+
67+
$this->assertSame(1, $form->get('age')->getData());
68+
$this->assertSame('1', $form->get('age')->getViewData());
69+
}
3570
}

0 commit comments

Comments
 (0)