Skip to content

Commit

Permalink
choice typeが機能していなかったので修正
Browse files Browse the repository at this point in the history
  • Loading branch information
chihiro-adachi committed Mar 14, 2017
1 parent 023ba39 commit a74de65
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/Eccube/Util/FormUtil.php
Expand Up @@ -44,7 +44,12 @@ public static function getViewData(FormInterface $form)
}

foreach ($forms as $key => $value) {
$viewData[$key] = self::getViewData($value);
// choice typeは各選択肢もFormとして扱われるため再帰しない.
if ($value->getConfig()->hasOption('choices')) {
$viewData[$key] = $value->getViewData();
} else {
$viewData[$key] = self::getViewData($value);
}
}

return $viewData;
Expand Down
54 changes: 54 additions & 0 deletions tests/Eccube/Tests/Util/FormUtilTest.php
Expand Up @@ -94,4 +94,58 @@ public function testNestedFormType()
$viewData = FormUtil::getViewData($form);
$this->assertEquals($formData, $viewData);
}

/**
* choice typeのテスト
*/
public function testChoiceType()
{
$formData = array(
'sex' => '1',
);

$form = $this->app['form.factory']
->createBuilder(
'form',
null,
array(
'csrf_protection' => false,
)
)
->add('sex', 'sex')
->getForm();

$form->submit($formData);
$viewData = FormUtil::getViewData($form);
$this->assertEquals($formData, $viewData);
}


/**
* choice type(multiple)のテスト
*/
public function testChoiceTypeMultiple()
{
$formData = array(
'sex' => array('1', '2')
);

$form = $this->app['form.factory']
->createBuilder(
'form',
null,
array(
'csrf_protection' => false,
)
)
->add('sex', 'sex', array(
'multiple' => true,
))
->getForm();

$form->submit($formData);
$viewData = FormUtil::getViewData($form);
$this->assertEquals($formData, $viewData);
}

}

0 comments on commit a74de65

Please sign in to comment.