/** * @param string $expectedTranslationDomain * @param array $options * @param string|null $parentTranslationDomain * @param array $expectedChoices * @param array $inputChoices * * @dataProvider finishViewDataProvider */ public function testFinishView($expectedTranslationDomain, $options, $parentTranslationDomain = null, $expectedChoices = array(), $inputChoices = array()) { // expectations for translator if ($expectedChoices) { $prefix = self::TRANSLATION_PREFIX; $this->translator->expects($this->exactly(count($expectedChoices)))->method('trans')->with($this->isType('string'), array(), $expectedTranslationDomain)->will($this->returnCallback(function ($id) use($prefix) { return $prefix . $id; })); } else { $this->translator->expects($this->never())->method('trans'); } /** @var FormInterface $form */ $form = $this->getMockBuilder('Symfony\\Component\\Form\\Test\\FormInterface')->disableOriginalConstructor()->getMockForAbstractClass(); $filterFormView = $this->getFilterFormView($parentTranslationDomain, $inputChoices); $this->instance->finishView($filterFormView, $form, $options); // get list of actual translated choices /** @var FormView $valueFormView */ $valueFormView = $filterFormView->children['value']; $choiceViews = $valueFormView->vars['choices']; $actualChoices = array(); /** @var ChoiceView $choiceView */ foreach ($choiceViews as $choiceView) { $actualChoices[$choiceView->value] = $choiceView->label; } $this->assertEquals($expectedChoices, $actualChoices); }
/** * {@inheritDoc} */ public function finishView(FormView $view, FormInterface $form, array $options) { parent::finishView($view, $form, $options); if (isset($options['populate_default'])) { $view->vars['populate_default'] = $options['populate_default']; } }
/** * {@inheritDoc} */ public function finishView(FormView $view, FormInterface $form, array $options) { parent::finishView($view, $form, $options); if (isset($options['populate_default'])) { $view->vars['populate_default'] = $options['populate_default']; $view->vars['default_value'] = $options['default_value']; } if (!empty($options['null_value'])) { $view->vars['null_value'] = $options['null_value']; } if (!empty($options['class'])) { $view->vars['class'] = $options['class']; } }