Skip to content

Commit

Permalink
[Form] fixed radio and checkbox when data is not bool
Browse files Browse the repository at this point in the history
  • Loading branch information
kriswallsmith committed Nov 16, 2011
1 parent b55a438 commit 79ae3fc
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 2 deletions.
Expand Up @@ -37,7 +37,7 @@ public function buildView(FormView $view, FormInterface $form)
{
$view
->set('value', $form->getAttribute('value'))
->set('checked', (Boolean) $form->getData())
->set('checked', (Boolean) $form->getClientData())
;
}

Expand Down
Expand Up @@ -37,7 +37,7 @@ public function buildView(FormView $view, FormInterface $form)
{
$view
->set('value', $form->getAttribute('value'))
->set('checked', (Boolean) $form->getData())
->set('checked', (Boolean) $form->getClientData())
;

if ($view->hasParent()) {
Expand Down
Expand Up @@ -11,6 +11,8 @@

namespace Symfony\Tests\Component\Form\Extension\Core\Type;

use Symfony\Component\Form\CallbackTransformer;

class CheckboxTypeTest extends TypeTestCase
{
public function testPassValueToView()
Expand Down Expand Up @@ -38,4 +40,39 @@ public function testNotCheckedIfDataFalse()

$this->assertFalse($view->get('checked'));
}

/**
* @dataProvider proviceTransformedData
*/
public function testTransformedData($data, $expected)
{
// present a binary status field as a checkbox
$transformer = new CallbackTransformer(
function ($value)
{
return 'expedited' == $value;
},
function ($value)
{
return $value ? 'expedited' : 'standard';
}
);

$form = $this->builder
->create('expedited_shipping', 'checkbox')
->prependClientTransformer($transformer)
->getForm();
$form->setData($data);
$view = $form->createView();

$this->assertEquals($expected, $view->get('checked'));
}

public function proviceTransformedData()
{
return array(
array('expedited', true),
array('standard', false),
);
}
}

0 comments on commit 79ae3fc

Please sign in to comment.