[Form] Added ChoiceView class for passing choice-related data to the view
This commit is contained in:
parent
d72900e613
commit
f533ef0e1b
@ -110,22 +110,6 @@ class EntityChoiceList extends ObjectChoiceList
|
|||||||
return parent::getChoices();
|
return parent::getChoices();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the labels for the entities
|
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*
|
|
||||||
* @see Symfony\Component\Form\Extension\Core\ChoiceList\ChoiceListInterface
|
|
||||||
*/
|
|
||||||
public function getLabels()
|
|
||||||
{
|
|
||||||
if (!$this->loaded) {
|
|
||||||
$this->load();
|
|
||||||
}
|
|
||||||
|
|
||||||
return parent::getLabels();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the values for the entities
|
* Returns the values for the entities
|
||||||
*
|
*
|
||||||
@ -143,70 +127,37 @@ class EntityChoiceList extends ObjectChoiceList
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the values of the entities that should be presented to the user
|
* Returns the choice views of the preferred choices as nested array with
|
||||||
* with priority.
|
* the choice groups as top-level keys.
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*
|
*
|
||||||
* @see Symfony\Component\Form\Extension\Core\ChoiceList\ChoiceListInterface
|
* @see Symfony\Component\Form\Extension\Core\ChoiceList\ChoiceListInterface
|
||||||
*/
|
*/
|
||||||
public function getPreferredValues()
|
public function getPreferredViews()
|
||||||
{
|
{
|
||||||
if (!$this->loaded) {
|
if (!$this->loaded) {
|
||||||
$this->load();
|
$this->load();
|
||||||
}
|
}
|
||||||
|
|
||||||
return parent::getPreferredValues();
|
return parent::getPreferredViews();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the values of the entities that should be presented to the user
|
* Returns the choice views of the choices that are not preferred as nested
|
||||||
* with priority as nested array with the choice groups as top-level keys.
|
* array with the choice groups as top-level keys.
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*
|
*
|
||||||
* @see Symfony\Component\Form\Extension\Core\ChoiceList\ChoiceListInterface
|
* @see Symfony\Component\Form\Extension\Core\ChoiceList\ChoiceListInterface
|
||||||
*/
|
*/
|
||||||
public function getPreferredValueHierarchy()
|
public function getRemainingViews()
|
||||||
{
|
{
|
||||||
if (!$this->loaded) {
|
if (!$this->loaded) {
|
||||||
$this->load();
|
$this->load();
|
||||||
}
|
}
|
||||||
|
|
||||||
return parent::getPreferredValueHierarchy();
|
return parent::getRemainingViews();
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the values of the entities that are not preferred.
|
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*
|
|
||||||
* @see Symfony\Component\Form\Extension\Core\ChoiceList\ChoiceListInterface
|
|
||||||
*/
|
|
||||||
public function getRemainingValues()
|
|
||||||
{
|
|
||||||
if (!$this->loaded) {
|
|
||||||
$this->load();
|
|
||||||
}
|
|
||||||
|
|
||||||
return parent::getRemainingValues();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the values of the entities that are not preferred as nested array
|
|
||||||
* with the choice groups as top-level keys.
|
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*
|
|
||||||
* @see Symfony\Component\Form\Extension\Core\ChoiceList\ChoiceListInterface
|
|
||||||
*/
|
|
||||||
public function getRemainingValueHierarchy()
|
|
||||||
{
|
|
||||||
if (!$this->loaded) {
|
|
||||||
$this->load();
|
|
||||||
}
|
|
||||||
|
|
||||||
return parent::getRemainingValueHierarchy();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -15,6 +15,7 @@ use Symfony\Bridge\Twig\TokenParser\FormThemeTokenParser;
|
|||||||
use Symfony\Component\Form\FormView;
|
use Symfony\Component\Form\FormView;
|
||||||
use Symfony\Component\Form\Exception\FormException;
|
use Symfony\Component\Form\Exception\FormException;
|
||||||
use Symfony\Component\Form\Extension\Csrf\CsrfProvider\CsrfProviderInterface;
|
use Symfony\Component\Form\Extension\Csrf\CsrfProvider\CsrfProviderInterface;
|
||||||
|
use Symfony\Component\Form\Extension\Core\View\ChoiceView;
|
||||||
use Symfony\Component\Form\Util\FormUtil;
|
use Symfony\Component\Form\Util\FormUtil;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -95,9 +96,9 @@ class FormExtension extends \Twig_Extension
|
|||||||
return FormUtil::isChoiceGroup($label);
|
return FormUtil::isChoiceGroup($label);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function isChoiceSelected(FormView $view, $choice)
|
public function isChoiceSelected(FormView $view, ChoiceView $choice)
|
||||||
{
|
{
|
||||||
return FormUtil::isChoiceSelected($choice, $view->get('value'));
|
return FormUtil::isChoiceSelected($choice->getValue(), $view->get('value'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -29,12 +29,12 @@
|
|||||||
{% for index, choice in options %}
|
{% for index, choice in options %}
|
||||||
{% if _form_is_choice_group(choice) %}
|
{% if _form_is_choice_group(choice) %}
|
||||||
<optgroup label="{{ index|trans({}, translation_domain) }}">
|
<optgroup label="{{ index|trans({}, translation_domain) }}">
|
||||||
{% for nested_index, nested_choice in choice %}
|
{% for nested_choice in choice %}
|
||||||
<option value="{{ nested_choice }}"{% if _form_is_choice_selected(form, nested_choice) %} selected="selected"{% endif %}>{{ choice_labels[nested_index]|trans({}, translation_domain) }}</option>
|
<option value="{{ nested_choice.value }}"{% if _form_is_choice_selected(form, nested_choice) %} selected="selected"{% endif %}>{{ nested_choice.label|trans({}, translation_domain) }}</option>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</optgroup>
|
</optgroup>
|
||||||
{% else %}
|
{% else %}
|
||||||
<option value="{{ choice }}"{% if _form_is_choice_selected(form, choice) %} selected="selected"{% endif %}>{{ choice_labels[index]|trans({}, translation_domain) }}</option>
|
<option value="{{ choice.value }}"{% if _form_is_choice_selected(form, choice) %} selected="selected"{% endif %}>{{ choice.label|trans({}, translation_domain) }}</option>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% endspaceless %}
|
{% endspaceless %}
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
<?php foreach ($options as $index => $choice): ?>
|
<?php foreach ($options as $index => $choice): ?>
|
||||||
<?php if ($view['form']->isChoiceGroup($choice)): ?>
|
<?php if ($view['form']->isChoiceGroup($choice)): ?>
|
||||||
<optgroup label="<?php echo $view->escape($view['translator']->trans($index, array(), $translation_domain)) ?>">
|
<optgroup label="<?php echo $view->escape($view['translator']->trans($index, array(), $translation_domain)) ?>">
|
||||||
<?php foreach ($choice as $nested_index => $nested_choice): ?>
|
<?php foreach ($choice as $nested_choice): ?>
|
||||||
<option value="<?php echo $view->escape($nested_choice) ?>"<?php if ($view['form']->isChoiceSelected($form, $nested_choice)): ?> selected="selected"<?php endif?>><?php echo $view->escape($view['translator']->trans($choice_labels[$nested_index], array(), $translation_domain)) ?></option>
|
<option value="<?php echo $view->escape($nested_choice->getValue()) ?>"<?php if ($view['form']->isChoiceSelected($form, $nested_choice)): ?> selected="selected"<?php endif?>><?php echo $view->escape($view['translator']->trans($nested_choice->getLabel(), array(), $translation_domain)) ?></option>
|
||||||
<?php endforeach ?>
|
<?php endforeach ?>
|
||||||
</optgroup>
|
</optgroup>
|
||||||
<?php else: ?>
|
<?php else: ?>
|
||||||
<option value="<?php echo $view->escape($choice) ?>"<?php if ($view['form']->isChoiceSelected($form, $choice)): ?> selected="selected"<?php endif?>><?php echo $view->escape($view['translator']->trans($choice_labels[$index], array(), $translation_domain)) ?></option>
|
<option value="<?php echo $view->escape($choice->getValue()) ?>"<?php if ($view['form']->isChoiceSelected($form, $choice)): ?> selected="selected"<?php endif?>><?php echo $view->escape($view['translator']->trans($choice->getLabel(), array(), $translation_domain)) ?></option>
|
||||||
<?php endif ?>
|
<?php endif ?>
|
||||||
<?php endforeach ?>
|
<?php endforeach ?>
|
||||||
|
@ -16,6 +16,7 @@ use Symfony\Component\Templating\EngineInterface;
|
|||||||
use Symfony\Component\Form\FormView;
|
use Symfony\Component\Form\FormView;
|
||||||
use Symfony\Component\Form\Exception\FormException;
|
use Symfony\Component\Form\Exception\FormException;
|
||||||
use Symfony\Component\Form\Extension\Csrf\CsrfProvider\CsrfProviderInterface;
|
use Symfony\Component\Form\Extension\Csrf\CsrfProvider\CsrfProviderInterface;
|
||||||
|
use Symfony\Component\Form\Extension\Core\View\ChoiceView;
|
||||||
use Symfony\Component\Form\Util\FormUtil;
|
use Symfony\Component\Form\Util\FormUtil;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -63,9 +64,9 @@ class FormHelper extends Helper
|
|||||||
return FormUtil::isChoiceGroup($label);
|
return FormUtil::isChoiceGroup($label);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function isChoiceSelected(FormView $view, $choice)
|
public function isChoiceSelected(FormView $view, ChoiceView $choice)
|
||||||
{
|
{
|
||||||
return FormUtil::isChoiceSelected($choice, $view->get('value'));
|
return FormUtil::isChoiceSelected($choice->getValue(), $view->get('value'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -13,6 +13,7 @@ namespace Symfony\Component\Form\Extension\Core\ChoiceList;
|
|||||||
|
|
||||||
use Symfony\Component\Form\Util\FormUtil;
|
use Symfony\Component\Form\Util\FormUtil;
|
||||||
use Symfony\Component\Form\Exception\UnexpectedTypeException;
|
use Symfony\Component\Form\Exception\UnexpectedTypeException;
|
||||||
|
use Symfony\Component\Form\Extension\Core\View\ChoiceView;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Base class for choice list implementations.
|
* Base class for choice list implementations.
|
||||||
@ -59,43 +60,20 @@ class ChoiceList implements ChoiceListInterface
|
|||||||
private $values = array();
|
private $values = array();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The choice labels with the indices of the matching choices as keys.
|
* The preferred view objects as hierarchy containing also the choice groups
|
||||||
*
|
|
||||||
* @var array
|
|
||||||
*/
|
|
||||||
private $labels = array();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The preferred values as flat array with the indices of the matching
|
|
||||||
* choices as keys.
|
|
||||||
*
|
|
||||||
* @var array
|
|
||||||
*/
|
|
||||||
private $preferredValues = array();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The non-preferred values as flat array with the indices of the matching
|
|
||||||
* choices as keys.
|
|
||||||
*
|
|
||||||
* @var array
|
|
||||||
*/
|
|
||||||
private $remainingValues = array();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The preferred values as hierarchy containing also the choice groups
|
|
||||||
* with the indices of the matching choices as bottom-level keys.
|
* with the indices of the matching choices as bottom-level keys.
|
||||||
*
|
*
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
private $preferredValueHierarchy = array();
|
private $preferredViews = array();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The non-preferred values as hierarchy containing also the choice groups
|
* The non-preferred view objects as hierarchy containing also the choice
|
||||||
* with the indices of the matching choices as bottom-level keys.
|
* groups with the indices of the matching choices as bottom-level keys.
|
||||||
*
|
*
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
private $remainingValueHierarchy = array();
|
private $remainingViews = array();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The strategy used for creating choice indices.
|
* The strategy used for creating choice indices.
|
||||||
@ -153,15 +131,12 @@ class ChoiceList implements ChoiceListInterface
|
|||||||
{
|
{
|
||||||
$this->choices = array();
|
$this->choices = array();
|
||||||
$this->values = array();
|
$this->values = array();
|
||||||
$this->labels = array();
|
$this->preferredViews = array();
|
||||||
$this->preferredValues = array();
|
$this->remainingViews = array();
|
||||||
$this->preferredValueHierarchy = array();
|
|
||||||
$this->remainingValues = array();
|
|
||||||
$this->remainingValueHierarchy = array();
|
|
||||||
|
|
||||||
$this->addChoices(
|
$this->addChoices(
|
||||||
$this->preferredValueHierarchy,
|
$this->preferredViews,
|
||||||
$this->remainingValueHierarchy,
|
$this->remainingViews,
|
||||||
$choices,
|
$choices,
|
||||||
$labels,
|
$labels,
|
||||||
$preferredChoices
|
$preferredChoices
|
||||||
@ -180,18 +155,6 @@ class ChoiceList implements ChoiceListInterface
|
|||||||
return $this->choices;
|
return $this->choices;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the labels for the choices
|
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*
|
|
||||||
* @see Symfony\Component\Form\Extension\Core\ChoiceList\ChoiceListInterface
|
|
||||||
*/
|
|
||||||
public function getLabels()
|
|
||||||
{
|
|
||||||
return $this->labels;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the values for the choices
|
* Returns the values for the choices
|
||||||
*
|
*
|
||||||
@ -205,56 +168,29 @@ class ChoiceList implements ChoiceListInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the values of the choices that should be presented to the user
|
* Returns the choice views of the preferred choices as nested array with
|
||||||
* with priority.
|
* the choice groups as top-level keys.
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*
|
*
|
||||||
* @see Symfony\Component\Form\Extension\Core\ChoiceList\ChoiceListInterface
|
* @see Symfony\Component\Form\Extension\Core\ChoiceList\ChoiceListInterface
|
||||||
*/
|
*/
|
||||||
public function getPreferredValues()
|
public function getPreferredViews()
|
||||||
{
|
{
|
||||||
return $this->preferredValues;
|
return $this->preferredViews;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the values of the choices that should be presented to the user
|
* Returns the choice views of the choices that are not preferred as nested
|
||||||
* with priority as nested array with the choice groups as top-level keys.
|
* array with the choice groups as top-level keys.
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*
|
*
|
||||||
* @see Symfony\Component\Form\Extension\Core\ChoiceList\ChoiceListInterface
|
* @see Symfony\Component\Form\Extension\Core\ChoiceList\ChoiceListInterface
|
||||||
*/
|
*/
|
||||||
public function getPreferredValueHierarchy()
|
public function getRemainingViews()
|
||||||
{
|
{
|
||||||
return $this->preferredValueHierarchy;
|
return $this->remainingViews;
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the values of the choices that are not preferred.
|
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*
|
|
||||||
* @see Symfony\Component\Form\Extension\Core\ChoiceList\ChoiceListInterface
|
|
||||||
*/
|
|
||||||
public function getRemainingValues()
|
|
||||||
{
|
|
||||||
return $this->remainingValues;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the values of the choices that are not preferred as nested array
|
|
||||||
* with the choice groups as top-level keys.
|
|
||||||
*
|
|
||||||
* @return array A nested array containing the values with the corresponding
|
|
||||||
* choice indices as keys on the lower levels and the choice
|
|
||||||
* group names in the keys of the topmost level.
|
|
||||||
*
|
|
||||||
* @see getPreferredValueHierarchy
|
|
||||||
*/
|
|
||||||
public function getRemainingValueHierarchy()
|
|
||||||
{
|
|
||||||
return $this->remainingValueHierarchy;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -395,9 +331,9 @@ class ChoiceList implements ChoiceListInterface
|
|||||||
* Recursively adds the given choices to the list.
|
* Recursively adds the given choices to the list.
|
||||||
*
|
*
|
||||||
* @param array $bucketForPreferred The bucket where to store the preferred
|
* @param array $bucketForPreferred The bucket where to store the preferred
|
||||||
* values.
|
* view objects.
|
||||||
* @param array $bucketForRemaining The bucket where to store the
|
* @param array $bucketForRemaining The bucket where to store the
|
||||||
* non-preferred values.
|
* non-preferred view objects.
|
||||||
* @param array $choices The list of choices.
|
* @param array $choices The list of choices.
|
||||||
* @param array $labels The labels corresponding to the choices.
|
* @param array $labels The labels corresponding to the choices.
|
||||||
* @param array $preferredChoices The preferred choices.
|
* @param array $preferredChoices The preferred choices.
|
||||||
@ -447,9 +383,9 @@ class ChoiceList implements ChoiceListInterface
|
|||||||
*
|
*
|
||||||
* @param string $group The name of the group.
|
* @param string $group The name of the group.
|
||||||
* @param array $bucketForPreferred The bucket where to store the preferred
|
* @param array $bucketForPreferred The bucket where to store the preferred
|
||||||
* values.
|
* view objects.
|
||||||
* @param array $bucketForRemaining The bucket where to store the
|
* @param array $bucketForRemaining The bucket where to store the
|
||||||
* non-preferred values.
|
* non-preferred view objects.
|
||||||
* @param array $choices The list of choices in the group.
|
* @param array $choices The list of choices in the group.
|
||||||
* @param array $labels The labels corresponding to the choices in the group.
|
* @param array $labels The labels corresponding to the choices in the group.
|
||||||
* @param array $preferredChoices The preferred choices.
|
* @param array $preferredChoices The preferred choices.
|
||||||
@ -482,9 +418,9 @@ class ChoiceList implements ChoiceListInterface
|
|||||||
* Adds a new choice.
|
* Adds a new choice.
|
||||||
*
|
*
|
||||||
* @param array $bucketForPreferred The bucket where to store the preferred
|
* @param array $bucketForPreferred The bucket where to store the preferred
|
||||||
* values.
|
* view objects.
|
||||||
* @param array $bucketForRemaining The bucket where to store the
|
* @param array $bucketForRemaining The bucket where to store the
|
||||||
* non-preferred values.
|
* non-preferred view objects.
|
||||||
* @param mixed $choice The choice to add.
|
* @param mixed $choice The choice to add.
|
||||||
* @param string $label The label for the choice.
|
* @param string $label The label for the choice.
|
||||||
* @param array $preferredChoices The preferred choices.
|
* @param array $preferredChoices The preferred choices.
|
||||||
@ -495,17 +431,15 @@ class ChoiceList implements ChoiceListInterface
|
|||||||
|
|
||||||
// Always store values as strings to facilitate comparisons
|
// Always store values as strings to facilitate comparisons
|
||||||
$value = $this->fixValue($this->createValue($choice));
|
$value = $this->fixValue($this->createValue($choice));
|
||||||
|
$view = new ChoiceView($value, $label);
|
||||||
|
|
||||||
$this->choices[$index] = $this->fixChoice($choice);
|
$this->choices[$index] = $this->fixChoice($choice);
|
||||||
$this->labels[$index] = $label;
|
|
||||||
$this->values[$index] = $value;
|
$this->values[$index] = $value;
|
||||||
|
|
||||||
if ($this->isPreferred($choice, $preferredChoices)) {
|
if ($this->isPreferred($choice, $preferredChoices)) {
|
||||||
$bucketForPreferred[$index] = $value;
|
$bucketForPreferred[$index] = $view;
|
||||||
$this->preferredValues[$index] = $value;
|
|
||||||
} else {
|
} else {
|
||||||
$bucketForRemaining[$index] = $value;
|
$bucketForRemaining[$index] = $view;
|
||||||
$this->remainingValues[$index] = $value;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -40,13 +40,6 @@ interface ChoiceListInterface
|
|||||||
*/
|
*/
|
||||||
function getChoices();
|
function getChoices();
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the labels for the choices
|
|
||||||
*
|
|
||||||
* @return array The labels with the corresponding choice indices as keys.
|
|
||||||
*/
|
|
||||||
function getLabels();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the values for the choices
|
* Returns the values for the choices
|
||||||
*
|
*
|
||||||
@ -55,43 +48,26 @@ interface ChoiceListInterface
|
|||||||
function getValues();
|
function getValues();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the values of the choices that should be presented to the user
|
* Returns the choice views of the preferred choices as nested array with
|
||||||
* with priority.
|
* the choice groups as top-level keys.
|
||||||
*
|
*
|
||||||
* @return array The values with the corresponding choice indices as keys.
|
* @return array A nested array containing the views with the corresponding
|
||||||
|
* choice indices as keys on the lowest levels and the choice
|
||||||
|
* group names in the keys of the higher levels.
|
||||||
*/
|
*/
|
||||||
function getPreferredValues();
|
function getPreferredViews();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the values of the choices that should be presented to the user
|
* Returns the choice views of the choices that are not preferred as nested
|
||||||
* with priority as nested array with the choice groups as top-level keys.
|
* array with the choice groups as top-level keys.
|
||||||
*
|
*
|
||||||
* @return array A nested array containing the values with the corresponding
|
* @return array A nested array containing the views with the corresponding
|
||||||
* choice indices as keys on the lower levels and the choice
|
* choice indices as keys on the lowest levels and the choice
|
||||||
* group names in the keys of the topmost level.
|
* group names in the keys of the higher levels.
|
||||||
*/
|
|
||||||
function getPreferredValueHierarchy();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the values of the choices that are not preferred.
|
|
||||||
*
|
|
||||||
* @return array The values with the corresponding choice indices as keys.
|
|
||||||
*
|
*
|
||||||
* @see getPreferredValues
|
* @see getPreferredValues
|
||||||
*/
|
*/
|
||||||
function getRemainingValues();
|
function getRemainingViews();
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the values of the choices that are not preferred as nested array
|
|
||||||
* with the choice groups as top-level keys.
|
|
||||||
*
|
|
||||||
* @return array A nested array containing the values with the corresponding
|
|
||||||
* choice indices as keys on the lower levels and the choice
|
|
||||||
* group names in the keys of the topmost level.
|
|
||||||
*
|
|
||||||
* @see getPreferredValueHierarchy
|
|
||||||
*/
|
|
||||||
function getRemainingValueHierarchy();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the choices corresponding to the given values.
|
* Returns the choices corresponding to the given values.
|
||||||
|
@ -52,28 +52,8 @@ class ChoiceType extends AbstractType
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($options['expanded']) {
|
if ($options['expanded']) {
|
||||||
// Load choices already if expanded
|
$this->addSubFields($builder, $options['choice_list']->getPreferredViews(), $options);
|
||||||
$values = $options['choice_list']->getValues();
|
$this->addSubFields($builder, $options['choice_list']->getRemainingViews(), $options);
|
||||||
$labels = $options['choice_list']->getLabels();
|
|
||||||
|
|
||||||
foreach ($values as $i => $value) {
|
|
||||||
if ($options['multiple']) {
|
|
||||||
$builder->add((string) $i, 'checkbox', array(
|
|
||||||
'value' => $value,
|
|
||||||
'label' => $labels[$i],
|
|
||||||
// The user can check 0 or more checkboxes. If required
|
|
||||||
// is true, he is required to check all of them.
|
|
||||||
'required' => false,
|
|
||||||
'translation_domain' => $options['translation_domain'],
|
|
||||||
));
|
|
||||||
} else {
|
|
||||||
$builder->add((string) $i, 'radio', array(
|
|
||||||
'value' => $value,
|
|
||||||
'label' => $labels[$i],
|
|
||||||
'translation_domain' => $options['translation_domain'],
|
|
||||||
));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// empty value
|
// empty value
|
||||||
@ -129,9 +109,8 @@ class ChoiceType extends AbstractType
|
|||||||
$view
|
$view
|
||||||
->set('multiple', $form->getAttribute('multiple'))
|
->set('multiple', $form->getAttribute('multiple'))
|
||||||
->set('expanded', $form->getAttribute('expanded'))
|
->set('expanded', $form->getAttribute('expanded'))
|
||||||
->set('preferred_choices', $choiceList->getPreferredValueHierarchy())
|
->set('preferred_choices', $choiceList->getPreferredViews())
|
||||||
->set('choices', $choiceList->getRemainingValueHierarchy())
|
->set('choices', $choiceList->getRemainingViews())
|
||||||
->set('choice_labels', $choiceList->getLabels())
|
|
||||||
->set('separator', '-------------------')
|
->set('separator', '-------------------')
|
||||||
->set('empty_value', $form->getAttribute('empty_value'))
|
->set('empty_value', $form->getAttribute('empty_value'))
|
||||||
;
|
;
|
||||||
@ -181,4 +160,36 @@ class ChoiceType extends AbstractType
|
|||||||
{
|
{
|
||||||
return 'choice';
|
return 'choice';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds the sub fields for an expanded choice field.
|
||||||
|
*
|
||||||
|
* @param FormBuilder $builder The form builder.
|
||||||
|
* @param array $choiceViews The choice view objects.
|
||||||
|
* @param array $options The build options.
|
||||||
|
*/
|
||||||
|
private function addSubFields(FormBuilder $builder, array $choiceViews, array $options)
|
||||||
|
{
|
||||||
|
foreach ($choiceViews as $i => $choiceView) {
|
||||||
|
if (is_array($choiceView)) {
|
||||||
|
// Flatten groups
|
||||||
|
$this->addSubFields($builder, $choiceView, $options);
|
||||||
|
} elseif ($options['multiple']) {
|
||||||
|
$builder->add((string) $i, 'checkbox', array(
|
||||||
|
'value' => $choiceView->getValue(),
|
||||||
|
'label' => $choiceView->getLabel(),
|
||||||
|
// The user can check 0 or more checkboxes. If required
|
||||||
|
// is true, he is required to check all of them.
|
||||||
|
'required' => false,
|
||||||
|
'translation_domain' => $options['translation_domain'],
|
||||||
|
));
|
||||||
|
} else {
|
||||||
|
$builder->add((string) $i, 'radio', array(
|
||||||
|
'value' => $choiceView->getValue(),
|
||||||
|
'label' => $choiceView->getLabel(),
|
||||||
|
'translation_domain' => $options['translation_domain'],
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,66 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of the Symfony package.
|
||||||
|
*
|
||||||
|
* (c) Fabien Potencier <fabien@symfony.com>
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Symfony\Component\Form\Extension\Core\View;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents a choice in templates.
|
||||||
|
*
|
||||||
|
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||||
|
*/
|
||||||
|
class ChoiceView
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The view representation of the choice.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
private $value;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The label displayed to humans.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
private $label;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new ChoiceView.
|
||||||
|
*
|
||||||
|
* @param string $value The view representation of the choice.
|
||||||
|
* @param string $label The label displayed to humans.
|
||||||
|
*/
|
||||||
|
public function __construct($value, $label)
|
||||||
|
{
|
||||||
|
$this->value = $value;
|
||||||
|
$this->label = $label;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the choice value.
|
||||||
|
*
|
||||||
|
* @return string The view representation of the choice.
|
||||||
|
*/
|
||||||
|
public function getValue()
|
||||||
|
{
|
||||||
|
return $this->value;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the choice label.
|
||||||
|
*
|
||||||
|
* @return string The label displayed to humans.
|
||||||
|
*/
|
||||||
|
public function getLabel()
|
||||||
|
{
|
||||||
|
return $this->label;
|
||||||
|
}
|
||||||
|
}
|
@ -19,6 +19,7 @@ use Symfony\Tests\Bridge\Doctrine\DoctrineOrmTestCase;
|
|||||||
use Symfony\Tests\Bridge\Doctrine\Fixtures\ItemGroupEntity;
|
use Symfony\Tests\Bridge\Doctrine\Fixtures\ItemGroupEntity;
|
||||||
use Symfony\Tests\Bridge\Doctrine\Fixtures\SingleIdentEntity;
|
use Symfony\Tests\Bridge\Doctrine\Fixtures\SingleIdentEntity;
|
||||||
use Symfony\Bridge\Doctrine\Form\ChoiceList\EntityChoiceList;
|
use Symfony\Bridge\Doctrine\Form\ChoiceList\EntityChoiceList;
|
||||||
|
use Symfony\Component\Form\Extension\Core\View\ChoiceView;
|
||||||
|
|
||||||
class EntityChoiceListTest extends DoctrineOrmTestCase
|
class EntityChoiceListTest extends DoctrineOrmTestCase
|
||||||
{
|
{
|
||||||
@ -133,10 +134,10 @@ class EntityChoiceListTest extends DoctrineOrmTestCase
|
|||||||
);
|
);
|
||||||
|
|
||||||
$this->assertSame(array(1 => $entity1, 2 => $entity2), $choiceList->getChoices());
|
$this->assertSame(array(1 => $entity1, 2 => $entity2), $choiceList->getChoices());
|
||||||
$this->assertSame(array(
|
$this->assertEquals(array(
|
||||||
'group1' => array(1 => '1'),
|
'group1' => array(1 => new ChoiceView('1', 'Foo')),
|
||||||
'group2' => array(2 => '2')
|
'group2' => array(2 => new ChoiceView('2', 'Bar'))
|
||||||
), $choiceList->getRemainingValueHierarchy());
|
), $choiceList->getRemainingViews());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGroupBySupportsString()
|
public function testGroupBySupportsString()
|
||||||
@ -167,10 +168,10 @@ class EntityChoiceListTest extends DoctrineOrmTestCase
|
|||||||
|
|
||||||
$this->assertEquals(array(1 => $item1, 2 => $item2, 3 => $item3, 4 => $item4), $choiceList->getChoices());
|
$this->assertEquals(array(1 => $item1, 2 => $item2, 3 => $item3, 4 => $item4), $choiceList->getChoices());
|
||||||
$this->assertEquals(array(
|
$this->assertEquals(array(
|
||||||
'Group1' => array(1 => '1', 2 => '2'),
|
'Group1' => array(1 => new ChoiceView('1', 'Foo'), 2 => new ChoiceView('2', 'Bar')),
|
||||||
'Group2' => array(3 => '3'),
|
'Group2' => array(3 => new ChoiceView('3', 'Baz')),
|
||||||
4 => '4'
|
4 => new ChoiceView('4', 'Boo!')
|
||||||
), $choiceList->getRemainingValueHierarchy());
|
), $choiceList->getRemainingViews());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGroupByInvalidPropertyPathReturnsFlatChoices()
|
public function testGroupByInvalidPropertyPathReturnsFlatChoices()
|
||||||
|
@ -29,6 +29,7 @@ use Symfony\Tests\Bridge\Doctrine\Fixtures\CompositeStringIdentEntity;
|
|||||||
use Symfony\Bridge\Doctrine\Form\DoctrineOrmExtension;
|
use Symfony\Bridge\Doctrine\Form\DoctrineOrmExtension;
|
||||||
use Doctrine\ORM\Tools\SchemaTool;
|
use Doctrine\ORM\Tools\SchemaTool;
|
||||||
use Doctrine\Common\Collections\ArrayCollection;
|
use Doctrine\Common\Collections\ArrayCollection;
|
||||||
|
use Symfony\Component\Form\Extension\Core\View\ChoiceView;
|
||||||
|
|
||||||
class EntityTypeTest extends TypeTestCase
|
class EntityTypeTest extends TypeTestCase
|
||||||
{
|
{
|
||||||
@ -109,8 +110,7 @@ class EntityTypeTest extends TypeTestCase
|
|||||||
'property' => 'name'
|
'property' => 'name'
|
||||||
));
|
));
|
||||||
|
|
||||||
$this->assertSame(array(1 => '1', 2 => '2'), $field->createView()->get('choices'));
|
$this->assertEquals(array(1 => new ChoiceView('1', 'Foo'), 2 => new ChoiceView('2', 'Bar')), $field->createView()->get('choices'));
|
||||||
$this->assertSame(array(1 => 'Foo', 2 => 'Bar'), $field->createView()->get('choice_labels'));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSetDataToUninitializedEntityWithNonRequiredToString()
|
public function testSetDataToUninitializedEntityWithNonRequiredToString()
|
||||||
@ -126,8 +126,7 @@ class EntityTypeTest extends TypeTestCase
|
|||||||
'required' => false,
|
'required' => false,
|
||||||
));
|
));
|
||||||
|
|
||||||
$this->assertSame(array(1 => '1', 2 => '2'), $field->createView()->get('choices'));
|
$this->assertEquals(array(1 => new ChoiceView('1', 'Foo'), 2 => new ChoiceView('2', 'Bar')), $field->createView()->get('choices'));
|
||||||
$this->assertSame(array(1 => 'Foo', 2 => 'Bar'), $field->createView()->get('choice_labels'));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSetDataToUninitializedEntityWithNonRequiredQueryBuilder()
|
public function testSetDataToUninitializedEntityWithNonRequiredQueryBuilder()
|
||||||
@ -146,8 +145,7 @@ class EntityTypeTest extends TypeTestCase
|
|||||||
'query_builder' => $qb
|
'query_builder' => $qb
|
||||||
));
|
));
|
||||||
|
|
||||||
$this->assertSame(array(1 => '1', 2 => '2'), $field->createView()->get('choices'));
|
$this->assertEquals(array(1 => new ChoiceView('1', 'Foo'), 2 => new ChoiceView('2', 'Bar')), $field->createView()->get('choices'));
|
||||||
$this->assertSame(array(1 => 'Foo', 2 => 'Bar'), $field->createView()->get('choice_labels'));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -491,8 +489,7 @@ class EntityTypeTest extends TypeTestCase
|
|||||||
|
|
||||||
$field->bind('2');
|
$field->bind('2');
|
||||||
|
|
||||||
$this->assertSame(array(1 => '1', 2 => '2'), $field->createView()->get('choices'));
|
$this->assertEquals(array(1 => new ChoiceView('1', 'Foo'), 2 => new ChoiceView('2', 'Bar')), $field->createView()->get('choices'));
|
||||||
$this->assertSame(array(1 => 'Foo', 2 => 'Bar'), $field->createView()->get('choice_labels'));
|
|
||||||
$this->assertTrue($field->isSynchronized());
|
$this->assertTrue($field->isSynchronized());
|
||||||
$this->assertSame($entity2, $field->getData());
|
$this->assertSame($entity2, $field->getData());
|
||||||
$this->assertSame('2', $field->getClientData());
|
$this->assertSame('2', $field->getClientData());
|
||||||
@ -518,12 +515,11 @@ class EntityTypeTest extends TypeTestCase
|
|||||||
$field->bind('2');
|
$field->bind('2');
|
||||||
|
|
||||||
$this->assertSame('2', $field->getClientData());
|
$this->assertSame('2', $field->getClientData());
|
||||||
$this->assertSame(array(
|
$this->assertEquals(array(
|
||||||
'Group1' => array(1 => '1', 2 => '2'),
|
'Group1' => array(1 => new ChoiceView('1', 'Foo'), 2 => new ChoiceView('2', 'Bar')),
|
||||||
'Group2' => array(3 => '3'),
|
'Group2' => array(3 => new ChoiceView('3', 'Baz')),
|
||||||
'4' => '4'
|
'4' => new ChoiceView('4', 'Boo!')
|
||||||
), $field->createView()->get('choices'));
|
), $field->createView()->get('choices'));
|
||||||
$this->assertSame(array(1 => 'Foo', 2 => 'Bar', 3 => 'Baz', 4 => 'Boo!'), $field->createView()->get('choice_labels'));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testDisallowChoicesThatAreNotIncluded_choicesSingleIdentifier()
|
public function testDisallowChoicesThatAreNotIncluded_choicesSingleIdentifier()
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
namespace Symfony\Tests\Component\Form\Extension\Core\ChoiceList;
|
namespace Symfony\Tests\Component\Form\Extension\Core\ChoiceList;
|
||||||
|
|
||||||
use Symfony\Component\Form\Extension\Core\ChoiceList\ChoiceList;
|
use Symfony\Component\Form\Extension\Core\ChoiceList\ChoiceList;
|
||||||
|
use Symfony\Component\Form\Extension\Core\View\ChoiceView;
|
||||||
|
|
||||||
class ChoiceListTest extends \PHPUnit_Framework_TestCase
|
class ChoiceListTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
@ -67,29 +68,23 @@ class ChoiceListTest extends \PHPUnit_Framework_TestCase
|
|||||||
);
|
);
|
||||||
|
|
||||||
$this->assertSame(array($this->obj1, $this->obj2, $this->obj3, $this->obj4), $this->list->getChoices());
|
$this->assertSame(array($this->obj1, $this->obj2, $this->obj3, $this->obj4), $this->list->getChoices());
|
||||||
$this->assertSame(array('A', 'B', 'C', 'D'), $this->list->getLabels());
|
$this->assertSame(array('0', '1', '2', '3'), $this->list->getValues());
|
||||||
|
$this->assertEquals(array(1 => new ChoiceView('1', 'B')), $this->list->getPreferredViews());
|
||||||
$this->assertSame(array(1 => '1'), $this->list->getPreferredValues());
|
$this->assertEquals(array(0 => new ChoiceView('0', 'A'), 2 => new ChoiceView('2', 'C'), 3 => new ChoiceView('3', 'D')), $this->list->getRemainingViews());
|
||||||
$this->assertSame(array(1 => '1'), $this->list->getPreferredValueHierarchy());
|
|
||||||
$this->assertSame(array(0 => '0', 2 => '2', 3 => '3'), $this->list->getRemainingValues());
|
|
||||||
$this->assertSame(array(0 => '0', 2 => '2', 3 => '3'), $this->list->getRemainingValueHierarchy());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testInitNestedArray()
|
public function testInitNestedArray()
|
||||||
{
|
{
|
||||||
$this->assertSame(array($this->obj1, $this->obj2, $this->obj3, $this->obj4), $this->list->getChoices());
|
$this->assertSame(array($this->obj1, $this->obj2, $this->obj3, $this->obj4), $this->list->getChoices());
|
||||||
$this->assertSame(array('A', 'B', 'C', 'D'), $this->list->getLabels());
|
$this->assertSame(array('0', '1', '2', '3'), $this->list->getValues());
|
||||||
|
$this->assertEquals(array(
|
||||||
$this->assertSame(array(1 => '1', 2 => '2'), $this->list->getPreferredValues());
|
'Group 1' => array(1 => new ChoiceView('1', 'B')),
|
||||||
$this->assertSame(array(
|
'Group 2' => array(2 => new ChoiceView('2', 'C'))
|
||||||
'Group 1' => array(1 => '1'),
|
), $this->list->getPreferredViews());
|
||||||
'Group 2' => array(2 => '2')
|
$this->assertEquals(array(
|
||||||
), $this->list->getPreferredValueHierarchy());
|
'Group 1' => array(0 => new ChoiceView('0', 'A')),
|
||||||
$this->assertSame(array(0 => '0', 3 => '3'), $this->list->getRemainingValues());
|
'Group 2' => array(3 => new ChoiceView('3', 'D'))
|
||||||
$this->assertSame(array(
|
), $this->list->getRemainingViews());
|
||||||
'Group 1' => array(0 => '0'),
|
|
||||||
'Group 2' => array(3 => '3')
|
|
||||||
), $this->list->getRemainingValueHierarchy());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGetIndicesForChoices()
|
public function testGetIndicesForChoices()
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
namespace Symfony\Tests\Component\Form\Extension\Core\ChoiceList;
|
namespace Symfony\Tests\Component\Form\Extension\Core\ChoiceList;
|
||||||
|
|
||||||
use Symfony\Component\Form\Extension\Core\ChoiceList\ObjectChoiceList;
|
use Symfony\Component\Form\Extension\Core\ChoiceList\ObjectChoiceList;
|
||||||
|
use Symfony\Component\Form\Extension\Core\View\ChoiceView;
|
||||||
|
|
||||||
class ObjectChoiceListTest_EntityWithToString
|
class ObjectChoiceListTest_EntityWithToString
|
||||||
{
|
{
|
||||||
@ -79,29 +80,23 @@ class ObjectChoiceListTest extends \PHPUnit_Framework_TestCase
|
|||||||
);
|
);
|
||||||
|
|
||||||
$this->assertSame(array($this->obj1, $this->obj2, $this->obj3, $this->obj4), $this->list->getChoices());
|
$this->assertSame(array($this->obj1, $this->obj2, $this->obj3, $this->obj4), $this->list->getChoices());
|
||||||
$this->assertSame(array('A', 'B', 'C', 'D'), $this->list->getLabels());
|
$this->assertSame(array('0', '1', '2', '3'), $this->list->getValues());
|
||||||
|
$this->assertEquals(array(1 => new ChoiceView('1', 'B')), $this->list->getPreferredViews());
|
||||||
$this->assertSame(array(1 => '1'), $this->list->getPreferredValues());
|
$this->assertEquals(array(0 => new ChoiceView('0', 'A'), 2 => new ChoiceView('2', 'C'), 3 => new ChoiceView('3', 'D')), $this->list->getRemainingViews());
|
||||||
$this->assertSame(array(1 => '1'), $this->list->getPreferredValueHierarchy());
|
|
||||||
$this->assertSame(array(0 => '0', 2 => '2', 3 => '3'), $this->list->getRemainingValues());
|
|
||||||
$this->assertSame(array(0 => '0', 2 => '2', 3 => '3'), $this->list->getRemainingValueHierarchy());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testInitNestedArray()
|
public function testInitNestedArray()
|
||||||
{
|
{
|
||||||
$this->assertSame(array($this->obj1, $this->obj2, $this->obj3, $this->obj4), $this->list->getChoices());
|
$this->assertSame(array($this->obj1, $this->obj2, $this->obj3, $this->obj4), $this->list->getChoices());
|
||||||
$this->assertSame(array('A', 'B', 'C', 'D'), $this->list->getLabels());
|
$this->assertSame(array('0', '1', '2', '3'), $this->list->getValues());
|
||||||
|
$this->assertEquals(array(
|
||||||
$this->assertSame(array(1 => '1', 2 => '2'), $this->list->getPreferredValues());
|
'Group 1' => array(1 => new ChoiceView('1', 'B')),
|
||||||
$this->assertSame(array(
|
'Group 2' => array(2 => new ChoiceView('2', 'C'))
|
||||||
'Group 1' => array(1 => '1'),
|
), $this->list->getPreferredViews());
|
||||||
'Group 2' => array(2 => '2')
|
$this->assertEquals(array(
|
||||||
), $this->list->getPreferredValueHierarchy());
|
'Group 1' => array(0 => new ChoiceView('0', 'A')),
|
||||||
$this->assertSame(array(0 => '0', 3 => '3'), $this->list->getRemainingValues());
|
'Group 2' => array(3 => new ChoiceView('3', 'D'))
|
||||||
$this->assertSame(array(
|
), $this->list->getRemainingViews());
|
||||||
'Group 1' => array(0 => '0'),
|
|
||||||
'Group 2' => array(3 => '3')
|
|
||||||
), $this->list->getRemainingValueHierarchy());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testInitArrayWithGroupPath()
|
public function testInitArrayWithGroupPath()
|
||||||
@ -126,20 +121,17 @@ class ObjectChoiceListTest extends \PHPUnit_Framework_TestCase
|
|||||||
);
|
);
|
||||||
|
|
||||||
$this->assertSame(array($this->obj1, $this->obj2, $this->obj3, $this->obj4, $obj5, $obj6), $this->list->getChoices());
|
$this->assertSame(array($this->obj1, $this->obj2, $this->obj3, $this->obj4, $obj5, $obj6), $this->list->getChoices());
|
||||||
$this->assertSame(array('A', 'B', 'C', 'D', 'E', 'F'), $this->list->getLabels());
|
$this->assertSame(array('0', '1', '2', '3', '4', '5'), $this->list->getValues());
|
||||||
|
$this->assertEquals(array(
|
||||||
$this->assertSame(array(1 => '1', 2 => '2'), $this->list->getPreferredValues());
|
'Group 1' => array(1 => new ChoiceView('1', 'B')),
|
||||||
$this->assertSame(array(
|
'Group 2' => array(2 => new ChoiceView('2', 'C'))
|
||||||
'Group 1' => array(1 => '1'),
|
), $this->list->getPreferredViews());
|
||||||
'Group 2' => array(2 => '2')
|
$this->assertEquals(array(
|
||||||
), $this->list->getPreferredValueHierarchy());
|
'Group 1' => array(0 => new ChoiceView('0', 'A')),
|
||||||
$this->assertSame(array(0 => '0', 3 => '3', 4 => '4', 5 => '5'), $this->list->getRemainingValues());
|
'Group 2' => array(3 => new ChoiceView('3', 'D')),
|
||||||
$this->assertSame(array(
|
4 => new ChoiceView('4', 'E'),
|
||||||
'Group 1' => array(0 => '0'),
|
5 => new ChoiceView('5', 'F'),
|
||||||
'Group 2' => array(3 => '3'),
|
), $this->list->getRemainingViews());
|
||||||
4 => '4',
|
|
||||||
5 => '5',
|
|
||||||
), $this->list->getRemainingValueHierarchy());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -179,14 +171,9 @@ class ObjectChoiceListTest extends \PHPUnit_Framework_TestCase
|
|||||||
);
|
);
|
||||||
|
|
||||||
$this->assertSame(array($this->obj1, $this->obj2, $this->obj3, $this->obj4), $this->list->getChoices());
|
$this->assertSame(array($this->obj1, $this->obj2, $this->obj3, $this->obj4), $this->list->getChoices());
|
||||||
$this->assertSame(array('A', 'B', 'C', 'D'), $this->list->getLabels());
|
$this->assertSame(array('10', '20', '30', '40'), $this->list->getValues());
|
||||||
|
$this->assertEquals(array(1 => new ChoiceView('20', 'B'), 2 => new ChoiceView('30', 'C')), $this->list->getPreferredViews());
|
||||||
// Values are always converted to strings to avoid problems with
|
$this->assertEquals(array(0 => new ChoiceView('10', 'A'), 3 => new ChoiceView('40', 'D')), $this->list->getRemainingViews());
|
||||||
// comparisons
|
|
||||||
$this->assertSame(array(1 => '20', 2 => '30'), $this->list->getPreferredValues());
|
|
||||||
$this->assertSame(array(1 => '20', 2 => '30'), $this->list->getPreferredValueHierarchy());
|
|
||||||
$this->assertSame(array(0 => '10', 3 => '40'), $this->list->getRemainingValues());
|
|
||||||
$this->assertSame(array(0 => '10', 3 => '40'), $this->list->getRemainingValueHierarchy());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testInitArrayWithIndexPath()
|
public function testInitArrayWithIndexPath()
|
||||||
@ -206,12 +193,9 @@ class ObjectChoiceListTest extends \PHPUnit_Framework_TestCase
|
|||||||
);
|
);
|
||||||
|
|
||||||
$this->assertSame(array(10 => $this->obj1, 20 => $this->obj2, 30 => $this->obj3, 40 => $this->obj4), $this->list->getChoices());
|
$this->assertSame(array(10 => $this->obj1, 20 => $this->obj2, 30 => $this->obj3, 40 => $this->obj4), $this->list->getChoices());
|
||||||
$this->assertSame(array(10 => 'A', 20 => 'B', 30 => 'C', 40 => 'D'), $this->list->getLabels());
|
$this->assertSame(array(10 => '0', 20 => '1', 30 => '2', 40 => '3'), $this->list->getValues());
|
||||||
|
$this->assertEquals(array(20 => new ChoiceView('1', 'B'), 30 => new ChoiceView('2', 'C')), $this->list->getPreferredViews());
|
||||||
$this->assertSame(array(20 => '1', 30 => '2'), $this->list->getPreferredValues());
|
$this->assertEquals(array(10 => new ChoiceView('0', 'A'), 40 => new ChoiceView('3', 'D')), $this->list->getRemainingViews());
|
||||||
$this->assertSame(array(20 => '1', 30 => '2'), $this->list->getPreferredValueHierarchy());
|
|
||||||
$this->assertSame(array(10 => '0', 40 => '3'), $this->list->getRemainingValues());
|
|
||||||
$this->assertSame(array(10 => '0', 40 => '3'), $this->list->getRemainingValueHierarchy());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testInitArrayUsesToString()
|
public function testInitArrayUsesToString()
|
||||||
@ -226,7 +210,8 @@ class ObjectChoiceListTest extends \PHPUnit_Framework_TestCase
|
|||||||
);
|
);
|
||||||
|
|
||||||
$this->assertSame(array($this->obj1, $this->obj2, $this->obj3, $this->obj4), $this->list->getChoices());
|
$this->assertSame(array($this->obj1, $this->obj2, $this->obj3, $this->obj4), $this->list->getChoices());
|
||||||
$this->assertSame(array('A', 'B', 'C', 'D'), $this->list->getLabels());
|
$this->assertSame(array('0', '1', '2', '3'), $this->list->getValues());
|
||||||
|
$this->assertEquals(array(0 => new ChoiceView('0', 'A'), 1 => new ChoiceView('1', 'B'), 2 => new ChoiceView('2', 'C'), 3 => new ChoiceView('3', 'D')), $this->list->getRemainingViews());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -239,11 +224,8 @@ class ObjectChoiceListTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->obj3 = (object) array('name' => 'C');
|
$this->obj3 = (object) array('name' => 'C');
|
||||||
$this->obj4 = new ObjectChoiceListTest_EntityWithToString('D');
|
$this->obj4 = new ObjectChoiceListTest_EntityWithToString('D');
|
||||||
|
|
||||||
$this->list = new ObjectChoiceList(
|
new ObjectChoiceList(
|
||||||
array($this->obj1, $this->obj2, $this->obj3, $this->obj4)
|
array($this->obj1, $this->obj2, $this->obj3, $this->obj4)
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->assertSame(array($this->obj1, $this->obj2, $this->obj3, $this->obj4), $this->list->getChoices());
|
|
||||||
$this->assertSame(array('A', 'B', 'C', 'D'), $this->list->getLabels());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,8 +12,8 @@
|
|||||||
namespace Symfony\Tests\Component\Form\Extension\Core\ChoiceList;
|
namespace Symfony\Tests\Component\Form\Extension\Core\ChoiceList;
|
||||||
|
|
||||||
use Symfony\Component\Form\Extension\Core\ChoiceList\ChoiceList;
|
use Symfony\Component\Form\Extension\Core\ChoiceList\ChoiceList;
|
||||||
|
|
||||||
use Symfony\Component\Form\Extension\Core\ChoiceList\SimpleChoiceList;
|
use Symfony\Component\Form\Extension\Core\ChoiceList\SimpleChoiceList;
|
||||||
|
use Symfony\Component\Form\Extension\Core\View\ChoiceView;
|
||||||
|
|
||||||
class SimpleChoiceListTest extends \PHPUnit_Framework_TestCase
|
class SimpleChoiceListTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
@ -54,12 +54,9 @@ class SimpleChoiceListTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->list = new SimpleChoiceList($choices, array('b'), ChoiceList::GENERATE, ChoiceList::GENERATE);
|
$this->list = new SimpleChoiceList($choices, array('b'), ChoiceList::GENERATE, ChoiceList::GENERATE);
|
||||||
|
|
||||||
$this->assertSame(array(0 => 'a', 1 => 'b', 2 => 'c'), $this->list->getChoices());
|
$this->assertSame(array(0 => 'a', 1 => 'b', 2 => 'c'), $this->list->getChoices());
|
||||||
$this->assertSame(array(0 => 'A', 1 => 'B', 2 => 'C'), $this->list->getLabels());
|
$this->assertSame(array(0 => '0', 1 => '1', 2 => '2'), $this->list->getValues());
|
||||||
|
$this->assertEquals(array(1 => new ChoiceView('1', 'B')), $this->list->getPreferredViews());
|
||||||
$this->assertSame(array(1 => '1'), $this->list->getPreferredValues());
|
$this->assertEquals(array(0 => new ChoiceView('0', 'A'), 2 => new ChoiceView('2', 'C')), $this->list->getRemainingViews());
|
||||||
$this->assertSame(array(1 => '1'), $this->list->getPreferredValueHierarchy());
|
|
||||||
$this->assertSame(array(0 => '0', 2 => '2'), $this->list->getRemainingValues());
|
|
||||||
$this->assertSame(array(0 => '0', 2 => '2'), $this->list->getRemainingValueHierarchy());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testInitArrayValueCopyChoice()
|
public function testInitArrayValueCopyChoice()
|
||||||
@ -68,12 +65,9 @@ class SimpleChoiceListTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->list = new SimpleChoiceList($choices, array('b'), ChoiceList::COPY_CHOICE, ChoiceList::GENERATE);
|
$this->list = new SimpleChoiceList($choices, array('b'), ChoiceList::COPY_CHOICE, ChoiceList::GENERATE);
|
||||||
|
|
||||||
$this->assertSame(array(0 => 'a', 1 => 'b', 2 => 'c'), $this->list->getChoices());
|
$this->assertSame(array(0 => 'a', 1 => 'b', 2 => 'c'), $this->list->getChoices());
|
||||||
$this->assertSame(array(0 => 'A', 1 => 'B', 2 => 'C'), $this->list->getLabels());
|
$this->assertSame(array(0 => 'a', 1 => 'b', 2 => 'c'), $this->list->getValues());
|
||||||
|
$this->assertEquals(array(1 => new ChoiceView('b', 'B')), $this->list->getPreferredViews());
|
||||||
$this->assertSame(array(1 => 'b'), $this->list->getPreferredValues());
|
$this->assertEquals(array(0 => new ChoiceView('a', 'A'), 2 => new ChoiceView('c', 'C')), $this->list->getRemainingViews());
|
||||||
$this->assertSame(array(1 => 'b'), $this->list->getPreferredValueHierarchy());
|
|
||||||
$this->assertSame(array(0 => 'a', 2 => 'c'), $this->list->getRemainingValues());
|
|
||||||
$this->assertSame(array(0 => 'a', 2 => 'c'), $this->list->getRemainingValueHierarchy());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testInitArrayIndexCopyChoice()
|
public function testInitArrayIndexCopyChoice()
|
||||||
@ -82,29 +76,23 @@ class SimpleChoiceListTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->list = new SimpleChoiceList($choices, array('b'), ChoiceList::GENERATE, ChoiceList::COPY_CHOICE);
|
$this->list = new SimpleChoiceList($choices, array('b'), ChoiceList::GENERATE, ChoiceList::COPY_CHOICE);
|
||||||
|
|
||||||
$this->assertSame(array('a' => 'a', 'b' => 'b', 'c' => 'c'), $this->list->getChoices());
|
$this->assertSame(array('a' => 'a', 'b' => 'b', 'c' => 'c'), $this->list->getChoices());
|
||||||
$this->assertSame(array('a' => 'A', 'b' => 'B', 'c' => 'C'), $this->list->getLabels());
|
$this->assertSame(array('a' => '0', 'b' => '1', 'c' => '2'), $this->list->getValues());
|
||||||
|
$this->assertEquals(array('b' => new ChoiceView('1', 'B')), $this->list->getPreferredViews());
|
||||||
$this->assertSame(array('b' => '1'), $this->list->getPreferredValues());
|
$this->assertEquals(array('a' => new ChoiceView('0', 'A'), 'c' => new ChoiceView('2', 'C')), $this->list->getRemainingViews());
|
||||||
$this->assertSame(array('b' => '1'), $this->list->getPreferredValueHierarchy());
|
|
||||||
$this->assertSame(array('a' => '0', 'c' => '2'), $this->list->getRemainingValues());
|
|
||||||
$this->assertSame(array('a' => '0', 'c' => '2'), $this->list->getRemainingValueHierarchy());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testInitNestedArray()
|
public function testInitNestedArray()
|
||||||
{
|
{
|
||||||
$this->assertSame(array(0 => 'a', 1 => 'b', 2 => 'c', 3 => 'd'), $this->list->getChoices());
|
$this->assertSame(array(0 => 'a', 1 => 'b', 2 => 'c', 3 => 'd'), $this->list->getChoices());
|
||||||
$this->assertSame(array(0 => 'A', 1 => 'B', 2 => 'C', 3 => 'D'), $this->list->getLabels());
|
$this->assertSame(array(0 => '0', 1 => '1', 2 => '2', 3 => '3'), $this->list->getValues());
|
||||||
|
$this->assertEquals(array(
|
||||||
$this->assertSame(array(1 => '1', 2 => '2'), $this->list->getPreferredValues());
|
'Group 1' => array(1 => new ChoiceView('1', 'B')),
|
||||||
$this->assertSame(array(
|
'Group 2' => array(2 => new ChoiceView('2', 'C'))
|
||||||
'Group 1' => array(1 => '1'),
|
), $this->list->getPreferredViews());
|
||||||
'Group 2' => array(2 => '2')
|
$this->assertEquals(array(
|
||||||
), $this->list->getPreferredValueHierarchy());
|
'Group 1' => array(0 => new ChoiceView('0', 'A')),
|
||||||
$this->assertSame(array(0 => '0', 3 => '3'), $this->list->getRemainingValues());
|
'Group 2' => array(3 => new ChoiceView('3', 'D'))
|
||||||
$this->assertSame(array(
|
), $this->list->getRemainingViews());
|
||||||
'Group 1' => array(0 => '0'),
|
|
||||||
'Group 2' => array(3 => '3')
|
|
||||||
), $this->list->getRemainingValueHierarchy());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGetIndicesForChoices()
|
public function testGetIndicesForChoices()
|
||||||
|
@ -12,9 +12,8 @@
|
|||||||
namespace Symfony\Tests\Component\Form\Extension\Core\Type;
|
namespace Symfony\Tests\Component\Form\Extension\Core\Type;
|
||||||
|
|
||||||
use Symfony\Component\Form\Extension\Core\ChoiceList\ObjectChoiceList;
|
use Symfony\Component\Form\Extension\Core\ChoiceList\ObjectChoiceList;
|
||||||
|
|
||||||
use Symfony\Component\Form\Extension\Core\ChoiceList\SimpleChoiceList;
|
use Symfony\Component\Form\Extension\Core\ChoiceList\SimpleChoiceList;
|
||||||
|
use Symfony\Component\Form\Extension\Core\View\ChoiceView;
|
||||||
use Symfony\Component\Form\Exception\UnexpectedTypeException;
|
use Symfony\Component\Form\Exception\UnexpectedTypeException;
|
||||||
|
|
||||||
class ChoiceTypeTest extends TypeTestCase
|
class ChoiceTypeTest extends TypeTestCase
|
||||||
@ -600,8 +599,12 @@ class ChoiceTypeTest extends TypeTestCase
|
|||||||
));
|
));
|
||||||
$view = $form->createView();
|
$view = $form->createView();
|
||||||
|
|
||||||
$this->assertSame(array('0', '1', '2', '3'), $view->get('choices'));
|
$this->assertEquals(array(
|
||||||
$this->assertSame(array('A', 'B', 'C', 'D'), $view->get('choice_labels'));
|
new ChoiceView('0', 'A'),
|
||||||
|
new ChoiceView('1', 'B'),
|
||||||
|
new ChoiceView('2', 'C'),
|
||||||
|
new ChoiceView('3', 'D'),
|
||||||
|
), $view->get('choices'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testPassPreferredChoicesToView()
|
public function testPassPreferredChoicesToView()
|
||||||
@ -613,9 +616,14 @@ class ChoiceTypeTest extends TypeTestCase
|
|||||||
));
|
));
|
||||||
$view = $form->createView();
|
$view = $form->createView();
|
||||||
|
|
||||||
$this->assertSame(array(0 => '0', 2 => '2'), $view->get('choices'));
|
$this->assertEquals(array(
|
||||||
$this->assertSame(array(1 => '1', 3 => '3'), $view->get('preferred_choices'));
|
0 => new ChoiceView('0', 'A'),
|
||||||
$this->assertSame(array('A', 'B', 'C', 'D'), $view->get('choice_labels'));
|
2 => new ChoiceView('2', 'C'),
|
||||||
|
), $view->get('choices'));
|
||||||
|
$this->assertEquals(array(
|
||||||
|
1 => new ChoiceView('1', 'B'),
|
||||||
|
3 => new ChoiceView('3', 'D'),
|
||||||
|
), $view->get('preferred_choices'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testPassHierarchicalChoicesToView()
|
public function testPassHierarchicalChoicesToView()
|
||||||
@ -626,9 +634,23 @@ class ChoiceTypeTest extends TypeTestCase
|
|||||||
));
|
));
|
||||||
$view = $form->createView();
|
$view = $form->createView();
|
||||||
|
|
||||||
$this->assertSame(array('Symfony' => array(0 => '0', 2 => '2'), 'Doctrine' => array(4 => '4')), $view->get('choices'));
|
$this->assertEquals(array(
|
||||||
$this->assertSame(array('Symfony' => array(1 => '1'), 'Doctrine' => array(3 => '3')), $view->get('preferred_choices'));
|
'Symfony' => array(
|
||||||
$this->assertSame(array(0 => 'Bernhard', 1 => 'Fabien', 2 => 'Kris', 3 => 'Jon', 4 => 'Roman'), $view->get('choice_labels'));
|
0 => new ChoiceView('0', 'Bernhard'),
|
||||||
|
2 => new ChoiceView('2', 'Kris'),
|
||||||
|
),
|
||||||
|
'Doctrine' => array(
|
||||||
|
4 => new ChoiceView('4', 'Roman'),
|
||||||
|
),
|
||||||
|
), $view->get('choices'));
|
||||||
|
$this->assertEquals(array(
|
||||||
|
'Symfony' => array(
|
||||||
|
1 => new ChoiceView('1', 'Fabien'),
|
||||||
|
),
|
||||||
|
'Doctrine' => array(
|
||||||
|
3 => new ChoiceView('3', 'Jon'),
|
||||||
|
),
|
||||||
|
), $view->get('preferred_choices'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testAdjustFullNameForMultipleNonExpanded()
|
public function testAdjustFullNameForMultipleNonExpanded()
|
||||||
|
@ -11,6 +11,7 @@
|
|||||||
|
|
||||||
namespace Symfony\Tests\Component\Form\Extension\Core\Type;
|
namespace Symfony\Tests\Component\Form\Extension\Core\Type;
|
||||||
|
|
||||||
|
use Symfony\Component\Form\Extension\Core\View\ChoiceView;
|
||||||
|
|
||||||
class CountryTypeTest extends LocalizedTestCase
|
class CountryTypeTest extends LocalizedTestCase
|
||||||
{
|
{
|
||||||
@ -21,18 +22,12 @@ class CountryTypeTest extends LocalizedTestCase
|
|||||||
$form = $this->factory->create('country');
|
$form = $this->factory->create('country');
|
||||||
$view = $form->createView();
|
$view = $form->createView();
|
||||||
$choices = $view->get('choices');
|
$choices = $view->get('choices');
|
||||||
$labels = $view->get('choice_labels');
|
|
||||||
|
|
||||||
$this->assertContains('DE', $choices);
|
$this->assertEquals(new ChoiceView('DE', 'Deutschland'), $choices['DE']);
|
||||||
$this->assertEquals('Deutschland', $labels['DE']);
|
$this->assertEquals(new ChoiceView('GB', 'Vereinigtes Königreich'), $choices['GB']);
|
||||||
$this->assertContains('GB', $choices);
|
$this->assertEquals(new ChoiceView('US', 'Vereinigte Staaten'), $choices['US']);
|
||||||
$this->assertEquals('Vereinigtes Königreich', $labels['GB']);
|
$this->assertEquals(new ChoiceView('FR', 'Frankreich'), $choices['FR']);
|
||||||
$this->assertContains('US', $choices);
|
$this->assertEquals(new ChoiceView('MY', 'Malaysia'), $choices['MY']);
|
||||||
$this->assertEquals('Vereinigte Staaten', $labels['US']);
|
|
||||||
$this->assertContains('FR', $choices);
|
|
||||||
$this->assertEquals('Frankreich', $labels['FR']);
|
|
||||||
$this->assertContains('MY', $choices);
|
|
||||||
$this->assertEquals('Malaysia', $labels['MY']);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testUnknownCountryIsNotIncluded()
|
public function testUnknownCountryIsNotIncluded()
|
||||||
|
@ -11,8 +11,9 @@
|
|||||||
|
|
||||||
namespace Symfony\Tests\Component\Form\Extension\Core\Type;
|
namespace Symfony\Tests\Component\Form\Extension\Core\Type;
|
||||||
|
|
||||||
require_once __DIR__ . '/LocalizedTestCase.php';
|
use Symfony\Component\Form\Extension\Core\View\ChoiceView;
|
||||||
|
|
||||||
|
require_once __DIR__ . '/LocalizedTestCase.php';
|
||||||
|
|
||||||
class DateTypeTest extends LocalizedTestCase
|
class DateTypeTest extends LocalizedTestCase
|
||||||
{
|
{
|
||||||
@ -325,7 +326,10 @@ class DateTypeTest extends LocalizedTestCase
|
|||||||
|
|
||||||
$view = $form->createView();
|
$view = $form->createView();
|
||||||
|
|
||||||
$this->assertSame(array(2010 => '2010', 2011 => '2011'), $view->getChild('year')->get('choice_labels'));
|
$this->assertEquals(array(
|
||||||
|
2010 => new ChoiceView('2010', '2010'),
|
||||||
|
2011 => new ChoiceView('2011', '2011'),
|
||||||
|
), $view->getChild('year')->get('choices'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testMonthsOption()
|
public function testMonthsOption()
|
||||||
@ -336,7 +340,10 @@ class DateTypeTest extends LocalizedTestCase
|
|||||||
|
|
||||||
$view = $form->createView();
|
$view = $form->createView();
|
||||||
|
|
||||||
$this->assertSame(array(6 => '06', 7 => '07'), $view->getChild('month')->get('choice_labels'));
|
$this->assertEquals(array(
|
||||||
|
6 => new ChoiceView('6', '06'),
|
||||||
|
7 => new ChoiceView('7', '07'),
|
||||||
|
), $view->getChild('month')->get('choices'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testMonthsOptionNumericIfFormatContainsNoMonth()
|
public function testMonthsOptionNumericIfFormatContainsNoMonth()
|
||||||
@ -348,7 +355,10 @@ class DateTypeTest extends LocalizedTestCase
|
|||||||
|
|
||||||
$view = $form->createView();
|
$view = $form->createView();
|
||||||
|
|
||||||
$this->assertSame(array(6 => '06', 7 => '07'), $view->getChild('month')->get('choice_labels'));
|
$this->assertEquals(array(
|
||||||
|
6 => new ChoiceView('6', '06'),
|
||||||
|
7 => new ChoiceView('7', '07'),
|
||||||
|
), $view->getChild('month')->get('choices'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testMonthsOptionShortFormat()
|
public function testMonthsOptionShortFormat()
|
||||||
@ -360,7 +370,10 @@ class DateTypeTest extends LocalizedTestCase
|
|||||||
|
|
||||||
$view = $form->createView();
|
$view = $form->createView();
|
||||||
|
|
||||||
$this->assertSame(array(1 => 'Jän', 4 => 'Apr'), $view->getChild('month')->get('choice_labels'));
|
$this->assertEquals(array(
|
||||||
|
1 => new ChoiceView('1', 'Jän'),
|
||||||
|
4 => new ChoiceView('4', 'Apr')
|
||||||
|
), $view->getChild('month')->get('choices'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testMonthsOptionLongFormat()
|
public function testMonthsOptionLongFormat()
|
||||||
@ -372,7 +385,10 @@ class DateTypeTest extends LocalizedTestCase
|
|||||||
|
|
||||||
$view = $form->createView();
|
$view = $form->createView();
|
||||||
|
|
||||||
$this->assertSame(array(1 => 'Jänner', 4 => 'April'), $view->getChild('month')->get('choice_labels'));
|
$this->assertEquals(array(
|
||||||
|
1 => new ChoiceView('1', 'Jänner'),
|
||||||
|
4 => new ChoiceView('4', 'April'),
|
||||||
|
), $view->getChild('month')->get('choices'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testMonthsOptionLongFormatWithDifferentTimezone()
|
public function testMonthsOptionLongFormatWithDifferentTimezone()
|
||||||
@ -384,7 +400,10 @@ class DateTypeTest extends LocalizedTestCase
|
|||||||
|
|
||||||
$view = $form->createView();
|
$view = $form->createView();
|
||||||
|
|
||||||
$this->assertSame(array(1 => 'Jänner', 4 => 'April'), $view->getChild('month')->get('choice_labels'));
|
$this->assertEquals(array(
|
||||||
|
1 => new ChoiceView('1', 'Jänner'),
|
||||||
|
4 => new ChoiceView('4', 'April'),
|
||||||
|
), $view->getChild('month')->get('choices'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testIsDayWithinRangeReturnsTrueIfWithin()
|
public function testIsDayWithinRangeReturnsTrueIfWithin()
|
||||||
@ -395,7 +414,10 @@ class DateTypeTest extends LocalizedTestCase
|
|||||||
|
|
||||||
$view = $form->createView();
|
$view = $form->createView();
|
||||||
|
|
||||||
$this->assertSame(array(6 => '06', 7 => '07'), $view->getChild('day')->get('choice_labels'));
|
$this->assertEquals(array(
|
||||||
|
6 => new ChoiceView('6', '06'),
|
||||||
|
7 => new ChoiceView('7', '07'),
|
||||||
|
), $view->getChild('day')->get('choices'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testIsPartiallyFilledReturnsFalseIfSingleText()
|
public function testIsPartiallyFilledReturnsFalseIfSingleText()
|
||||||
|
@ -11,6 +11,7 @@
|
|||||||
|
|
||||||
namespace Symfony\Tests\Component\Form\Extension\Core\Type;
|
namespace Symfony\Tests\Component\Form\Extension\Core\Type;
|
||||||
|
|
||||||
|
use Symfony\Component\Form\Extension\Core\View\ChoiceView;
|
||||||
|
|
||||||
class LanguageTypeTest extends LocalizedTestCase
|
class LanguageTypeTest extends LocalizedTestCase
|
||||||
{
|
{
|
||||||
@ -23,16 +24,11 @@ class LanguageTypeTest extends LocalizedTestCase
|
|||||||
$choices = $view->get('choices');
|
$choices = $view->get('choices');
|
||||||
$labels = $view->get('choice_labels');
|
$labels = $view->get('choice_labels');
|
||||||
|
|
||||||
$this->assertContains('en', $choices);
|
$this->assertContains(new ChoiceView('en', 'Englisch'), $choices, '', false, false);
|
||||||
$this->assertEquals('Englisch', $labels[array_search('en', $choices)]);
|
$this->assertContains(new ChoiceView('en_GB', 'Britisches Englisch'), $choices, '', false, false);
|
||||||
$this->assertContains('en_GB', $choices);
|
$this->assertContains(new ChoiceView('en_US', 'Amerikanisches Englisch'), $choices, '', false, false);
|
||||||
$this->assertEquals('Britisches Englisch', $labels[array_search('en_GB', $choices)]);
|
$this->assertContains(new ChoiceView('fr', 'Französisch'), $choices, '', false, false);
|
||||||
$this->assertContains('en_US', $choices);
|
$this->assertContains(new ChoiceView('my', 'Birmanisch'), $choices, '', false, false);
|
||||||
$this->assertEquals('Amerikanisches Englisch', $labels[array_search('en_US', $choices)]);
|
|
||||||
$this->assertContains('fr', $choices);
|
|
||||||
$this->assertEquals('Französisch', $labels[array_search('fr', $choices)]);
|
|
||||||
$this->assertContains('my', $choices);
|
|
||||||
$this->assertEquals('Birmanisch', $labels[array_search('my', $choices)]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testMultipleLanguagesIsNotIncluded()
|
public function testMultipleLanguagesIsNotIncluded()
|
||||||
@ -41,6 +37,6 @@ class LanguageTypeTest extends LocalizedTestCase
|
|||||||
$view = $form->createView();
|
$view = $form->createView();
|
||||||
$choices = $view->get('choices');
|
$choices = $view->get('choices');
|
||||||
|
|
||||||
$this->assertArrayNotHasKey('mul', $choices);
|
$this->assertNotContains(new ChoiceView('mul', 'Mehrsprachig'), $choices, '', false, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,6 +11,7 @@
|
|||||||
|
|
||||||
namespace Symfony\Tests\Component\Form\Extension\Core\Type;
|
namespace Symfony\Tests\Component\Form\Extension\Core\Type;
|
||||||
|
|
||||||
|
use Symfony\Component\Form\Extension\Core\View\ChoiceView;
|
||||||
|
|
||||||
class LocaleTypeTest extends LocalizedTestCase
|
class LocaleTypeTest extends LocalizedTestCase
|
||||||
{
|
{
|
||||||
@ -21,13 +22,9 @@ class LocaleTypeTest extends LocalizedTestCase
|
|||||||
$form = $this->factory->create('locale');
|
$form = $this->factory->create('locale');
|
||||||
$view = $form->createView();
|
$view = $form->createView();
|
||||||
$choices = $view->get('choices');
|
$choices = $view->get('choices');
|
||||||
$labels = $view->get('choice_labels');
|
|
||||||
|
|
||||||
$this->assertContains('en', $choices);
|
$this->assertContains(new ChoiceView('en', 'Englisch'), $choices, '', false, false);
|
||||||
$this->assertEquals('Englisch', $labels[array_search('en', $choices)]);
|
$this->assertContains(new ChoiceView('en_GB', 'Englisch (Vereinigtes Königreich)'), $choices, '', false, false);
|
||||||
$this->assertContains('en_GB', $choices);
|
$this->assertContains(new ChoiceView('zh_Hant_MO', 'Chinesisch (traditionell, Sonderverwaltungszone Macao)'), $choices, '', false, false);
|
||||||
$this->assertEquals('Englisch (Vereinigtes Königreich)', $labels[array_search('en_GB', $choices)]);
|
|
||||||
$this->assertContains('zh_Hant_MO', $choices);
|
|
||||||
$this->assertEquals('Chinesisch (traditionell, Sonderverwaltungszone Macao)', $labels[array_search('zh_Hant_MO', $choices)]);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,6 +11,8 @@
|
|||||||
|
|
||||||
namespace Symfony\Tests\Component\Form\Extension\Core\Type;
|
namespace Symfony\Tests\Component\Form\Extension\Core\Type;
|
||||||
|
|
||||||
|
use Symfony\Component\Form\Extension\Core\View\ChoiceView;
|
||||||
|
|
||||||
require_once __DIR__ . '/LocalizedTestCase.php';
|
require_once __DIR__ . '/LocalizedTestCase.php';
|
||||||
|
|
||||||
|
|
||||||
@ -243,7 +245,10 @@ class TimeTypeTest extends LocalizedTestCase
|
|||||||
|
|
||||||
$view = $form->createView();
|
$view = $form->createView();
|
||||||
|
|
||||||
$this->assertSame(array(6 => '06', 7 => '07'), $view->getChild('hour')->get('choice_labels'));
|
$this->assertEquals(array(
|
||||||
|
6 => new ChoiceView('6', '06'),
|
||||||
|
7 => new ChoiceView('7', '07'),
|
||||||
|
), $view->getChild('hour')->get('choices'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testIsMinuteWithinRange_returnsTrueIfWithin()
|
public function testIsMinuteWithinRange_returnsTrueIfWithin()
|
||||||
@ -254,7 +259,10 @@ class TimeTypeTest extends LocalizedTestCase
|
|||||||
|
|
||||||
$view = $form->createView();
|
$view = $form->createView();
|
||||||
|
|
||||||
$this->assertSame(array(6 => '06', 7 => '07'), $view->getChild('minute')->get('choice_labels'));
|
$this->assertEquals(array(
|
||||||
|
6 => new ChoiceView('6', '06'),
|
||||||
|
7 => new ChoiceView('7', '07'),
|
||||||
|
), $view->getChild('minute')->get('choices'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testIsSecondWithinRange_returnsTrueIfWithin()
|
public function testIsSecondWithinRange_returnsTrueIfWithin()
|
||||||
@ -266,7 +274,10 @@ class TimeTypeTest extends LocalizedTestCase
|
|||||||
|
|
||||||
$view = $form->createView();
|
$view = $form->createView();
|
||||||
|
|
||||||
$this->assertSame(array(6 => '06', 7 => '07'), $view->getChild('second')->get('choice_labels'));
|
$this->assertEquals(array(
|
||||||
|
6 => new ChoiceView('6', '06'),
|
||||||
|
7 => new ChoiceView('7', '07'),
|
||||||
|
), $view->getChild('second')->get('choices'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testIsPartiallyFilled_returnsFalseIfCompletelyEmpty()
|
public function testIsPartiallyFilled_returnsFalseIfCompletelyEmpty()
|
||||||
|
@ -11,6 +11,7 @@
|
|||||||
|
|
||||||
namespace Symfony\Tests\Component\Form\Extension\Core\Type;
|
namespace Symfony\Tests\Component\Form\Extension\Core\Type;
|
||||||
|
|
||||||
|
use Symfony\Component\Form\Extension\Core\View\ChoiceView;
|
||||||
|
|
||||||
class TimezoneTypeTest extends TypeTestCase
|
class TimezoneTypeTest extends TypeTestCase
|
||||||
{
|
{
|
||||||
@ -22,11 +23,9 @@ class TimezoneTypeTest extends TypeTestCase
|
|||||||
$labels = $view->get('choice_labels');
|
$labels = $view->get('choice_labels');
|
||||||
|
|
||||||
$this->assertArrayHasKey('Africa', $choices);
|
$this->assertArrayHasKey('Africa', $choices);
|
||||||
$this->assertContains('Africa/Kinshasa', $choices['Africa']);
|
$this->assertContains(new ChoiceView('Africa/Kinshasa', 'Kinshasa'), $choices['Africa'], '', false, false);
|
||||||
$this->assertEquals('Kinshasa', $labels[array_search('Africa/Kinshasa', $choices['Africa'])]);
|
|
||||||
|
|
||||||
$this->assertArrayHasKey('America', $choices);
|
$this->assertArrayHasKey('America', $choices);
|
||||||
$this->assertContains('America/New_York', $choices['America']);
|
$this->assertContains(new ChoiceView('America/New_York', 'New York'), $choices['America'], '', false, false);
|
||||||
$this->assertEquals('New York', $labels[array_search('America/New_York', $choices['America'])]);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user