Skip to content

Commit

Permalink
[Form] Turned Twig filters into tests
Browse files Browse the repository at this point in the history
  • Loading branch information
webmozart committed Jul 21, 2012
1 parent 310f985 commit 9216816
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 17 deletions.
14 changes: 11 additions & 3 deletions src/Symfony/Bridge/Twig/Extension/FormExtension.php
Expand Up @@ -80,8 +80,16 @@ public function getFilters()
{
return array(
'humanize' => new \Twig_Filter_Method($this, 'renderer->humanize'),
'is_choice_group' => new \Twig_Filter_Function('is_array', array('is_safe' => array('html'))),
'is_choice_selected' => new \Twig_Filter_Method($this, 'isChoiceSelected'),
);
}

/**
* {@inheritdoc}
*/
public function getTests()
{
return array(
'selectedchoice' => new \Twig_Test_Method($this, 'isSelectedChoice'),
);
}

Expand All @@ -108,7 +116,7 @@ public function getFilters()
*
* @see ChoiceView::isSelected()
*/
public function isChoiceSelected(ChoiceView $choice, $selectedValue)
public function isSelectedChoice(ChoiceView $choice, $selectedValue)
{
if (is_array($selectedValue)) {
return false !== array_search($choice->value, $selectedValue, true);
Expand Down
Expand Up @@ -87,13 +87,13 @@
{% block choice_widget_options %}
{% spaceless %}
{% for group_label, choice in options %}
{% if choice|is_choice_group %}
{% if choice is iterable %}
<optgroup label="{{ group_label|trans({}, translation_domain) }}">
{% set options = choice %}
{{ block('choice_widget_options') }}
</optgroup>
{% else %}
<option value="{{ choice.value }}"{% if choice|is_choice_selected(value) %} selected="selected"{% endif %}>{{ choice.label|trans({}, translation_domain) }}</option>
<option value="{{ choice.value }}"{% if choice is selectedchoice(value) %} selected="selected"{% endif %}>{{ choice.label|trans({}, translation_domain) }}</option>
{% endif %}
{% endfor %}
{% endspaceless %}
Expand Down
Expand Up @@ -106,7 +106,7 @@ public function testThemeBlockInheritanceUsingExtend()
);
}

public function isChoiceSelectedProvider()
public function isSelectedChoiceProvider()
{
// The commented cases should not be necessary anymore, because the
// choice lists should assure that both values passed here are always
Expand All @@ -130,13 +130,13 @@ public function isChoiceSelectedProvider()
}

/**
* @dataProvider isChoiceSelectedProvider
* @dataProvider isSelectedChoiceProvider
*/
public function testIsChoiceSelected($expected, $choice, $value)
{
$choice = new ChoiceView($choice, $choice . ' label');

$this->assertSame($expected, $this->extension->isChoiceSelected($choice, $value));
$this->assertSame($expected, $this->extension->isSelectedChoice($choice, $value));
}

protected function renderEnctype(FormView $view)
Expand Down
Expand Up @@ -49,11 +49,6 @@ public function getName()
return 'form';
}

public function isChoiceSelected(ChoiceView $choice, $selectedValue)
{
return $this->renderer->isChoiceSelected($choice, $selectedValue);
}

/**
* Sets a theme for a given view.
*
Expand Down
7 changes: 3 additions & 4 deletions src/Symfony/Component/Form/CHANGELOG.md
Expand Up @@ -113,10 +113,9 @@ CHANGELOG
* deprecated the methods `getDefaultOptions` and `getAllowedOptionValues`
in FormTypeInterface and FormTypeExtensionInterface
* options passed during construction can now be accessed from FormConfigInterface
* added FormBuilderInterface, FormView and FormConfigEditorInterface
* [BC BREAK] the methods in FormTypeInterface and FormTypeExtensionInterface now
receive FormBuilderInterface and FormView instead of FormBuilder and
FormView
* added FormBuilderInterface and FormConfigEditorInterface
* [BC BREAK] the method `buildForm` in FormTypeInterface and FormTypeExtensionInterface
now receives a FormBuilderInterface instead of a FormBuilder instance
* [BC BREAK] the method `buildViewBottomUp` was renamed to `finishView` in
FormTypeInterface and FormTypeExtensionInterface
* [BC BREAK] the options array is now passed as last argument of the
Expand Down

0 comments on commit 9216816

Please sign in to comment.