[Form] Renamed TemplateContext to FormView

This commit is contained in:
Bernhard Schussek 2011-04-14 15:02:51 +02:00
parent ca6ae09779
commit 72b17cd67c
49 changed files with 410 additions and 410 deletions

View File

@ -12,7 +12,7 @@
namespace Symfony\Bridge\Twig\Extension;
use Symfony\Bridge\Twig\TokenParser\FormThemeTokenParser;
use Symfony\Component\Form\TemplateContext;
use Symfony\Component\Form\FormView;
use Symfony\Component\Form\Exception\FormException;
/**
@ -43,14 +43,14 @@ class FormExtension extends \Twig_Extension
}
/**
* Sets a theme for a given context.
* Sets a theme for a given view.
*
* @param TemplateContext $context A TemplateContext instance
* @param FormView $view A FormView instance
* @param array $resources An array of resources
*/
public function setTheme(TemplateContext $context, array $resources)
public function setTheme(FormView $view, array $resources)
{
$this->themes->attach($context, $resources);
$this->themes->attach($view, $resources);
}
/**
@ -86,115 +86,115 @@ class FormExtension extends \Twig_Extension
*
* <form action="..." method="post" {{ form_enctype(form) }}>
*
* @param TemplateContext $context The context for which to render the encoding type
* @param FormView $view The view for which to render the encoding type
*/
public function renderEnctype(TemplateContext $context)
public function renderEnctype(FormView $view)
{
return $this->render($context, 'enctype');
return $this->render($view, 'enctype');
}
/**
* Renders a row for the context.
* Renders a row for the view.
*
* @param TemplateContext $context The context to render as a row
* @param FormView $view The view to render as a row
*/
public function renderRow(TemplateContext $context, array $variables = array())
public function renderRow(FormView $view, array $variables = array())
{
return $this->render($context, 'row', $variables);
return $this->render($view, 'row', $variables);
}
public function renderRest(TemplateContext $context, array $variables = array())
public function renderRest(FormView $view, array $variables = array())
{
return $this->render($context, 'rest', $variables);
return $this->render($view, 'rest', $variables);
}
/**
* Renders the HTML for a given context
* Renders the HTML for a given view
*
* Example usage in Twig:
*
* {{ form_widget(context) }}
* {{ form_widget(view) }}
*
* You can pass attributes element during the call:
*
* {{ form_widget(context, {'class': 'foo'}) }}
* {{ form_widget(view, {'class': 'foo'}) }}
*
* Some fields also accept additional variables as parameters:
*
* {{ form_widget(context, {}, {'separator': '+++++'}) }}
* {{ form_widget(view, {}, {'separator': '+++++'}) }}
*
* @param TemplateContext $context The context to render
* @param FormView $view The view to render
* @param array $attributes HTML attributes passed to the template
* @param array $parameters Additional variables passed to the template
* @param array|string $resources A resource or array of resources
*/
public function renderWidget(TemplateContext $context, array $variables = array(), $resources = null)
public function renderWidget(FormView $view, array $variables = array(), $resources = null)
{
if (null !== $resources && !is_array($resources)) {
$resources = array($resources);
}
return $this->render($context, 'widget', $variables, $resources);
return $this->render($view, 'widget', $variables, $resources);
}
/**
* Renders the errors of the given context
* Renders the errors of the given view
*
* @param TemplateContext $context The context to render the errors for
* @param FormView $view The view to render the errors for
* @param array $params Additional variables passed to the template
*/
public function renderErrors(TemplateContext $context)
public function renderErrors(FormView $view)
{
return $this->render($context, 'errors');
return $this->render($view, 'errors');
}
/**
* Renders the label of the given context
* Renders the label of the given view
*
* @param TemplateContext $context The context to render the label for
* @param FormView $view The view to render the label for
*/
public function renderLabel(TemplateContext $context, $label = null)
public function renderLabel(FormView $view, $label = null)
{
return $this->render($context, 'label', null === $label ? array() : array('label' => $label));
return $this->render($view, 'label', null === $label ? array() : array('label' => $label));
}
/**
* Renders the widget data of the given context
* Renders the widget data of the given view
*
* @param TemplateContext $context The context to render the data for
* @param FormView $view The view to render the data for
*/
public function renderData(TemplateContext $context)
public function renderData(FormView $view)
{
return $form->getData();
}
protected function render(TemplateContext $context, $section, array $variables = array(), array $resources = null)
protected function render(FormView $view, $section, array $variables = array(), array $resources = null)
{
$templates = $this->getTemplates($context, $resources);
$blocks = $context->getVar('types');
$templates = $this->getTemplates($view, $resources);
$blocks = $view->getVar('types');
foreach ($blocks as &$block) {
$block = $block.'__'.$section;
if (isset($templates[$block])) {
if ('widget' === $section || 'row' === $section) {
$context->setRendered(true);
$view->setRendered(true);
}
return $templates[$block]->renderBlock($block, array_merge($context->getVars(), $variables));
return $templates[$block]->renderBlock($block, array_merge($view->getVars(), $variables));
}
}
throw new FormException(sprintf('Unable to render form as none of the following blocks exist: "%s".', implode('", "', $blocks)));
}
protected function getTemplate(TemplateContext $context, $name, array $resources = null)
protected function getTemplate(FormView $view, $name, array $resources = null)
{
$templates = $this->getTemplates($context, $resources);
$templates = $this->getTemplates($view, $resources);
return $templates[$name];
}
protected function getTemplates(TemplateContext $context, array $resources = null)
protected function getTemplates(FormView $view, array $resources = null)
{
// templates are looked for in the following resources:
// * resources provided directly into the function call
@ -205,7 +205,7 @@ class FormExtension extends \Twig_Extension
$all = $this->resources;
// themes
$parent = $context;
$parent = $view;
do {
if (isset($this->themes[$parent])) {
$all = array_merge($all, $this->themes[$parent]);

View File

@ -1,6 +1,6 @@
<?php if ($expanded): ?>
<div<?php echo $view['form']->attributes() ?>>
<?php foreach ($context as $choice => $child): ?>
<?php foreach ($form as $choice => $child): ?>
<?php echo $view['form']->widget($child) ?>
<?php echo $view['form']->label($child) ?>
<?php endforeach ?>
@ -16,27 +16,27 @@
<?php if (!$multiple && !$required): ?><option value=""><?php echo $empty_value; ?></option><?php endif; ?>
<?php if (count($preferred_choices) > 0): ?>
<?php foreach ($preferred_choices as $choice => $label): ?>
<?php if ($context->isChoiceGroup($label)): ?>
<?php if ($form->isChoiceGroup($label)): ?>
<optgroup label="<?php echo $choice ?>">
<?php foreach ($label as $nestedChoice => $nestedLabel): ?>
<option value="<?php echo $nestedChoice ?>"<?php if ($context->isChoiceSelected($nestedChoice)): ?> selected="selected"<?php endif?>><?php echo $nestedLabel ?></option>
<option value="<?php echo $nestedChoice ?>"<?php if ($form->isChoiceSelected($nestedChoice)): ?> selected="selected"<?php endif?>><?php echo $nestedLabel ?></option>
<?php endforeach ?>
</optgroup>
<?php else: ?>
<option value="<?php echo $choice ?>"<?php if ($context->isChoiceSelected($choice)): ?> selected="selected"<?php endif?>><?php echo $label ?></option>
<option value="<?php echo $choice ?>"<?php if ($form->isChoiceSelected($choice)): ?> selected="selected"<?php endif?>><?php echo $label ?></option>
<?php endif ?>
<?php endforeach ?>
<option disabled="disabled"><?php echo $separator ?></option>
<?php endif ?>
<?php foreach ($choices as $choice => $label): ?>
<?php if ($context->isChoiceGroup($label)): ?>
<?php if ($form->isChoiceGroup($label)): ?>
<optgroup label="<?php echo $choice ?>">
<?php foreach ($label as $nestedChoice => $nestedLabel): ?>
<option value="<?php echo $nestedChoice ?>"<?php if ($context->isChoiceSelected($nestedChoice)): ?> selected="selected"<?php endif?>><?php echo $nestedLabel ?></option>
<option value="<?php echo $nestedChoice ?>"<?php if ($form->isChoiceSelected($nestedChoice)): ?> selected="selected"<?php endif?>><?php echo $nestedLabel ?></option>
<?php endforeach ?>
</optgroup>
<?php else: ?>
<option value="<?php echo $choice ?>"<?php if ($context->isChoiceSelected($choice)): ?> selected="selected"<?php endif?>><?php echo $label ?></option>
<option value="<?php echo $choice ?>"<?php if ($form->isChoiceSelected($choice)): ?> selected="selected"<?php endif?>><?php echo $label ?></option>
<?php endif ?>
<?php endforeach ?>
</select>

View File

@ -11,9 +11,9 @@
<?php else: ?>
<div<?php echo $view['form']->attributes() ?>>
<?php echo str_replace(array('{{ year }}', '{{ month }}', '{{ day }}'), array(
$view['form']->widget($context['year']),
$view['form']->widget($context['month']),
$view['form']->widget($context['day']),
$view['form']->widget($form['year']),
$view['form']->widget($form['month']),
$view['form']->widget($form['day']),
), $date_pattern) ?>
</div>
<?php endif ?>

View File

@ -1,5 +1,5 @@
<div<?php echo $view['form']->attributes() ?>>
<?php echo $view['form']->widget($context['date'])
<?php echo $view['form']->widget($form['date'])
. ' '
. $view['form']->widget($context['time']) ?>
. $view['form']->widget($form['time']) ?>
</div>

View File

@ -1 +1 @@
<?php if ($context->getVar('multipart')): ?>enctype="multipart/form-data"<?php endif ?>
<?php if ($form->getVar('multipart')): ?>enctype="multipart/form-data"<?php endif ?>

View File

@ -1,5 +1,5 @@
<?php foreach ($context->getChildren() as $context): ?>
<?php if (!$context->isRendered()): ?>
<?php echo $view['form']->row($context) ?>
<?php foreach ($form->getChildren() as $child): ?>
<?php if (!$child->isRendered()): ?>
<?php echo $view['form']->row($child) ?>
<?php endif; ?>
<?php endforeach; ?>

View File

@ -1,5 +1,5 @@
<div>
<?php echo $view['form']->label($context) ?>
<?php echo $view['form']->errors($context) ?>
<?php echo $view['form']->widget($context) ?>
<?php echo $view['form']->label($form) ?>
<?php echo $view['form']->errors($form) ?>
<?php echo $view['form']->widget($form) ?>
</div>

View File

@ -1,12 +1,12 @@
<div<?php echo $view['form']->attributes() ?>>
<input type="file"
id="<?php echo $context['file']->getVar('id') ?>"
name="<?php echo $context['file']->getVar('name') ?>"
<?php if ($context['file']->getVar('disabled')): ?>disabled="disabled"<?php endif ?>
<?php if ($context['file']->getVar('required')): ?>required="required"<?php endif ?>
<?php if ($context['file']->getVar('class')): ?>class="<?php echo $context['file']->getVar('class') ?>"<?php endif ?>
id="<?php echo $form['file']->getVar('id') ?>"
name="<?php echo $form['file']->getVar('name') ?>"
<?php if ($form['file']->getVar('disabled')): ?>disabled="disabled"<?php endif ?>
<?php if ($form['file']->getVar('required')): ?>required="required"<?php endif ?>
<?php if ($form['file']->getVar('class')): ?>class="<?php echo $form['file']->getVar('class') ?>"<?php endif ?>
/>
<?php echo $view['form']->widget($context['token']) ?>
<?php echo $view['form']->widget($context['name']) ?>
<?php echo $view['form']->widget($form['token']) ?>
<?php echo $view['form']->widget($form['name']) ?>
</div>

View File

@ -1,8 +1,8 @@
<div<?php echo $view['form']->attributes() ?>>
<?php echo $view['form']->errors($context); ?>
<?php foreach ($context->getChildren() as $context): ?>
<?php echo $view['form']->row($context); ?>
<?php echo $view['form']->errors($form); ?>
<?php foreach ($form->getChildren() as $child): ?>
<?php echo $view['form']->row($child); ?>
<?php endforeach; ?>
<?php echo $view['form']->rest($context) ?>
<?php echo $view['form']->rest($form) ?>
</div>

View File

@ -1 +1 @@
<?php echo $view['form']->widget($context) ?>
<?php echo $view['form']->widget($form) ?>

View File

@ -1,5 +1,5 @@
<?php echo $view['form']->errors($context) ?>
<?php echo $view['form']->errors($form) ?>
<?php foreach ($context->getChildren() as $context): ?>
<?php echo $view['form']->row($context); ?>
<?php foreach ($form->getChildren() as $child): ?>
<?php echo $view['form']->row($child); ?>
<?php endforeach; ?>

View File

@ -2,13 +2,13 @@
<?php
// There should be no spaces between the colons and the widgets, that's why
// this block is written in a single PHP tag
echo $view['form']->widget($context['hour'], array('size' => 1));
echo $view['form']->widget($form['hour'], array('size' => 1));
echo ':';
echo $view['form']->widget($context['minute'], array('size' => 1));
echo $view['form']->widget($form['minute'], array('size' => 1));
if ($with_seconds) {
echo ':';
echo $view['form']->widget($context['second'], array('size' => 1));
echo $view['form']->widget($form['second'], array('size' => 1));
}
?>
</div>

View File

@ -13,7 +13,7 @@ namespace Symfony\Bundle\FrameworkBundle\Templating\Helper;
use Symfony\Component\Templating\Helper\Helper;
use Symfony\Component\Templating\EngineInterface;
use Symfony\Component\Form\TemplateContext;
use Symfony\Component\Form\FormView;
use Symfony\Component\Form\Exception\FormException;
/**
@ -59,14 +59,14 @@ class FormHelper extends Helper
return $html;
}
public function enctype(TemplateContext $context)
public function enctype(FormView $view)
{
return $this->renderSection($context, 'enctype');
return $this->renderSection($view, 'enctype');
}
public function widget(TemplateContext $context, array $variables = array())
public function widget(FormView $view, array $variables = array())
{
return trim($this->renderSection($context, 'widget', $variables));
return trim($this->renderSection($view, 'widget', $variables));
}
/**
@ -75,30 +75,30 @@ class FormHelper extends Helper
* @param FieldInterface $field
* @return string
*/
public function row(TemplateContext $context, array $variables = array())
public function row(FormView $view, array $variables = array())
{
return $this->renderSection($context, 'row', $variables);
return $this->renderSection($view, 'row', $variables);
}
public function label(TemplateContext $context, $label = null)
public function label(FormView $view, $label = null)
{
return $this->renderSection($context, 'label', null === $label ? array() : array('label' => $label));
return $this->renderSection($view, 'label', null === $label ? array() : array('label' => $label));
}
public function errors(TemplateContext $context)
public function errors(FormView $view)
{
return $this->renderSection($context, 'errors');
return $this->renderSection($view, 'errors');
}
public function rest(TemplateContext $context, array $variables = array())
public function rest(FormView $view, array $variables = array())
{
return $this->renderSection($context, 'rest', $variables);
return $this->renderSection($view, 'rest', $variables);
}
protected function renderSection(TemplateContext $context, $section, array $variables = array())
protected function renderSection(FormView $view, $section, array $variables = array())
{
$template = null;
$blocks = $context->getVar('types');
$blocks = $view->getVar('types');
foreach ($blocks as &$block) {
$block = $block.'_'.$section;
@ -114,10 +114,10 @@ class FormHelper extends Helper
}
if ('widget' === $section || 'row' === $section) {
$context->setRendered(true);
$view->setRendered(true);
}
return $this->render($template, array_merge($context->getVars(), $variables));
return $this->render($template, array_merge($view->getVars(), $variables));
}
public function render($template, array $variables = array())

View File

@ -18,7 +18,7 @@ use Symfony\Bundle\FrameworkBundle\Templating\Helper\FormHelper;
use Symfony\Bundle\FrameworkBundle\Templating\Helper\TranslatorHelper;
use Symfony\Bundle\FrameworkBundle\Tests\Templating\Helper\Fixtures\StubTemplateNameParser;
use Symfony\Bundle\FrameworkBundle\Tests\Templating\Helper\Fixtures\StubTranslator;
use Symfony\Component\Form\TemplateContext;
use Symfony\Component\Form\FormView;
use Symfony\Component\Templating\PhpEngine;
use Symfony\Component\Templating\TemplateNameParser;
use Symfony\Component\Templating\Loader\FilesystemLoader;
@ -45,34 +45,34 @@ class FormHelperTest extends AbstractDivLayoutTest
));
}
protected function renderEnctype(TemplateContext $context)
protected function renderEnctype(FormView $view)
{
return (string)$this->helper->enctype($context);
return (string)$this->helper->enctype($view);
}
protected function renderLabel(TemplateContext $context, $label = null)
protected function renderLabel(FormView $view, $label = null)
{
return (string)$this->helper->label($context, $label);
return (string)$this->helper->label($view, $label);
}
protected function renderErrors(TemplateContext $context)
protected function renderErrors(FormView $view)
{
return (string)$this->helper->errors($context);
return (string)$this->helper->errors($view);
}
protected function renderWidget(TemplateContext $context, array $vars = array())
protected function renderWidget(FormView $view, array $vars = array())
{
return (string)$this->helper->widget($context, $vars);
return (string)$this->helper->widget($view, $vars);
}
protected function renderRow(TemplateContext $context, array $vars = array())
protected function renderRow(FormView $view, array $vars = array())
{
return (string)$this->helper->row($context, $vars);
return (string)$this->helper->row($view, $vars);
}
protected function renderRest(TemplateContext $context, array $vars = array())
protected function renderRest(FormView $view, array $vars = array())
{
return (string)$this->helper->rest($context, $vars);
return (string)$this->helper->rest($view, $vars);
}
}

View File

@ -1,8 +1,8 @@
{% block field__rows %}
{% spaceless %}
{{ form_errors(context) }}
{% for context in context.children %}
{{ form_row(context) }}
{{ form_errors(form) }}
{% for child in form.children %}
{{ form_row(child) }}
{% endfor %}
{% endspaceless %}
{% endblock field__rows %}
@ -27,9 +27,9 @@
{% block field__rest %}
{% spaceless %}
{% for context in context.children %}
{% if not context.rendered %}
{{ form_row(context) }}
{% for child in form.children %}
{% if not child.rendered %}
{{ form_row(child) }}
{% endif %}
{% endfor %}
{% endspaceless %}
@ -75,7 +75,7 @@
{% endblock hidden__widget %}
{% block hidden__row %}
{{ form_widget(context) }}
{{ form_widget(form) }}
{% endblock hidden__row %}
{% block textarea__widget %}
@ -87,14 +87,14 @@
{% block options %}
{% spaceless %}
{% for choice, label in options %}
{% if context.choiceGroup(label) %}
{% if form.choiceGroup(label) %}
<optgroup label="{{ choice }}">
{% for nestedChoice, nestedLabel in label %}
<option value="{{ nestedChoice }}"{% if context.choiceSelected(nestedChoice) %} selected="selected"{% endif %}>{{ nestedLabel }}</option>
<option value="{{ nestedChoice }}"{% if form.choiceSelected(nestedChoice) %} selected="selected"{% endif %}>{{ nestedLabel }}</option>
{% endfor %}
</optgroup>
{% else %}
<option value="{{ choice }}"{% if context.choiceSelected(choice) %} selected="selected"{% endif %}>{{ label }}</option>
<option value="{{ choice }}"{% if form.choiceSelected(choice) %} selected="selected"{% endif %}>{{ label }}</option>
{% endif %}
{% endfor %}
{% endspaceless %}
@ -104,7 +104,7 @@
{% spaceless %}
{% if expanded %}
<div {{ block('attributes') }}>
{% for choice, child in context %}
{% for choice, child in form %}
{{ form_widget(child) }}
{{ form_label(child) }}
{% endfor %}
@ -141,10 +141,10 @@
{% block datetime__widget %}
{% spaceless %}
<div {{ block('attributes') }}>
{{ form_errors(context.date) }}
{{ form_errors(context.time) }}
{{ form_widget(context.date) }}
{{ form_widget(context.time) }}
{{ form_errors(form.date) }}
{{ form_errors(form.time) }}
{{ form_widget(form.date) }}
{{ form_widget(form.time) }}
</div>
{% endspaceless %}
{% endblock datetime__widget %}
@ -156,9 +156,9 @@
{% else %}
<div {{ block('attributes') }}>
{{ date_pattern|replace({
'{{ year }}': form_widget(context.year),
'{{ month }}': form_widget(context.month),
'{{ day }}': form_widget(context.day),
'{{ year }}': form_widget(form.year),
'{{ month }}': form_widget(form.month),
'{{ day }}': form_widget(form.day),
})|raw }}
</div>
{% endif %}
@ -168,7 +168,7 @@
{% block time__widget %}
{% spaceless %}
<div {{ block('attributes') }}>
{{ form_widget(context.hour, { 'size': '1' }) }}:{{ form_widget(context.minute, { 'size': '1' }) }}{% if with_seconds %}:{{ form_widget(context.second, { 'size': '1' }) }}{% endif %}
{{ form_widget(form.hour, { 'size': '1' }) }}:{{ form_widget(form.minute, { 'size': '1' }) }}{% if with_seconds %}:{{ form_widget(form.second, { 'size': '1' }) }}{% endif %}
</div>
{% endspaceless %}
{% endblock time__widget %}
@ -211,9 +211,9 @@
{% block file__widget %}
{% spaceless %}
<div {{ block('attributes') }}>
{{ form_widget(context.file) }}
{{ form_widget(context.token) }}
{{ form_widget(context.name) }}
{{ form_widget(form.file) }}
{{ form_widget(form.token) }}
{{ form_widget(form.name) }}
</div>
{% endspaceless %}
{% endblock file__widget %}
@ -234,9 +234,9 @@
{% block field__row %}
{% spaceless %}
<div>
{{ form_label(context) }}
{{ form_errors(context) }}
{{ form_widget(context) }}
{{ form_label(form) }}
{{ form_errors(form) }}
{{ form_widget(form) }}
</div>
{% endspaceless %}
{% endblock field__row %}
@ -245,7 +245,7 @@
{% spaceless %}
<div {{ block('attributes') }}>
{{ block('field__rows') }}
{{ form_rest(context) }}
{{ form_rest(form) }}
</div>
{% endspaceless %}
{% endblock form__widget %}

View File

@ -4,11 +4,11 @@
{% spaceless %}
<tr>
<td>
{{ form_label(context) }}
{{ form_label(form) }}
</td>
<td>
{{ form_errors(context) }}
{{ form_widget(context) }}
{{ form_errors(form) }}
{{ form_widget(form) }}
</td>
</tr>
{% endspaceless %}
@ -30,7 +30,7 @@
{% spaceless %}
<tr style="display: none">
<td colspan="2">
{{ form_widget(context) }}
{{ form_widget(form) }}
</td>
</tr>
{% endspaceless %}
@ -46,7 +46,7 @@
{% spaceless %}
<table {{ block('attributes') }}>
{{ block('field__rows') }}
{{ form_rest(context) }}
{{ form_rest(form) }}
</table>
{% endspaceless %}
{% endblock form__widget %}

View File

@ -26,7 +26,7 @@ use Symfony\Component\Form\DataTransformer\DataTransformerInterface;
use Symfony\Component\Form\DataTransformer\TransformationFailedException;
use Symfony\Component\Form\DataMapper\DataMapperInterface;
use Symfony\Component\Form\Validator\FormValidatorInterface;
use Symfony\Component\Form\TemplateContext;
use Symfony\Component\Form\FormView;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
@ -832,9 +832,9 @@ class Form implements \IteratorAggregate, FormInterface
return $value;
}
public function getContext()
public function getView()
{
return new TemplateContext($this);
return new FormView($this);
}
/**

View File

@ -119,5 +119,5 @@ interface FormInterface extends \ArrayAccess, \Traversable, \Countable
function isRoot();
function getContext();
function getView();
}

View File

@ -14,7 +14,7 @@ namespace Symfony\Component\Form;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\Form\Util\ChoiceUtil;
class TemplateContext implements \ArrayAccess, \IteratorAggregate
class FormView implements \ArrayAccess, \IteratorAggregate
{
private $vars = array(
'value' => null,
@ -43,10 +43,10 @@ class TemplateContext implements \ArrayAccess, \IteratorAggregate
$types = (array) $form->getTypes();
$children = array();
$this->setVar('context', $this);
$this->setVar('form', $this);
foreach ($types as $type) {
$type->buildContext($this, $form);
$type->buildView($this, $form);
}
foreach ($form as $key => $child) {
@ -56,7 +56,7 @@ class TemplateContext implements \ArrayAccess, \IteratorAggregate
$this->setChildren($children);
foreach ($types as $type) {
$type->buildContextBottomUp($this, $form);
$type->buildViewBottomUp($this, $form);
}
}

View File

@ -14,7 +14,7 @@ namespace Symfony\Component\Form\Type;
use Symfony\Component\Form\FormBuilder;
use Symfony\Component\Form\FormFactoryInterface;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\Form\TemplateContext;
use Symfony\Component\Form\FormView;
abstract class AbstractType implements FormTypeInterface
{
@ -22,11 +22,11 @@ abstract class AbstractType implements FormTypeInterface
{
}
public function buildContext(TemplateContext $context, FormInterface $form)
public function buildView(FormView $view, FormInterface $form)
{
}
public function buildContextBottomUp(TemplateContext $context, FormInterface $form)
public function buildViewBottomUp(FormView $view, FormInterface $form)
{
}

View File

@ -14,7 +14,7 @@ namespace Symfony\Component\Form\Type;
use Symfony\Component\Form\FormBuilder;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\Form\DataTransformer\BooleanToStringTransformer;
use Symfony\Component\Form\TemplateContext;
use Symfony\Component\Form\FormView;
class CheckboxType extends AbstractType
{
@ -24,10 +24,10 @@ class CheckboxType extends AbstractType
->setAttribute('value', $options['value']);
}
public function buildContext(TemplateContext $context, FormInterface $form)
public function buildView(FormView $view, FormInterface $form)
{
$context->setVar('value', $form->getAttribute('value'));
$context->setVar('checked', (bool)$form->getData());
$view->setVar('value', $form->getAttribute('value'));
$view->setVar('checked', (bool)$form->getData());
}
public function getDefaultOptions(array $options)

View File

@ -17,7 +17,7 @@ use Symfony\Component\Form\Exception\FormException;
use Symfony\Component\Form\Exception\UnexpectedTypeException;
use Symfony\Component\Form\ChoiceList\ArrayChoiceList;
use Symfony\Component\Form\EventListener\FixRadioInputListener;
use Symfony\Component\Form\TemplateContext;
use Symfony\Component\Form\FormView;
use Symfony\Component\Form\DataTransformer\ScalarToChoiceTransformer;
use Symfony\Component\Form\DataTransformer\ScalarToBooleanChoicesTransformer;
use Symfony\Component\Form\DataTransformer\ArrayToChoicesTransformer;
@ -70,23 +70,23 @@ class ChoiceType extends AbstractType
}
public function buildContext(TemplateContext $context, FormInterface $form)
public function buildView(FormView $view, FormInterface $form)
{
$choices = $form->getAttribute('choice_list')->getChoices();
$preferred = array_flip($form->getAttribute('preferred_choices'));
$context->setVar('multiple', $form->getAttribute('multiple'));
$context->setVar('expanded', $form->getAttribute('expanded'));
$context->setVar('preferred_choices', array_intersect_key($choices, $preferred));
$context->setVar('choices', array_diff_key($choices, $preferred));
$context->setVar('separator', '-------------------');
$context->setVar('empty_value', '');
$view->setVar('multiple', $form->getAttribute('multiple'));
$view->setVar('expanded', $form->getAttribute('expanded'));
$view->setVar('preferred_choices', array_intersect_key($choices, $preferred));
$view->setVar('choices', array_diff_key($choices, $preferred));
$view->setVar('separator', '-------------------');
$view->setVar('empty_value', '');
if ($context->getVar('multiple') && !$context->getVar('expanded')) {
if ($view->getVar('multiple') && !$view->getVar('expanded')) {
// Add "[]" to the name in case a select tag with multiple options is
// displayed. Otherwise only one of the selected options is sent in the
// POST request.
$context->setVar('name', $context->getVar('name').'[]');
$view->setVar('name', $view->getVar('name').'[]');
}
}

View File

@ -15,7 +15,7 @@ use Symfony\Component\Form\FormInterface;
use Symfony\Component\Form\FormBuilder;
use Symfony\Component\Form\ChoiceList\PaddedChoiceList;
use Symfony\Component\Form\ChoiceList\MonthChoiceList;
use Symfony\Component\Form\TemplateContext;
use Symfony\Component\Form\FormView;
use Symfony\Component\Form\DataTransformer\DateTimeToLocalizedStringTransformer;
use Symfony\Component\Form\DataTransformer\DateTimeToArrayTransformer;
use Symfony\Component\Form\DataTransformer\DateTimeToStringTransformer;
@ -77,11 +77,11 @@ class DateType extends AbstractType
->setAttribute('widget', $options['widget']);
}
public function buildContextBottomUp(TemplateContext $context, FormInterface $form)
public function buildViewBottomUp(FormView $view, FormInterface $form)
{
$context->setVar('widget', $form->getAttribute('widget'));
$view->setVar('widget', $form->getAttribute('widget'));
if ($context->hasChildren()) {
if ($view->hasChildren()) {
$pattern = $form->getAttribute('formatter')->getPattern();
@ -94,7 +94,7 @@ class DateType extends AbstractType
$pattern = '{{ year }}-{{ month }}-{{ day }}';
}
$context->setVar('date_pattern', $pattern);
$view->setVar('date_pattern', $pattern);
}
}

View File

@ -14,7 +14,7 @@ namespace Symfony\Component\Form\Type;
use Symfony\Component\Form\Util\PropertyPath;
use Symfony\Component\Form\FormBuilder;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\Form\TemplateContext;
use Symfony\Component\Form\FormView;
use Symfony\Component\Form\EventListener\TrimListener;
use Symfony\Component\Form\Validator\DefaultValidator;
use Symfony\Component\Form\Validator\DelegatingValidator;
@ -64,11 +64,11 @@ class FieldType extends AbstractType
}
}
public function buildContext(TemplateContext $context, FormInterface $form)
public function buildView(FormView $view, FormInterface $form)
{
if ($context->hasParent()) {
$parentId = $context->getParent()->getVar('id');
$parentName = $context->getParent()->getVar('name');
if ($view->hasParent()) {
$parentId = $view->getParent()->getVar('id');
$parentName = $view->getParent()->getVar('name');
$id = sprintf('%s_%s', $parentId, $form->getName());
$name = sprintf('%s[%s]', $parentName, $form->getName());
} else {
@ -76,24 +76,24 @@ class FieldType extends AbstractType
$name = $form->getName();
}
$context->setVar('id', $id);
$context->setVar('name', $name);
$context->setVar('errors', $form->getErrors());
$context->setVar('value', $form->getClientData());
$context->setVar('read_only', $form->isReadOnly());
$context->setVar('required', $form->isRequired());
$context->setVar('class', null);
$context->setVar('max_length', $form->getAttribute('max_length'));
$context->setVar('size', null);
$context->setVar('label', ucfirst(strtolower(str_replace('_', ' ', $form->getName()))));
$context->setVar('multipart', false);
$context->setVar('attr', array());
$view->setVar('id', $id);
$view->setVar('name', $name);
$view->setVar('errors', $form->getErrors());
$view->setVar('value', $form->getClientData());
$view->setVar('read_only', $form->isReadOnly());
$view->setVar('required', $form->isRequired());
$view->setVar('class', null);
$view->setVar('max_length', $form->getAttribute('max_length'));
$view->setVar('size', null);
$view->setVar('label', ucfirst(strtolower(str_replace('_', ' ', $form->getName()))));
$view->setVar('multipart', false);
$view->setVar('attr', array());
$types = array();
foreach (array_reverse((array) $form->getTypes()) as $type) {
$types[] = $type->getName();
}
$context->setVar('types', $types);
$view->setVar('types', $types);
}
public function getDefaultOptions(array $options)

View File

@ -19,7 +19,7 @@ use Symfony\Component\Form\DataTransformer\DataTransformerChain;
use Symfony\Component\Form\DataTransformer\ReversedTransformer;
use Symfony\Component\Form\DataTransformer\FileToStringTransformer;
use Symfony\Component\Form\DataTransformer\FileToArrayTransformer;
use Symfony\Component\Form\TemplateContext;
use Symfony\Component\Form\FormView;
use Symfony\Component\HttpFoundation\File\TemporaryStorage;
class FileType extends AbstractType
@ -48,10 +48,10 @@ class FileType extends AbstractType
->add('name', 'hidden');
}
public function buildContextBottomUp(TemplateContext $context, FormInterface $form)
public function buildViewBottomUp(FormView $view, FormInterface $form)
{
$context->setVar('multipart', true);
$context['file']->setVar('type', 'file');
$view->setVar('multipart', true);
$view['file']->setVar('type', 'file');
}
public function getDefaultOptions(array $options)

View File

@ -13,7 +13,7 @@ namespace Symfony\Component\Form\Type;
use Symfony\Component\Form\FormBuilder;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\Form\TemplateContext;
use Symfony\Component\Form\FormView;
use Symfony\Component\Form\CsrfProvider\CsrfProviderInterface;
use Symfony\Component\Form\DataMapper\PropertyPathMapper;
use Symfony\Component\EventDispatcher\EventDispatcher;
@ -36,18 +36,18 @@ class FormType extends AbstractType
}
}
public function buildContextBottomUp(TemplateContext $context, FormInterface $form)
public function buildViewBottomUp(FormView $view, FormInterface $form)
{
$multipart = false;
foreach ($context as $child) {
foreach ($view as $child) {
if ($child->getVar('multipart')) {
$multipart = true;
break;
}
}
$context->setVar('multipart', $multipart);
$view->setVar('multipart', $multipart);
}
public function getDefaultOptions(array $options)

View File

@ -13,15 +13,15 @@ namespace Symfony\Component\Form\Type;
use Symfony\Component\Form\FormBuilder;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\Form\TemplateContext;
use Symfony\Component\Form\FormView;
interface FormTypeInterface
{
function buildForm(FormBuilder $builder, array $options);
function buildContext(TemplateContext $context, FormInterface $form);
function buildView(FormView $view, FormInterface $form);
function buildContextBottomUp(TemplateContext $context, FormInterface $form);
function buildViewBottomUp(FormView $view, FormInterface $form);
function createBuilder($name, array $options);

View File

@ -14,7 +14,7 @@ namespace Symfony\Component\Form\Type;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\Form\FormBuilder;
use Symfony\Component\Form\DataTransformer\MoneyToLocalizedStringTransformer;
use Symfony\Component\Form\TemplateContext;
use Symfony\Component\Form\FormView;
class MoneyType extends AbstractType
{
@ -26,9 +26,9 @@ class MoneyType extends AbstractType
->setAttribute('currency', $options['currency']);
}
public function buildContext(TemplateContext $context, FormInterface $form)
public function buildView(FormView $view, FormInterface $form)
{
$context->setVar('money_pattern', self::getPattern($form->getAttribute('currency')));
$view->setVar('money_pattern', self::getPattern($form->getAttribute('currency')));
}
public function getDefaultOptions(array $options)

View File

@ -13,7 +13,7 @@ namespace Symfony\Component\Form\Type;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\Form\FormBuilder;
use Symfony\Component\Form\TemplateContext;
use Symfony\Component\Form\FormView;
class PasswordType extends AbstractType
{
@ -22,10 +22,10 @@ class PasswordType extends AbstractType
$builder->setAttribute('always_empty', $options['always_empty']);
}
public function buildContext(TemplateContext $context, FormInterface $form)
public function buildView(FormView $view, FormInterface $form)
{
if ($form->getAttribute('always_empty') || !$form->isBound()) {
$context->setVar('value', '');
$view->setVar('value', '');
}
}

View File

@ -14,7 +14,7 @@ namespace Symfony\Component\Form\Type;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\Form\FormBuilder;
use Symfony\Component\Form\DataTransformer\BooleanToStringTransformer;
use Symfony\Component\Form\TemplateContext;
use Symfony\Component\Form\FormView;
class RadioType extends AbstractType
{
@ -24,13 +24,13 @@ class RadioType extends AbstractType
->setAttribute('value', $options['value']);
}
public function buildContext(TemplateContext $context, FormInterface $form)
public function buildView(FormView $view, FormInterface $form)
{
$context->setVar('value', $form->getAttribute('value'));
$context->setVar('checked', (bool)$form->getData());
$view->setVar('value', $form->getAttribute('value'));
$view->setVar('checked', (bool)$form->getData());
if ($context->hasParent()) {
$context->setVar('name', $context->getParent()->getVar('name'));
if ($view->hasParent()) {
$view->setVar('name', $view->getParent()->getVar('name'));
}
}

View File

@ -13,7 +13,7 @@ namespace Symfony\Component\Form\Type;
use Symfony\Component\Form\FormBuilder;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\Form\TemplateContext;
use Symfony\Component\Form\FormView;
class TextType extends AbstractType
{
@ -22,9 +22,9 @@ class TextType extends AbstractType
$builder->setAttribute('max_length', $options['max_length']);
}
public function buildContext(TemplateContext $context, FormInterface $form)
public function buildView(FormView $view, FormInterface $form)
{
$context->setVar('max_length', $form->getAttribute('max_length'));
$view->setVar('max_length', $form->getAttribute('max_length'));
}
public function getParent(array $options)

View File

@ -18,7 +18,7 @@ use Symfony\Component\Form\DataTransformer\ReversedTransformer;
use Symfony\Component\Form\DataTransformer\DateTimeToStringTransformer;
use Symfony\Component\Form\DataTransformer\DateTimeToTimestampTransformer;
use Symfony\Component\Form\DataTransformer\DateTimeToArrayTransformer;
use Symfony\Component\Form\TemplateContext;
use Symfony\Component\Form\FormView;
class TimeType extends AbstractType
{
@ -71,10 +71,10 @@ class TimeType extends AbstractType
->setAttribute('with_seconds', $options['with_seconds']);
}
public function buildContext(TemplateContext $context, FormInterface $form)
public function buildView(FormView $view, FormInterface $form)
{
$context->setVar('widget', $form->getAttribute('widget'));
$context->setVar('with_seconds', $form->getAttribute('with_seconds'));
$view->setVar('widget', $form->getAttribute('widget'));
$view->setVar('with_seconds', $form->getAttribute('with_seconds'));
}
public function getDefaultOptions(array $options)

View File

@ -14,7 +14,7 @@ namespace Symfony\Tests\Bridge\Twig\Extension;
require_once __DIR__.'/Fixtures/StubTranslator.php';
require_once __DIR__.'/Fixtures/StubFilesystemLoader.php';
use Symfony\Component\Form\TemplateContext;
use Symfony\Component\Form\FormView;
use Symfony\Bridge\Twig\Extension\FormExtension;
use Symfony\Bridge\Twig\Extension\TranslationExtension;
use Symfony\Tests\Component\Form\AbstractDivLayoutTest;
@ -40,33 +40,33 @@ class FormExtensionDivLayoutTest extends AbstractDivLayoutTest
$this->extension->initRuntime($environment);
}
protected function renderEnctype(TemplateContext $context)
protected function renderEnctype(FormView $view)
{
return (string)$this->extension->renderEnctype($context);
return (string)$this->extension->renderEnctype($view);
}
protected function renderLabel(TemplateContext $context, $label = null)
protected function renderLabel(FormView $view, $label = null)
{
return (string)$this->extension->renderLabel($context, $label);
return (string)$this->extension->renderLabel($view, $label);
}
protected function renderErrors(TemplateContext $context)
protected function renderErrors(FormView $view)
{
return (string)$this->extension->renderErrors($context);
return (string)$this->extension->renderErrors($view);
}
protected function renderWidget(TemplateContext $context, array $vars = array())
protected function renderWidget(FormView $view, array $vars = array())
{
return (string)$this->extension->renderWidget($context, $vars);
return (string)$this->extension->renderWidget($view, $vars);
}
protected function renderRow(TemplateContext $context, array $vars = array())
protected function renderRow(FormView $view, array $vars = array())
{
return (string)$this->extension->renderRow($context, $vars);
return (string)$this->extension->renderRow($view, $vars);
}
protected function renderRest(TemplateContext $context, array $vars = array())
protected function renderRest(FormView $view, array $vars = array())
{
return (string)$this->extension->renderRest($context, $vars);
return (string)$this->extension->renderRest($view, $vars);
}
}

View File

@ -14,7 +14,7 @@ namespace Symfony\Tests\Bridge\Twig\Extension;
require_once __DIR__.'/Fixtures/StubTranslator.php';
require_once __DIR__.'/Fixtures/StubFilesystemLoader.php';
use Symfony\Component\Form\TemplateContext;
use Symfony\Component\Form\FormView;
use Symfony\Bridge\Twig\Extension\FormExtension;
use Symfony\Bridge\Twig\Extension\TranslationExtension;
use Symfony\Tests\Component\Form\AbstractTableLayoutTest;
@ -40,33 +40,33 @@ class FormExtensionTableLayoutTest extends AbstractTableLayoutTest
$this->extension->initRuntime($environment);
}
protected function renderEnctype(TemplateContext $context)
protected function renderEnctype(FormView $view)
{
return (string)$this->extension->renderEnctype($context);
return (string)$this->extension->renderEnctype($view);
}
protected function renderLabel(TemplateContext $context, $label = null)
protected function renderLabel(FormView $view, $label = null)
{
return (string)$this->extension->renderLabel($context, $label);
return (string)$this->extension->renderLabel($view, $label);
}
protected function renderErrors(TemplateContext $context)
protected function renderErrors(FormView $view)
{
return (string)$this->extension->renderErrors($context);
return (string)$this->extension->renderErrors($view);
}
protected function renderWidget(TemplateContext $context, array $vars = array())
protected function renderWidget(FormView $view, array $vars = array())
{
return (string)$this->extension->renderWidget($context, $vars);
return (string)$this->extension->renderWidget($view, $vars);
}
protected function renderRow(TemplateContext $context, array $vars = array())
protected function renderRow(FormView $view, array $vars = array())
{
return (string)$this->extension->renderRow($context, $vars);
return (string)$this->extension->renderRow($view, $vars);
}
protected function renderRest(TemplateContext $context, array $vars = array())
protected function renderRest(FormView $view, array $vars = array())
{
return (string)$this->extension->renderRest($context, $vars);
return (string)$this->extension->renderRest($view, $vars);
}
}

View File

@ -19,8 +19,8 @@ abstract class AbstractDivLayoutTest extends AbstractLayoutTest
{
$form = $this->factory->create('text', 'name');
$form->addError(new FormError('Error!'));
$context = $form->getContext();
$html = $this->renderRow($context);
$view = $form->getView();
$html = $this->renderRow($view);
$this->assertMatchesXpath($html,
'/div
@ -39,8 +39,8 @@ abstract class AbstractDivLayoutTest extends AbstractLayoutTest
{
$form = $this->factory->create('repeated', 'name');
$form->addError(new FormError('Error!'));
$context = $form->getContext();
$html = $this->renderRow($context);
$view = $form->getView();
$html = $this->renderRow($view);
$this->assertMatchesXpath($html,
'/ul
@ -62,23 +62,23 @@ abstract class AbstractDivLayoutTest extends AbstractLayoutTest
public function testRest()
{
$context = $this->factory->createBuilder('form', 'name')
$view = $this->factory->createBuilder('form', 'name')
->add('field1', 'text')
->add('field2', 'repeated')
->add('field3', 'text')
->add('field4', 'text')
->getForm()
->getContext();
->getView();
// Render field2 row -> does not implicitely call renderWidget because
// it is a repeated field!
$this->renderRow($context['field2']);
$this->renderRow($view['field2']);
// Render field3 widget
$this->renderWidget($context['field3']);
$this->renderWidget($view['field3']);
// Rest should only contain field1 and field4
$html = $this->renderRest($context);
$html = $this->renderRest($view);
$this->assertMatchesXpath($html,
'/input
@ -108,7 +108,7 @@ abstract class AbstractDivLayoutTest extends AbstractLayoutTest
'data' => array('a', 'b'),
));
$this->assertWidgetMatchesXpath($form->getContext(), array(),
$this->assertWidgetMatchesXpath($form->getView(), array(),
'/div
[
./div[./input[@type="text"][@value="a"]]
@ -126,7 +126,7 @@ abstract class AbstractDivLayoutTest extends AbstractLayoutTest
->add('lastName', 'text')
->getForm();
$this->assertWidgetMatchesXpath($form->getContext(), array(),
$this->assertWidgetMatchesXpath($form->getView(), array(),
'/div
[
./input[@type="hidden"][@id="name__token"]
@ -153,7 +153,7 @@ abstract class AbstractDivLayoutTest extends AbstractLayoutTest
'data' => 'foobar',
));
$this->assertWidgetMatchesXpath($form->getContext(), array(),
$this->assertWidgetMatchesXpath($form->getView(), array(),
'/div
[
./div

View File

@ -12,7 +12,7 @@
namespace Symfony\Tests\Component\Form;
use Symfony\Component\Form\FormError;
use Symfony\Component\Form\TemplateContext;
use Symfony\Component\Form\FormView;
use Symfony\Component\Form\FormFactory;
use Symfony\Component\Form\CsrfProvider\DefaultCsrfProvider;
use Symfony\Component\Form\Type\Loader\DefaultTypeLoader;
@ -73,9 +73,9 @@ abstract class AbstractLayoutTest extends \PHPUnit_Framework_TestCase
}
}
protected function assertWidgetMatchesXpath(TemplateContext $context, array $vars, $xpath)
protected function assertWidgetMatchesXpath(FormView $view, array $vars, $xpath)
{
$html = $this->renderWidget($context, array_merge(array(
$html = $this->renderWidget($view, array_merge(array(
'id' => 'my_id',
'attr' => array('class' => 'my_class'),
), $vars));
@ -87,17 +87,17 @@ abstract class AbstractLayoutTest extends \PHPUnit_Framework_TestCase
$this->assertMatchesXpath($html, $xpath);
}
abstract protected function renderEnctype(TemplateContext $context);
abstract protected function renderEnctype(FormView $view);
abstract protected function renderLabel(TemplateContext $context, $label = null);
abstract protected function renderLabel(FormView $view, $label = null);
abstract protected function renderErrors(TemplateContext $context);
abstract protected function renderErrors(FormView $view);
abstract protected function renderWidget(TemplateContext $context, array $vars = array());
abstract protected function renderWidget(FormView $view, array $vars = array());
abstract protected function renderRow(TemplateContext $context, array $vars = array());
abstract protected function renderRow(FormView $view, array $vars = array());
abstract protected function renderRest(TemplateContext $context, array $vars = array());
abstract protected function renderRest(FormView $view, array $vars = array());
public function testEnctype()
{
@ -105,7 +105,7 @@ abstract class AbstractLayoutTest extends \PHPUnit_Framework_TestCase
->add('file', 'file')
->getForm();
$this->assertEquals('enctype="multipart/form-data"', $this->renderEnctype($form->getContext()));
$this->assertEquals('enctype="multipart/form-data"', $this->renderEnctype($form->getView()));
}
public function testNoEnctype()
@ -114,13 +114,13 @@ abstract class AbstractLayoutTest extends \PHPUnit_Framework_TestCase
->add('text', 'text')
->getForm();
$this->assertEquals('', $this->renderEnctype($form->getContext()));
$this->assertEquals('', $this->renderEnctype($form->getView()));
}
public function testLabel()
{
$form = $this->factory->create('text', 'name');
$html = $this->renderLabel($form->getContext());
$html = $this->renderLabel($form->getView());
$this->assertMatchesXpath($html,
'/label
@ -133,7 +133,7 @@ abstract class AbstractLayoutTest extends \PHPUnit_Framework_TestCase
public function testLabelWithCustomText()
{
$form = $this->factory->create('text', 'name');
$html = $this->renderLabel($form->getContext(), 'Custom label');
$html = $this->renderLabel($form->getView(), 'Custom label');
$this->assertMatchesXpath($html,
'/label
@ -148,8 +148,8 @@ abstract class AbstractLayoutTest extends \PHPUnit_Framework_TestCase
$form = $this->factory->create('text', 'name');
$form->addError(new FormError('Error 1'));
$form->addError(new FormError('Error 2'));
$context = $form->getContext();
$html = $this->renderErrors($context);
$view = $form->getView();
$html = $this->renderErrors($view);
$this->assertMatchesXpath($html,
'/ul
@ -168,7 +168,7 @@ abstract class AbstractLayoutTest extends \PHPUnit_Framework_TestCase
'data' => true,
));
$this->assertWidgetMatchesXpath($form->getContext(), array(),
$this->assertWidgetMatchesXpath($form->getView(), array(),
'/input
[@type="checkbox"]
[@name="name"]
@ -185,7 +185,7 @@ abstract class AbstractLayoutTest extends \PHPUnit_Framework_TestCase
'data' => true,
));
$this->assertWidgetMatchesXpath($form->getContext(), array(),
$this->assertWidgetMatchesXpath($form->getView(), array(),
'/input
[@type="checkbox"]
[@name="name"]
@ -201,7 +201,7 @@ abstract class AbstractLayoutTest extends \PHPUnit_Framework_TestCase
'data' => false,
));
$this->assertWidgetMatchesXpath($form->getContext(), array(),
$this->assertWidgetMatchesXpath($form->getView(), array(),
'/input
[@type="checkbox"]
[@name="name"]
@ -219,7 +219,7 @@ abstract class AbstractLayoutTest extends \PHPUnit_Framework_TestCase
'expanded' => false,
));
$this->assertWidgetMatchesXpath($form->getContext(), array(),
$this->assertWidgetMatchesXpath($form->getView(), array(),
'/select
[@name="name"]
[
@ -241,7 +241,7 @@ abstract class AbstractLayoutTest extends \PHPUnit_Framework_TestCase
'expanded' => false,
));
$this->assertWidgetMatchesXpath($form->getContext(), array('separator' => '-- sep --'),
$this->assertWidgetMatchesXpath($form->getView(), array('separator' => '-- sep --'),
'/select
[@name="name"]
[
@ -264,7 +264,7 @@ abstract class AbstractLayoutTest extends \PHPUnit_Framework_TestCase
'expanded' => false,
));
$this->assertWidgetMatchesXpath($form->getContext(), array(),
$this->assertWidgetMatchesXpath($form->getView(), array(),
'/select
[@name="name"]
[
@ -289,7 +289,7 @@ abstract class AbstractLayoutTest extends \PHPUnit_Framework_TestCase
'expanded' => false,
));
$this->assertWidgetMatchesXpath($form->getContext(), array(),
$this->assertWidgetMatchesXpath($form->getView(), array(),
'/select
[@name="name"]
[./optgroup[@label="Group1"]
@ -317,7 +317,7 @@ abstract class AbstractLayoutTest extends \PHPUnit_Framework_TestCase
'expanded' => false,
));
$this->assertWidgetMatchesXpath($form->getContext(), array(),
$this->assertWidgetMatchesXpath($form->getView(), array(),
'/select
[@name="name[]"]
[@multiple="multiple"]
@ -340,7 +340,7 @@ abstract class AbstractLayoutTest extends \PHPUnit_Framework_TestCase
'expanded' => false,
));
$this->assertWidgetMatchesXpath($form->getContext(), array(),
$this->assertWidgetMatchesXpath($form->getView(), array(),
'/select
[@name="name[]"]
[@multiple="multiple"]
@ -362,7 +362,7 @@ abstract class AbstractLayoutTest extends \PHPUnit_Framework_TestCase
'expanded' => true,
));
$this->assertWidgetMatchesXpath($form->getContext(), array(),
$this->assertWidgetMatchesXpath($form->getView(), array(),
'/div
[
./input[@type="radio"][@name="name"][@id="name_a"][@checked]
@ -384,7 +384,7 @@ abstract class AbstractLayoutTest extends \PHPUnit_Framework_TestCase
'expanded' => true,
));
$this->assertWidgetMatchesXpath($form->getContext(), array(),
$this->assertWidgetMatchesXpath($form->getView(), array(),
'/div
[
./input[@type="checkbox"][@name="name[a]"][@id="name_a"][@checked]
@ -405,7 +405,7 @@ abstract class AbstractLayoutTest extends \PHPUnit_Framework_TestCase
'data' => 'AT',
));
$this->assertWidgetMatchesXpath($form->getContext(), array(),
$this->assertWidgetMatchesXpath($form->getView(), array(),
'/select
[@name="name"]
[./option[@value="AT"][@selected="selected"][.="Austria"]]
@ -418,7 +418,7 @@ abstract class AbstractLayoutTest extends \PHPUnit_Framework_TestCase
{
$form = $this->factory->create('csrf', 'name');
$this->assertWidgetMatchesXpath($form->getContext(), array(),
$this->assertWidgetMatchesXpath($form->getView(), array(),
'/input
[@type="hidden"]
[string-length(@value)>=40]
@ -434,7 +434,7 @@ abstract class AbstractLayoutTest extends \PHPUnit_Framework_TestCase
'with_seconds' => false,
));
$this->assertWidgetMatchesXpath($form->getContext(), array(),
$this->assertWidgetMatchesXpath($form->getView(), array(),
'/div
[
./div
@ -474,7 +474,7 @@ abstract class AbstractLayoutTest extends \PHPUnit_Framework_TestCase
'with_seconds' => true,
));
$this->assertWidgetMatchesXpath($form->getContext(), array(),
$this->assertWidgetMatchesXpath($form->getView(), array(),
'/div
[
./div
@ -517,7 +517,7 @@ abstract class AbstractLayoutTest extends \PHPUnit_Framework_TestCase
'widget' => 'choice',
));
$this->assertWidgetMatchesXpath($form->getContext(), array(),
$this->assertWidgetMatchesXpath($form->getView(), array(),
'/div
[
./select
@ -543,7 +543,7 @@ abstract class AbstractLayoutTest extends \PHPUnit_Framework_TestCase
'widget' => 'text',
));
$this->assertWidgetMatchesXpath($form->getContext(), array(),
$this->assertWidgetMatchesXpath($form->getView(), array(),
'/input
[@type="text"]
[@name="name"]
@ -556,7 +556,7 @@ abstract class AbstractLayoutTest extends \PHPUnit_Framework_TestCase
{
$form = $this->factory->create('file', 'name');
$this->assertWidgetMatchesXpath($form->getContext(), array(),
$this->assertWidgetMatchesXpath($form->getView(), array(),
'/div
[
./input[@type="file"][@id="name_file"]
@ -574,7 +574,7 @@ abstract class AbstractLayoutTest extends \PHPUnit_Framework_TestCase
'data' => 'foobar',
));
$this->assertWidgetMatchesXpath($form->getContext(), array(),
$this->assertWidgetMatchesXpath($form->getView(), array(),
'/input
[@type="hidden"]
[@name="name"]
@ -589,7 +589,7 @@ abstract class AbstractLayoutTest extends \PHPUnit_Framework_TestCase
'data' => '123',
));
$this->assertWidgetMatchesXpath($form->getContext(), array(),
$this->assertWidgetMatchesXpath($form->getView(), array(),
'/input
[@type="number"]
[@name="name"]
@ -604,7 +604,7 @@ abstract class AbstractLayoutTest extends \PHPUnit_Framework_TestCase
'data' => 'de',
));
$this->assertWidgetMatchesXpath($form->getContext(), array(),
$this->assertWidgetMatchesXpath($form->getView(), array(),
'/select
[@name="name"]
[./option[@value="de"][@selected="selected"][.="German"]]
@ -619,7 +619,7 @@ abstract class AbstractLayoutTest extends \PHPUnit_Framework_TestCase
'data' => 'de_AT',
));
$this->assertWidgetMatchesXpath($form->getContext(), array(),
$this->assertWidgetMatchesXpath($form->getView(), array(),
'/select
[@name="name"]
[./option[@value="de_AT"][@selected="selected"][.="German (Austria)"]]
@ -635,7 +635,7 @@ abstract class AbstractLayoutTest extends \PHPUnit_Framework_TestCase
'currency' => 'EUR',
));
$this->assertWidgetMatchesXpath($form->getContext(), array(),
$this->assertWidgetMatchesXpath($form->getView(), array(),
'/input
[@type="text"]
[@name="name"]
@ -651,7 +651,7 @@ abstract class AbstractLayoutTest extends \PHPUnit_Framework_TestCase
'data' => 1234.56,
));
$this->assertWidgetMatchesXpath($form->getContext(), array(),
$this->assertWidgetMatchesXpath($form->getView(), array(),
'/input
[@type="text"]
[@name="name"]
@ -666,7 +666,7 @@ abstract class AbstractLayoutTest extends \PHPUnit_Framework_TestCase
'data' => 'Pa$sW0rD',
));
$this->assertWidgetMatchesXpath($form->getContext(), array(),
$this->assertWidgetMatchesXpath($form->getView(), array(),
'/input
[@type="password"]
[@name="name"]
@ -682,7 +682,7 @@ abstract class AbstractLayoutTest extends \PHPUnit_Framework_TestCase
'max_length' => 123,
));
$this->assertWidgetMatchesXpath($form->getContext(), array(),
$this->assertWidgetMatchesXpath($form->getView(), array(),
'/input
[@type="password"]
[@name="name"]
@ -698,7 +698,7 @@ abstract class AbstractLayoutTest extends \PHPUnit_Framework_TestCase
'data' => 0.1,
));
$this->assertWidgetMatchesXpath($form->getContext(), array(),
$this->assertWidgetMatchesXpath($form->getView(), array(),
'/input
[@type="text"]
[@name="name"]
@ -714,7 +714,7 @@ abstract class AbstractLayoutTest extends \PHPUnit_Framework_TestCase
'data' => true,
));
$this->assertWidgetMatchesXpath($form->getContext(), array(),
$this->assertWidgetMatchesXpath($form->getView(), array(),
'/input
[@type="radio"]
[@name="name"]
@ -731,7 +731,7 @@ abstract class AbstractLayoutTest extends \PHPUnit_Framework_TestCase
'value' => 'foobar',
));
$this->assertWidgetMatchesXpath($form->getContext(), array(),
$this->assertWidgetMatchesXpath($form->getView(), array(),
'/input
[@type="radio"]
[@name="name"]
@ -747,7 +747,7 @@ abstract class AbstractLayoutTest extends \PHPUnit_Framework_TestCase
'data' => false,
));
$this->assertWidgetMatchesXpath($form->getContext(), array(),
$this->assertWidgetMatchesXpath($form->getView(), array(),
'/input
[@type="radio"]
[@name="name"]
@ -762,7 +762,7 @@ abstract class AbstractLayoutTest extends \PHPUnit_Framework_TestCase
'data' => 'foobar',
));
$this->assertWidgetMatchesXpath($form->getContext(), array(),
$this->assertWidgetMatchesXpath($form->getView(), array(),
'/textarea
[@name="name"]
[.="foobar"]
@ -776,7 +776,7 @@ abstract class AbstractLayoutTest extends \PHPUnit_Framework_TestCase
'data' => 'foobar',
));
$this->assertWidgetMatchesXpath($form->getContext(), array(),
$this->assertWidgetMatchesXpath($form->getView(), array(),
'/input
[@type="text"]
[@name="name"]
@ -793,7 +793,7 @@ abstract class AbstractLayoutTest extends \PHPUnit_Framework_TestCase
'max_length' => 123,
));
$this->assertWidgetMatchesXpath($form->getContext(), array(),
$this->assertWidgetMatchesXpath($form->getView(), array(),
'/input
[@type="text"]
[@name="name"]
@ -811,7 +811,7 @@ abstract class AbstractLayoutTest extends \PHPUnit_Framework_TestCase
'with_seconds' => false,
));
$this->assertWidgetMatchesXpath($form->getContext(), array(),
$this->assertWidgetMatchesXpath($form->getView(), array(),
'/div
[
./select
@ -834,7 +834,7 @@ abstract class AbstractLayoutTest extends \PHPUnit_Framework_TestCase
'with_seconds' => true,
));
$this->assertWidgetMatchesXpath($form->getContext(), array(),
$this->assertWidgetMatchesXpath($form->getView(), array(),
'/div
[
./select
@ -858,7 +858,7 @@ abstract class AbstractLayoutTest extends \PHPUnit_Framework_TestCase
'data' => 'Europe/Vienna',
));
$this->assertWidgetMatchesXpath($form->getContext(), array(),
$this->assertWidgetMatchesXpath($form->getView(), array(),
'/select
[@name="name"]
[./optgroup
@ -877,7 +877,7 @@ abstract class AbstractLayoutTest extends \PHPUnit_Framework_TestCase
'data' => 'http://www.google.com',
));
$this->assertWidgetMatchesXpath($form->getContext(), array(),
$this->assertWidgetMatchesXpath($form->getView(), array(),
'/input
[@type="url"]
[@name="name"]

View File

@ -19,8 +19,8 @@ abstract class AbstractTableLayoutTest extends AbstractLayoutTest
{
$form = $this->factory->create('text', 'name');
$form->addError(new FormError('Error!'));
$context = $form->getContext();
$html = $this->renderRow($context);
$view = $form->getView();
$html = $this->renderRow($view);
$this->assertMatchesXpath($html,
'/tr
@ -42,7 +42,7 @@ abstract class AbstractTableLayoutTest extends AbstractLayoutTest
public function testRepeatedRow()
{
$form = $this->factory->create('repeated', 'name');
$html = $this->renderRow($form->getContext());
$html = $this->renderRow($form->getView());
$this->assertMatchesXpath($html,
'/tr
@ -68,8 +68,8 @@ abstract class AbstractTableLayoutTest extends AbstractLayoutTest
{
$form = $this->factory->create('repeated', 'name');
$form->addError(new FormError('Error!'));
$context = $form->getContext();
$html = $this->renderRow($context);
$view = $form->getView();
$html = $this->renderRow($view);
$this->assertMatchesXpath($html,
'/tr
@ -97,23 +97,23 @@ abstract class AbstractTableLayoutTest extends AbstractLayoutTest
public function testRest()
{
$context = $this->factory->createBuilder('form', 'name')
$view = $this->factory->createBuilder('form', 'name')
->add('field1', 'text')
->add('field2', 'repeated')
->add('field3', 'text')
->add('field4', 'text')
->getForm()
->getContext();
->getView();
// Render field2 row -> does not implicitely call renderWidget because
// it is a repeated field!
$this->renderRow($context['field2']);
$this->renderRow($view['field2']);
// Render field3 widget
$this->renderWidget($context['field3']);
$this->renderWidget($view['field3']);
// Rest should only contain field1 and field4
$html = $this->renderRest($context);
$html = $this->renderRest($view);
$this->assertMatchesXpath($html,
'/tr[@style="display: none"]
@ -149,7 +149,7 @@ abstract class AbstractTableLayoutTest extends AbstractLayoutTest
'data' => array('a', 'b'),
));
$this->assertWidgetMatchesXpath($form->getContext(), array(),
$this->assertWidgetMatchesXpath($form->getView(), array(),
'/table
[
./tr[./td/input[@type="text"][@value="a"]]
@ -162,13 +162,13 @@ abstract class AbstractTableLayoutTest extends AbstractLayoutTest
public function testForm()
{
$context = $this->factory->createBuilder('form', 'name')
$view = $this->factory->createBuilder('form', 'name')
->add('firstName', 'text')
->add('lastName', 'text')
->getForm()
->getContext();
->getView();
$this->assertWidgetMatchesXpath($context, array(),
$this->assertWidgetMatchesXpath($view, array(),
'/table
[
./tr[@style="display: none"]
@ -203,7 +203,7 @@ abstract class AbstractTableLayoutTest extends AbstractLayoutTest
'data' => 'foobar',
));
$this->assertWidgetMatchesXpath($form->getContext(), array(),
$this->assertWidgetMatchesXpath($form->getView(), array(),
'/table
[
./tr

View File

@ -15,29 +15,29 @@ require_once __DIR__.'/TestCase.php';
class CheckboxTypeTest extends TestCase
{
public function testPassValueToContext()
public function testPassValueToView()
{
$form = $this->factory->create('checkbox', 'name', array('value' => 'foobar'));
$context = $form->getContext();
$view = $form->getView();
$this->assertEquals('foobar', $context->getVar('value'));
$this->assertEquals('foobar', $view->getVar('value'));
}
public function testCheckedIfDataTrue()
{
$form = $this->factory->create('checkbox');
$form->setData(true);
$context = $form->getContext();
$view = $form->getView();
$this->assertTrue($context->getVar('checked'));
$this->assertTrue($view->getVar('checked'));
}
public function testNotCheckedIfDataFalse()
{
$form = $this->factory->create('checkbox');
$form->setData(false);
$context = $form->getContext();
$view = $form->getView();
$this->assertFalse($context->getVar('checked'));
$this->assertFalse($view->getVar('checked'));
}
}

View File

@ -216,50 +216,50 @@ class ChoiceTypeTest extends TestCase
$this->factory->create('choice', 'name');
}
public function testPassMultipleToContext()
public function testPassMultipleToView()
{
$form = $this->factory->create('choice', 'name', array(
'multiple' => true,
'choices' => $this->choices,
));
$context = $form->getContext();
$view = $form->getView();
$this->assertTrue($context->getVar('multiple'));
$this->assertTrue($view->getVar('multiple'));
}
public function testPassExpandedToContext()
public function testPassExpandedToView()
{
$form = $this->factory->create('choice', 'name', array(
'expanded' => true,
'choices' => $this->choices,
));
$context = $form->getContext();
$view = $form->getView();
$this->assertTrue($context->getVar('expanded'));
$this->assertTrue($view->getVar('expanded'));
}
public function testPassChoicesToContext()
public function testPassChoicesToView()
{
$choices = array('a' => 'A', 'b' => 'B', 'c' => 'C', 'd' => 'D');
$form = $this->factory->create('choice', 'name', array(
'choices' => $choices,
));
$context = $form->getContext();
$view = $form->getView();
$this->assertSame($choices, $context->getVar('choices'));
$this->assertSame($choices, $view->getVar('choices'));
}
public function testPassPreferredChoicesToContext()
public function testPassPreferredChoicesToView()
{
$choices = array('a' => 'A', 'b' => 'B', 'c' => 'C', 'd' => 'D');
$form = $this->factory->create('choice', 'name', array(
'choices' => $choices,
'preferred_choices' => array('b', 'd'),
));
$context = $form->getContext();
$view = $form->getView();
$this->assertSame(array('a' => 'A', 'c' => 'C'), $context->getVar('choices'));
$this->assertSame(array('b' => 'B', 'd' => 'D'), $context->getVar('preferred_choices'));
$this->assertSame(array('a' => 'A', 'c' => 'C'), $view->getVar('choices'));
$this->assertSame(array('b' => 'B', 'd' => 'D'), $view->getVar('preferred_choices'));
}
public function testAdjustNameForMultipleNonExpanded()
@ -269,8 +269,8 @@ class ChoiceTypeTest extends TestCase
'expanded' => false,
'choices' => $this->choices,
));
$context = $form->getContext();
$view = $form->getView();
$this->assertSame('name[]', $context->getVar('name'));
$this->assertSame('name[]', $view->getVar('name'));
}
}

View File

@ -12,7 +12,7 @@
namespace Symfony\Tests\Component\Form\Type;
use Symfony\Component\Form\CountryField;
use Symfony\Component\Form\FormContext;
use Symfony\Component\Form\FormView;
require_once __DIR__.'/TestCase.php';
@ -23,8 +23,8 @@ class CountryTypeTest extends TestCase
\Locale::setDefault('de_AT');
$form = $this->factory->create('country');
$context = $form->getContext();
$choices = $context->getVar('choices');
$view = $form->getView();
$choices = $view->getVar('choices');
$this->assertArrayHasKey('DE', $choices);
$this->assertEquals('Deutschland', $choices['DE']);
@ -41,8 +41,8 @@ class CountryTypeTest extends TestCase
public function testUnknownCountryIsNotIncluded()
{
$form = $this->factory->create('country', 'country');
$context = $form->getContext();
$choices = $context->getVar('choices');
$view = $form->getView();
$choices = $view->getVar('choices');
$this->assertArrayNotHasKey('ZZ', $choices);
}

View File

@ -14,7 +14,7 @@ namespace Symfony\Tests\Component\Form\Type;
require_once __DIR__ . '/LocalizedTestCase.php';
use Symfony\Component\Form\DateField;
use Symfony\Component\Form\FormContext;
use Symfony\Component\Form\FormView;
class DateTypeTest extends LocalizedTestCase
{
@ -429,12 +429,12 @@ class DateTypeTest extends LocalizedTestCase
$this->assertTrue($form->isPartiallyFilled());
}
public function testPassDatePatternToContext()
public function testPassDatePatternToView()
{
$form = $this->factory->create('date');
$context = $form->getContext();
$view = $form->getView();
$this->assertSame('{{ day }}.{{ month }}.{{ year }}', $context->getVar('date_pattern'));
$this->assertSame('{{ day }}.{{ month }}.{{ year }}', $view->getVar('date_pattern'));
}
public function testDontPassDatePatternIfText()
@ -442,18 +442,18 @@ class DateTypeTest extends LocalizedTestCase
$form = $this->factory->create('date', 'name', array(
'widget' => 'text',
));
$context = $form->getContext();
$view = $form->getView();
$this->assertNull($context->getVar('date_pattern'));
$this->assertNull($view->getVar('date_pattern'));
}
public function testPassWidgetToContext()
public function testPassWidgetToView()
{
$form = $this->factory->create('date', 'name', array(
'widget' => 'text',
));
$context = $form->getContext();
$view = $form->getView();
$this->assertSame('text', $context->getVar('widget'));
$this->assertSame('text', $view->getVar('widget'));
}
}

View File

@ -110,42 +110,42 @@ class FieldTypeTest extends TestCase
$this->assertEquals('reverse[ a ]', $form->getData());
}
public function testPassIdAndNameToContext()
public function testPassIdAndNameToView()
{
$form = $this->factory->create('field', 'name');
$context = $form->getContext();
$view = $form->getView();
$this->assertEquals('name', $context->getVar('id'));
$this->assertEquals('name', $context->getVar('name'));
$this->assertEquals('name', $view->getVar('id'));
$this->assertEquals('name', $view->getVar('name'));
}
public function testPassIdAndNameToContextWithParent()
public function testPassIdAndNameToViewWithParent()
{
$parent = $this->factory->create('field', 'parent');
$parent->add($this->factory->create('field', 'child'));
$context = $parent->getContext();
$view = $parent->getView();
$this->assertEquals('parent_child', $context['child']->getVar('id'));
$this->assertEquals('parent[child]', $context['child']->getVar('name'));
$this->assertEquals('parent_child', $view['child']->getVar('id'));
$this->assertEquals('parent[child]', $view['child']->getVar('name'));
}
public function testPassIdAndNameToContextWithGrandParent()
public function testPassIdAndNameToViewWithGrandParent()
{
$parent = $this->factory->create('field', 'parent');
$parent->add($this->factory->create('field', 'child'));
$parent['child']->add($this->factory->create('field', 'grand_child'));
$context = $parent->getContext();
$view = $parent->getView();
$this->assertEquals('parent_child_grand_child', $context['child']['grand_child']->getVar('id'));
$this->assertEquals('parent[child][grand_child]', $context['child']['grand_child']->getVar('name'));
$this->assertEquals('parent_child_grand_child', $view['child']['grand_child']->getVar('id'));
$this->assertEquals('parent[child][grand_child]', $view['child']['grand_child']->getVar('name'));
}
public function testPassMaxLengthToContext()
public function testPassMaxLengthToView()
{
$form = $this->factory->create('field', null, array('max_length' => 10));
$context = $form->getContext();
$view = $form->getView();
$this->assertSame(10, $context->getVar('max_length'));
$this->assertSame(10, $view->getVar('max_length'));
}
public function testBindWithEmptyDataCreatesObjectIfClassAvailable()

View File

@ -15,7 +15,7 @@ require_once __DIR__ . '/TestCase.php';
require_once __DIR__ . '/../Fixtures/Author.php';
use Symfony\Component\Form\Form;
use Symfony\Component\Form\FormContext;
use Symfony\Component\Form\FormView;
use Symfony\Component\Form\Field;
use Symfony\Component\Form\FormError;
use Symfony\Component\Form\DataError;
@ -26,7 +26,7 @@ use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\File\UploadedFile;
use Symfony\Component\Validator\ConstraintViolation;
use Symfony\Component\Validator\ConstraintViolationList;
use Symfony\Component\Validator\ExecutionContext;
use Symfony\Component\Validator\ExecutionView;
use Symfony\Tests\Component\Form\Fixtures\Author;
class FormTest_AuthorWithoutRefSetter
@ -236,21 +236,21 @@ class FormTypeTest extends TestCase
$this->assertSame($ref2, $author['referenceCopy']);
}
public function testPassMultipartFalseToContext()
public function testPassMultipartFalseToView()
{
$form = $this->factory->create('form');
$context = $form->getContext();
$view = $form->getView();
$this->assertFalse($context->getVar('multipart'));
$this->assertFalse($view->getVar('multipart'));
}
public function testPassMultipartTrueIfAnyChildIsMultipartToContext()
public function testPassMultipartTrueIfAnyChildIsMultipartToView()
{
$form = $this->factory->create('form');
$form->add($this->factory->create('text'));
$form->add($this->factory->create('file'));
$context = $form->getContext();
$view = $form->getView();
$this->assertTrue($context->getVar('multipart'));
$this->assertTrue($view->getVar('multipart'));
}
}

View File

@ -14,7 +14,7 @@ namespace Symfony\Tests\Component\Form\Type;
require_once __DIR__.'/TestCase.php';
use Symfony\Component\Form\LanguageField;
use Symfony\Component\Form\FormContext;
use Symfony\Component\Form\FormView;
class LanguageTypeTest extends TestCase
{
@ -23,8 +23,8 @@ class LanguageTypeTest extends TestCase
\Locale::setDefault('de_AT');
$form = $this->factory->create('language');
$context = $form->getContext();
$choices = $context->getVar('choices');
$view = $form->getView();
$choices = $view->getVar('choices');
$this->assertArrayHasKey('en', $choices);
$this->assertEquals('Englisch', $choices['en']);
@ -41,8 +41,8 @@ class LanguageTypeTest extends TestCase
public function testMultipleLanguagesIsNotIncluded()
{
$form = $this->factory->create('language', 'language');
$context = $form->getContext();
$choices = $context->getVar('choices');
$view = $form->getView();
$choices = $view->getVar('choices');
$this->assertArrayNotHasKey('mul', $choices);
}

View File

@ -14,7 +14,7 @@ namespace Symfony\Tests\Component\Form\Type;
require_once __DIR__.'/TestCase.php';
use Symfony\Component\Form\LocaleField;
use Symfony\Component\Form\FormContext;
use Symfony\Component\Form\FormView;
class LocaleTypeTest extends TestCase
{
@ -23,8 +23,8 @@ class LocaleTypeTest extends TestCase
\Locale::setDefault('de_AT');
$form = $this->factory->create('locale');
$context = $form->getContext();
$choices = $context->getVar('choices');
$view = $form->getView();
$choices = $view->getVar('choices');
$this->assertArrayHasKey('en', $choices);
$this->assertEquals('Englisch', $choices['en']);

View File

@ -15,13 +15,13 @@ require_once __DIR__ . '/LocalizedTestCase.php';
class MoneyTypeTest extends LocalizedTestCase
{
public function testPassMoneyPatternToContext()
public function testPassMoneyPatternToView()
{
\Locale::setDefault('de_DE');
$form = $this->factory->create('money');
$context = $form->getContext();
$view = $form->getView();
$this->assertSame('{{ widget }} €', $context->getVar('money_pattern'));
$this->assertSame('{{ widget }} €', $view->getVar('money_pattern'));
}
}

View File

@ -21,26 +21,26 @@ class PasswordTypeTest extends TestCase
{
$form = $this->factory->create('password');
$form->setData('pAs5w0rd');
$context = $form->getContext();
$view = $form->getView();
$this->assertSame('', $context->getVar('value'));
$this->assertSame('', $view->getVar('value'));
}
public function testEmptyIfBound()
{
$form = $this->factory->create('password');
$form->bind('pAs5w0rd');
$context = $form->getContext();
$view = $form->getView();
$this->assertSame('', $context->getVar('value'));
$this->assertSame('', $view->getVar('value'));
}
public function testNotEmptyIfBoundAndNotAlwaysEmpty()
{
$form = $this->factory->create('password', null, array('always_empty' => false));
$form->bind('pAs5w0rd');
$context = $form->getContext();
$view = $form->getView();
$this->assertSame('pAs5w0rd', $context->getVar('value'));
$this->assertSame('pAs5w0rd', $view->getVar('value'));
}
}

View File

@ -15,38 +15,38 @@ require_once __DIR__.'/TestCase.php';
class RadioTypeTest extends TestCase
{
public function testPassValueToContext()
public function testPassValueToView()
{
$form = $this->factory->create('radio', 'name', array('value' => 'foobar'));
$context = $form->getContext();
$view = $form->getView();
$this->assertEquals('foobar', $context->getVar('value'));
$this->assertEquals('foobar', $view->getVar('value'));
}
public function testPassParentNameToContext()
public function testPassParentNameToView()
{
$parent = $this->factory->create('field', 'parent');
$parent->add($this->factory->create('radio', 'child'));
$context = $parent->getContext();
$view = $parent->getView();
$this->assertEquals('parent', $context['child']->getVar('name'));
$this->assertEquals('parent', $view['child']->getVar('name'));
}
public function testCheckedIfDataTrue()
{
$form = $this->factory->create('radio');
$form->setData(true);
$context = $form->getContext();
$view = $form->getView();
$this->assertTrue($context->getVar('checked'));
$this->assertTrue($view->getVar('checked'));
}
public function testNotCheckedIfDataFalse()
{
$form = $this->factory->create('radio');
$form->setData(false);
$context = $form->getContext();
$view = $form->getView();
$this->assertFalse($context->getVar('checked'));
$this->assertFalse($view->getVar('checked'));
}
}

View File

@ -20,8 +20,8 @@ class TimezoneTypeTest extends TestCase
public function testTimezonesAreSelectable()
{
$form = $this->factory->create('timezone');
$context = $form->getContext();
$choices = $context->getVar('choices');
$view = $form->getView();
$choices = $view->getVar('choices');
$this->assertArrayHasKey('Africa', $choices);
$this->assertArrayHasKey('Africa/Kinshasa', $choices['Africa']);