[Form] Merged various form events and added class FormEvent

This commit is contained in:
Bernhard Schussek 2012-05-23 20:58:42 +02:00
parent bec80157f9
commit 33fecca210
32 changed files with 336 additions and 253 deletions

View File

@ -671,6 +671,35 @@
$builder->addViewTransformer(new MyTransformer()); $builder->addViewTransformer(new MyTransformer());
``` ```
* The following events were deprecated and have a new equivalent:
* `FormEvents::SET_DATA`: `FormEvents::PRE_SET_DATA`
* `FormEvents::BIND_CLIENT_DATA`: `FormEvents::PRE_BIND`
* `FormEvents::BIND_NORM_DATA`: `FormEvents::BIND`
The deprecated events will be removed in Symfony 2.3.
Furthermore, the event classes `DataEvent` and `FilterDataEvent` were
deprecated and replaced by the generic `FormEvent`. You are advised to
code your listeners against the new event now. The deprecated events will
be removed in Symfony 2.3.
Before:
```
$builder->addListener(FormEvents::BIND_CLIENT_DATA, function (FilterDataEvent $event) {
// ...
});
```
After:
```
$builder->addListener(FormEvents::PRE_BIND, function (FormEvent $event) {
// ...
});
```
### Validator ### Validator
* The methods `setMessage()`, `getMessageTemplate()` and * The methods `setMessage()`, `getMessageTemplate()` and

View File

@ -12,7 +12,7 @@
namespace Symfony\Bridge\Doctrine\Form\EventListener; namespace Symfony\Bridge\Doctrine\Form\EventListener;
use Symfony\Component\Form\FormEvents; use Symfony\Component\Form\FormEvents;
use Symfony\Component\Form\Event\FilterDataEvent; use Symfony\Component\Form\FormEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\EventDispatcher\EventSubscriberInterface;
/** /**
@ -30,10 +30,10 @@ class MergeDoctrineCollectionListener implements EventSubscriberInterface
{ {
// Higher priority than core MergeCollectionListener so that this one // Higher priority than core MergeCollectionListener so that this one
// is called before // is called before
return array(FormEvents::BIND_NORM_DATA => array('onBindNormData', 10)); return array(FormEvents::BIND => array('onBind', 10));
} }
public function onBindNormData(FilterDataEvent $event) public function onBind(FormEvent $event)
{ {
$collection = $event->getForm()->getData(); $collection = $event->getForm()->getData();
$data = $event->getData(); $data = $event->getData();

View File

@ -15,7 +15,7 @@ use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\FormError; use Symfony\Component\Form\FormError;
use Symfony\Component\Form\FormEvents; use Symfony\Component\Form\FormEvents;
use Symfony\Component\Form\Event\FilterDataEvent; use Symfony\Component\Form\FormEvent;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Security\Core\SecurityContextInterface; use Symfony\Component\Security\Core\SecurityContextInterface;
use Symfony\Component\OptionsResolver\OptionsResolverInterface; use Symfony\Component\OptionsResolver\OptionsResolverInterface;
@ -57,7 +57,7 @@ class UserLoginFormType extends AbstractType
* request; however, we can match the expected behavior by checking the * request; however, we can match the expected behavior by checking the
* session for an authentication error and last username. * session for an authentication error and last username.
*/ */
$builder->addEventListener(FormEvents::SET_DATA, function (FilterDataEvent $event) use ($request) { $builder->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) use ($request) {
if ($request->attributes->has(SecurityContextInterface::AUTHENTICATION_ERROR)) { if ($request->attributes->has(SecurityContextInterface::AUTHENTICATION_ERROR)) {
$error = $request->attributes->get(SecurityContextInterface::AUTHENTICATION_ERROR); $error = $request->attributes->get(SecurityContextInterface::AUTHENTICATION_ERROR);
} else { } else {

View File

@ -124,3 +124,10 @@ CHANGELOG
* `finishView` * `finishView`
in FormTypeInterface and FormTypeExtensionInterface in FormTypeInterface and FormTypeExtensionInterface
* [BC BREAK] no options are passed to `getParent` of FormTypeInterface anymore * [BC BREAK] no options are passed to `getParent` of FormTypeInterface anymore
* deprecated DataEvent and FilterDataEvent in favor of the new FormEvent which is
now passed to all events thrown by the component
* FormEvents::BIND now replaces FormEvents::BIND_NORM_DATA
* FormEvents::PRE_SET_DATA now replaces FormEvents::SET_DATA
* FormEvents::PRE_BIND now replaces FormEvents::BIND_CLIENT_DATA
* deprecated FormEvents::SET_DATA, FormEvents::BIND_CLIENT_DATA and
FormEvents::BIND_NORM_DATA

View File

@ -14,6 +14,12 @@ namespace Symfony\Component\Form\Event;
use Symfony\Component\EventDispatcher\Event; use Symfony\Component\EventDispatcher\Event;
use Symfony\Component\Form\FormInterface; use Symfony\Component\Form\FormInterface;
/**
* @author Bernhard Schussek <bschussek@gmail.com>
*
* @deprecated Deprecated since version 2.1, to be removed in 2.3. Code against
* {@link \Symfony\Component\Form\FormEvent} instead.
*/
class DataEvent extends Event class DataEvent extends Event
{ {
private $form; private $form;
@ -50,4 +56,14 @@ class DataEvent extends Event
{ {
return $this->data; return $this->data;
} }
/**
* Allows updating with some filtered data
*
* @param mixed $data
*/
public function setData($data)
{
$this->data = $data;
}
} }

View File

@ -11,15 +11,12 @@
namespace Symfony\Component\Form\Event; namespace Symfony\Component\Form\Event;
/**
* @author Bernhard Schussek <bschussek@gmail.com>
*
* @deprecated Deprecated since version 2.1, to be removed in 2.3. Code against
* {@link \Symfony\Component\Form\FormEvent} instead.
*/
class FilterDataEvent extends DataEvent class FilterDataEvent extends DataEvent
{ {
/**
* Allows updating with some filtered data
*
* @param mixed $data
*/
public function setData($data)
{
$this->data = $data;
}
} }

View File

@ -12,7 +12,7 @@
namespace Symfony\Component\Form\Extension\Core\EventListener; namespace Symfony\Component\Form\Extension\Core\EventListener;
use Symfony\Component\Form\FormEvents; use Symfony\Component\Form\FormEvents;
use Symfony\Component\Form\Event\FilterDataEvent; use Symfony\Component\Form\FormEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Form\Extension\Core\ChoiceList\ChoiceListInterface; use Symfony\Component\Form\Extension\Core\ChoiceList\ChoiceListInterface;
@ -36,7 +36,7 @@ class FixCheckboxInputListener implements EventSubscriberInterface
$this->choiceList = $choiceList; $this->choiceList = $choiceList;
} }
public function onBindClientData(FilterDataEvent $event) public function preBind(FormEvent $event)
{ {
$values = (array) $event->getData(); $values = (array) $event->getData();
$indices = $this->choiceList->getIndicesForValues($values); $indices = $this->choiceList->getIndicesForValues($values);
@ -46,6 +46,6 @@ class FixCheckboxInputListener implements EventSubscriberInterface
static public function getSubscribedEvents() static public function getSubscribedEvents()
{ {
return array(FormEvents::BIND_CLIENT_DATA => 'onBindClientData'); return array(FormEvents::PRE_BIND => 'preBind');
} }
} }

View File

@ -12,7 +12,7 @@
namespace Symfony\Component\Form\Extension\Core\EventListener; namespace Symfony\Component\Form\Extension\Core\EventListener;
use Symfony\Component\Form\FormEvents; use Symfony\Component\Form\FormEvents;
use Symfony\Component\Form\Event\FilterDataEvent; use Symfony\Component\Form\FormEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Form\Extension\Core\ChoiceList\ChoiceListInterface; use Symfony\Component\Form\Extension\Core\ChoiceList\ChoiceListInterface;
@ -36,7 +36,7 @@ class FixRadioInputListener implements EventSubscriberInterface
$this->choiceList = $choiceList; $this->choiceList = $choiceList;
} }
public function onBindClientData(FilterDataEvent $event) public function preBind(FormEvent $event)
{ {
$value = $event->getData(); $value = $event->getData();
$index = current($this->choiceList->getIndicesForValues(array($value))); $index = current($this->choiceList->getIndicesForValues(array($value)));
@ -46,6 +46,6 @@ class FixRadioInputListener implements EventSubscriberInterface
static public function getSubscribedEvents() static public function getSubscribedEvents()
{ {
return array(FormEvents::BIND_CLIENT_DATA => 'onBindClientData'); return array(FormEvents::PRE_BIND => 'preBind');
} }
} }

View File

@ -12,7 +12,7 @@
namespace Symfony\Component\Form\Extension\Core\EventListener; namespace Symfony\Component\Form\Extension\Core\EventListener;
use Symfony\Component\Form\FormEvents; use Symfony\Component\Form\FormEvents;
use Symfony\Component\Form\Event\FilterDataEvent; use Symfony\Component\Form\FormEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\EventDispatcher\EventSubscriberInterface;
/** /**
@ -29,7 +29,7 @@ class FixUrlProtocolListener implements EventSubscriberInterface
$this->defaultProtocol = $defaultProtocol; $this->defaultProtocol = $defaultProtocol;
} }
public function onBindNormData(FilterDataEvent $event) public function onBind(FormEvent $event)
{ {
$data = $event->getData(); $data = $event->getData();
@ -40,6 +40,6 @@ class FixUrlProtocolListener implements EventSubscriberInterface
static public function getSubscribedEvents() static public function getSubscribedEvents()
{ {
return array(FormEvents::BIND_NORM_DATA => 'onBindNormData'); return array(FormEvents::BIND => 'onBind');
} }
} }

View File

@ -13,7 +13,7 @@ namespace Symfony\Component\Form\Extension\Core\EventListener;
use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Form\FormEvents; use Symfony\Component\Form\FormEvents;
use Symfony\Component\Form\Event\FilterDataEvent; use Symfony\Component\Form\FormEvent;
use Symfony\Component\Form\Exception\UnexpectedTypeException; use Symfony\Component\Form\Exception\UnexpectedTypeException;
/** /**
@ -50,15 +50,13 @@ class MergeCollectionListener implements EventSubscriberInterface
static public function getSubscribedEvents() static public function getSubscribedEvents()
{ {
return array( return array(
FormEvents::BIND_NORM_DATA => 'onBindNormData', FormEvents::BIND => 'onBind',
); );
} }
public function onBindNormData(FilterDataEvent $event) public function onBind(FormEvent $event)
{ {
$dataToMergeInto = $event->getForm()->getNormData(); $dataToMergeInto = $event->getForm()->getNormData();
$form = $event->getForm();
$data = $event->getData(); $data = $event->getData();
if (null === $data) { if (null === $data) {

View File

@ -12,8 +12,7 @@
namespace Symfony\Component\Form\Extension\Core\EventListener; namespace Symfony\Component\Form\Extension\Core\EventListener;
use Symfony\Component\Form\FormEvents; use Symfony\Component\Form\FormEvents;
use Symfony\Component\Form\Event\DataEvent; use Symfony\Component\Form\FormEvent;
use Symfony\Component\Form\Event\FilterDataEvent;
use Symfony\Component\Form\FormFactoryInterface; use Symfony\Component\Form\FormFactoryInterface;
use Symfony\Component\Form\Exception\UnexpectedTypeException; use Symfony\Component\Form\Exception\UnexpectedTypeException;
use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\EventDispatcher\EventSubscriberInterface;
@ -67,11 +66,11 @@ class ResizeFormListener implements EventSubscriberInterface
FormEvents::PRE_SET_DATA => 'preSetData', FormEvents::PRE_SET_DATA => 'preSetData',
FormEvents::PRE_BIND => 'preBind', FormEvents::PRE_BIND => 'preBind',
// (MergeCollectionListener, MergeDoctrineCollectionListener) // (MergeCollectionListener, MergeDoctrineCollectionListener)
FormEvents::BIND_NORM_DATA => array('onBindNormData', 50), FormEvents::BIND => array('onBind', 50),
); );
} }
public function preSetData(DataEvent $event) public function preSetData(FormEvent $event)
{ {
$form = $event->getForm(); $form = $event->getForm();
$data = $event->getData(); $data = $event->getData();
@ -97,7 +96,7 @@ class ResizeFormListener implements EventSubscriberInterface
} }
} }
public function preBind(DataEvent $event) public function preBind(FormEvent $event)
{ {
$form = $event->getForm(); $form = $event->getForm();
$data = $event->getData(); $data = $event->getData();
@ -131,7 +130,7 @@ class ResizeFormListener implements EventSubscriberInterface
} }
} }
public function onBindNormData(FilterDataEvent $event) public function onBind(FormEvent $event)
{ {
$form = $event->getForm(); $form = $event->getForm();
$data = $event->getData(); $data = $event->getData();

View File

@ -12,7 +12,7 @@
namespace Symfony\Component\Form\Extension\Core\EventListener; namespace Symfony\Component\Form\Extension\Core\EventListener;
use Symfony\Component\Form\FormEvents; use Symfony\Component\Form\FormEvents;
use Symfony\Component\Form\Event\FilterDataEvent; use Symfony\Component\Form\FormEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\EventDispatcher\EventSubscriberInterface;
/** /**
@ -22,7 +22,7 @@ use Symfony\Component\EventDispatcher\EventSubscriberInterface;
*/ */
class TrimListener implements EventSubscriberInterface class TrimListener implements EventSubscriberInterface
{ {
public function onBindClientData(FilterDataEvent $event) public function preBind(FormEvent $event)
{ {
$data = $event->getData(); $data = $event->getData();
@ -33,6 +33,6 @@ class TrimListener implements EventSubscriberInterface
static public function getSubscribedEvents() static public function getSubscribedEvents()
{ {
return array(FormEvents::BIND_CLIENT_DATA => 'onBindClientData'); return array(FormEvents::PRE_BIND => 'preBind');
} }
} }

View File

@ -14,7 +14,7 @@ namespace Symfony\Component\Form\Extension\Csrf\EventListener;
use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Form\FormEvents; use Symfony\Component\Form\FormEvents;
use Symfony\Component\Form\FormError; use Symfony\Component\Form\FormError;
use Symfony\Component\Form\Event\FilterDataEvent; use Symfony\Component\Form\FormEvent;
use Symfony\Component\Form\Extension\Csrf\CsrfProvider\CsrfProviderInterface; use Symfony\Component\Form\Extension\Csrf\CsrfProvider\CsrfProviderInterface;
/** /**
@ -47,7 +47,7 @@ class CsrfValidationListener implements EventSubscriberInterface
static public function getSubscribedEvents() static public function getSubscribedEvents()
{ {
return array( return array(
FormEvents::BIND_CLIENT_DATA => 'onBindClientData', FormEvents::PRE_BIND => 'preBind',
); );
} }
@ -58,7 +58,7 @@ class CsrfValidationListener implements EventSubscriberInterface
$this->intention = $intention; $this->intention = $intention;
} }
public function onBindClientData(FilterDataEvent $event) public function preBind(FormEvent $event)
{ {
$form = $event->getForm(); $form = $event->getForm();
$data = $event->getData(); $data = $event->getData();

View File

@ -11,8 +11,6 @@
namespace Symfony\Component\Form; namespace Symfony\Component\Form;
use Symfony\Component\Form\Event\DataEvent;
use Symfony\Component\Form\Event\FilterDataEvent;
use Symfony\Component\Form\Exception\FormException; use Symfony\Component\Form\Exception\FormException;
use Symfony\Component\Form\Exception\AlreadyBoundException; use Symfony\Component\Form\Exception\AlreadyBoundException;
use Symfony\Component\Form\Exception\UnexpectedTypeException; use Symfony\Component\Form\Exception\UnexpectedTypeException;
@ -329,11 +327,10 @@ class Form implements \IteratorAggregate, FormInterface
$modelData = clone $modelData; $modelData = clone $modelData;
} }
$event = new DataEvent($this, $modelData);
$this->config->getEventDispatcher()->dispatch(FormEvents::PRE_SET_DATA, $event);
// Hook to change content of the data // Hook to change content of the data
$event = new FilterDataEvent($this, $modelData); $event = new FormEvent($this, $modelData);
$this->config->getEventDispatcher()->dispatch(FormEvents::PRE_SET_DATA, $event);
// BC until 2.3
$this->config->getEventDispatcher()->dispatch(FormEvents::SET_DATA, $event); $this->config->getEventDispatcher()->dispatch(FormEvents::SET_DATA, $event);
$modelData = $event->getData(); $modelData = $event->getData();
@ -383,7 +380,7 @@ class Form implements \IteratorAggregate, FormInterface
$this->config->getDataMapper()->mapDataToForms($viewData, $this->children); $this->config->getDataMapper()->mapDataToForms($viewData, $this->children);
} }
$event = new DataEvent($this, $modelData); $event = new FormEvent($this, $modelData);
$this->config->getEventDispatcher()->dispatch(FormEvents::POST_SET_DATA, $event); $this->config->getEventDispatcher()->dispatch(FormEvents::POST_SET_DATA, $event);
return $this; return $this;
@ -465,16 +462,15 @@ class Form implements \IteratorAggregate, FormInterface
// errors added during listeners // errors added during listeners
$this->errors = array(); $this->errors = array();
$event = new DataEvent($this, $submittedData);
$this->config->getEventDispatcher()->dispatch(FormEvents::PRE_BIND, $event);
$modelData = null; $modelData = null;
$normData = null; $normData = null;
$extraData = array(); $extraData = array();
$synchronized = false; $synchronized = false;
// Hook to change content of the data bound by the browser // Hook to change content of the data bound by the browser
$event = new FilterDataEvent($this, $submittedData); $event = new FormEvent($this, $submittedData);
$this->config->getEventDispatcher()->dispatch(FormEvents::PRE_BIND, $event);
// BC until 2.3
$this->config->getEventDispatcher()->dispatch(FormEvents::BIND_CLIENT_DATA, $event); $this->config->getEventDispatcher()->dispatch(FormEvents::BIND_CLIENT_DATA, $event);
$submittedData = $event->getData(); $submittedData = $event->getData();
@ -537,10 +533,13 @@ class Form implements \IteratorAggregate, FormInterface
if ($synchronized) { if ($synchronized) {
// Hook to change content of the data into the normalized // Hook to change content of the data into the normalized
// representation // representation
$event = new FilterDataEvent($this, $normData); $event = new FormEvent($this, $normData);
$this->config->getEventDispatcher()->dispatch(FormEvents::BIND, $event);
// BC until 2.3
$this->config->getEventDispatcher()->dispatch(FormEvents::BIND_NORM_DATA, $event); $this->config->getEventDispatcher()->dispatch(FormEvents::BIND_NORM_DATA, $event);
$normData = $event->getData(); $normData = $event->getData();
// Synchronize representations - must not change the content! // Synchronize representations - must not change the content!
$modelData = $this->normToModel($normData); $modelData = $this->normToModel($normData);
$viewData = $this->normToView($normData); $viewData = $this->normToView($normData);
@ -553,7 +552,7 @@ class Form implements \IteratorAggregate, FormInterface
$this->extraData = $extraData; $this->extraData = $extraData;
$this->synchronized = $synchronized; $this->synchronized = $synchronized;
$event = new DataEvent($this, $viewData); $event = new FormEvent($this, $viewData);
$this->config->getEventDispatcher()->dispatch(FormEvents::POST_BIND, $event); $this->config->getEventDispatcher()->dispatch(FormEvents::POST_BIND, $event);
foreach ($this->config->getValidators() as $validator) { foreach ($this->config->getValidators() as $validator) {

View File

@ -0,0 +1,21 @@
<?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;
use Symfony\Component\Form\Event\FilterDataEvent;
/**
* @author Bernhard Schussek <bschussek@gmail.com>
*/
class FormEvent extends FilterDataEvent
{
}

View File

@ -18,15 +18,33 @@ final class FormEvents
{ {
const PRE_BIND = 'form.pre_bind'; const PRE_BIND = 'form.pre_bind';
const BIND = 'form.bind';
const POST_BIND = 'form.post_bind'; const POST_BIND = 'form.post_bind';
const PRE_SET_DATA = 'form.pre_set_data'; const PRE_SET_DATA = 'form.pre_set_data';
const POST_SET_DATA = 'form.post_set_data'; const POST_SET_DATA = 'form.post_set_data';
/**
* @deprecated Deprecated since version 2.1, to be removed in 2.3.
* Use {@link PRE_BIND} instead.
*/
const BIND_CLIENT_DATA = 'form.bind_client_data'; const BIND_CLIENT_DATA = 'form.bind_client_data';
/**
* @deprecated Deprecated since version 2.1, to be removed in 2.3.
* Use {@link BIND} instead.
*/
const BIND_NORM_DATA = 'form.bind_norm_data'; const BIND_NORM_DATA = 'form.bind_norm_data';
/**
* @deprecated Deprecated since version 2.1, to be removed in 2.3.
* Use {@link PRE_SET_DATA} instead.
*/
const SET_DATA = 'form.set_data'; const SET_DATA = 'form.set_data';
private function __construct()
{
}
} }

View File

@ -11,7 +11,7 @@
namespace Symfony\Component\Form\Tests\Extension\Core\EventListener; namespace Symfony\Component\Form\Tests\Extension\Core\EventListener;
use Symfony\Component\Form\Event\FilterDataEvent; use Symfony\Component\Form\FormEvent;
use Symfony\Component\Form\Extension\Core\EventListener\FixRadioInputListener; use Symfony\Component\Form\Extension\Core\EventListener\FixRadioInputListener;
use Symfony\Component\Form\Extension\Core\ChoiceList\SimpleChoiceList; use Symfony\Component\Form\Extension\Core\ChoiceList\SimpleChoiceList;
@ -42,9 +42,9 @@ class FixRadioInputListenerTest extends \PHPUnit_Framework_TestCase
{ {
$data = '1'; $data = '1';
$form = $this->getMock('Symfony\Component\Form\Tests\FormInterface'); $form = $this->getMock('Symfony\Component\Form\Tests\FormInterface');
$event = new FilterDataEvent($form, $data); $event = new FormEvent($form, $data);
$this->listener->onBindClientData($event); $this->listener->preBind($event);
$this->assertEquals(array(1 => '1'), $event->getData()); $this->assertEquals(array(1 => '1'), $event->getData());
} }
@ -53,9 +53,9 @@ class FixRadioInputListenerTest extends \PHPUnit_Framework_TestCase
{ {
$data = '0'; $data = '0';
$form = $this->getMock('Symfony\Component\Form\Tests\FormInterface'); $form = $this->getMock('Symfony\Component\Form\Tests\FormInterface');
$event = new FilterDataEvent($form, $data); $event = new FormEvent($form, $data);
$this->listener->onBindClientData($event); $this->listener->preBind($event);
$this->assertEquals(array(0 => '0'), $event->getData()); $this->assertEquals(array(0 => '0'), $event->getData());
} }
@ -64,9 +64,9 @@ class FixRadioInputListenerTest extends \PHPUnit_Framework_TestCase
{ {
$data = ''; $data = '';
$form = $this->getMock('Symfony\Component\Form\Tests\FormInterface'); $form = $this->getMock('Symfony\Component\Form\Tests\FormInterface');
$event = new FilterDataEvent($form, $data); $event = new FormEvent($form, $data);
$this->listener->onBindClientData($event); $this->listener->preBind($event);
$this->assertEquals(array(), $event->getData()); $this->assertEquals(array(), $event->getData());
} }

View File

@ -11,7 +11,7 @@
namespace Symfony\Component\Form\Tests\Extension\Core\EventListener; namespace Symfony\Component\Form\Tests\Extension\Core\EventListener;
use Symfony\Component\Form\Event\FilterDataEvent; use Symfony\Component\Form\FormEvent;
use Symfony\Component\Form\Extension\Core\EventListener\FixUrlProtocolListener; use Symfony\Component\Form\Extension\Core\EventListener\FixUrlProtocolListener;
class FixUrlProtocolListenerTest extends \PHPUnit_Framework_TestCase class FixUrlProtocolListenerTest extends \PHPUnit_Framework_TestCase
@ -27,10 +27,10 @@ class FixUrlProtocolListenerTest extends \PHPUnit_Framework_TestCase
{ {
$data = "www.symfony.com"; $data = "www.symfony.com";
$form = $this->getMock('Symfony\Component\Form\Tests\FormInterface'); $form = $this->getMock('Symfony\Component\Form\Tests\FormInterface');
$event = new FilterDataEvent($form, $data); $event = new FormEvent($form, $data);
$filter = new FixUrlProtocolListener('http'); $filter = new FixUrlProtocolListener('http');
$filter->onBindNormData($event); $filter->onBind($event);
$this->assertEquals('http://www.symfony.com', $event->getData()); $this->assertEquals('http://www.symfony.com', $event->getData());
} }
@ -39,10 +39,10 @@ class FixUrlProtocolListenerTest extends \PHPUnit_Framework_TestCase
{ {
$data = "http://www.symfony.com"; $data = "http://www.symfony.com";
$form = $this->getMock('Symfony\Component\Form\Tests\FormInterface'); $form = $this->getMock('Symfony\Component\Form\Tests\FormInterface');
$event = new FilterDataEvent($form, $data); $event = new FormEvent($form, $data);
$filter = new FixUrlProtocolListener('http'); $filter = new FixUrlProtocolListener('http');
$filter->onBindNormData($event); $filter->onBind($event);
$this->assertEquals('http://www.symfony.com', $event->getData()); $this->assertEquals('http://www.symfony.com', $event->getData());
} }
@ -51,10 +51,10 @@ class FixUrlProtocolListenerTest extends \PHPUnit_Framework_TestCase
{ {
$data = "ftp://www.symfony.com"; $data = "ftp://www.symfony.com";
$form = $this->getMock('Symfony\Component\Form\Tests\FormInterface'); $form = $this->getMock('Symfony\Component\Form\Tests\FormInterface');
$event = new FilterDataEvent($form, $data); $event = new FormEvent($form, $data);
$filter = new FixUrlProtocolListener('http'); $filter = new FixUrlProtocolListener('http');
$filter->onBindNormData($event); $filter->onBind($event);
$this->assertEquals('ftp://www.symfony.com', $event->getData()); $this->assertEquals('ftp://www.symfony.com', $event->getData());
} }

View File

@ -11,7 +11,7 @@
namespace Symfony\Component\Form\Tests\Extension\Core\EventListener; namespace Symfony\Component\Form\Tests\Extension\Core\EventListener;
use Symfony\Component\Form\Event\FilterDataEvent; use Symfony\Component\Form\FormEvent;
use Symfony\Component\Form\Extension\Core\EventListener\MergeCollectionListener; use Symfony\Component\Form\Extension\Core\EventListener\MergeCollectionListener;
use Symfony\Component\Form\FormBuilder; use Symfony\Component\Form\FormBuilder;
@ -85,8 +85,8 @@ abstract class MergeCollectionListenerTest extends \PHPUnit_Framework_TestCase
$this->form->setData($originalData); $this->form->setData($originalData);
$event = new FilterDataEvent($this->form, $newData); $event = new FormEvent($this->form, $newData);
$listener->onBindNormData($event); $listener->onBind($event);
// The original object was modified // The original object was modified
if (is_object($originalData)) { if (is_object($originalData)) {
@ -109,8 +109,8 @@ abstract class MergeCollectionListenerTest extends \PHPUnit_Framework_TestCase
$this->form->setData($originalData); $this->form->setData($originalData);
$event = new FilterDataEvent($this->form, $newData); $event = new FormEvent($this->form, $newData);
$listener->onBindNormData($event); $listener->onBind($event);
// The original object was modified // The original object was modified
if (is_object($originalData)) { if (is_object($originalData)) {
@ -134,8 +134,8 @@ abstract class MergeCollectionListenerTest extends \PHPUnit_Framework_TestCase
$this->form->setData($originalData); $this->form->setData($originalData);
$event = new FilterDataEvent($this->form, $newData); $event = new FormEvent($this->form, $newData);
$listener->onBindNormData($event); $listener->onBind($event);
// We still have the original object // We still have the original object
if (is_object($originalData)) { if (is_object($originalData)) {
@ -158,8 +158,8 @@ abstract class MergeCollectionListenerTest extends \PHPUnit_Framework_TestCase
$this->form->setData($originalData); $this->form->setData($originalData);
$event = new FilterDataEvent($this->form, $newData); $event = new FormEvent($this->form, $newData);
$listener->onBindNormData($event); $listener->onBind($event);
// The original object was modified // The original object was modified
if (is_object($originalData)) { if (is_object($originalData)) {
@ -183,8 +183,8 @@ abstract class MergeCollectionListenerTest extends \PHPUnit_Framework_TestCase
$this->form->setData($originalData); $this->form->setData($originalData);
$event = new FilterDataEvent($this->form, $newData); $event = new FormEvent($this->form, $newData);
$listener->onBindNormData($event); $listener->onBind($event);
// We still have the original object // We still have the original object
if (is_object($originalData)) { if (is_object($originalData)) {
@ -202,9 +202,9 @@ abstract class MergeCollectionListenerTest extends \PHPUnit_Framework_TestCase
public function testRequireArrayOrTraversable($allowAdd, $allowDelete) public function testRequireArrayOrTraversable($allowAdd, $allowDelete)
{ {
$newData = 'no array or traversable'; $newData = 'no array or traversable';
$event = new FilterDataEvent($this->form, $newData); $event = new FormEvent($this->form, $newData);
$listener = new MergeCollectionListener($allowAdd, $allowDelete); $listener = new MergeCollectionListener($allowAdd, $allowDelete);
$listener->onBindNormData($event); $listener->onBind($event);
} }
public function testDealWithNullData() public function testDealWithNullData()
@ -216,8 +216,8 @@ abstract class MergeCollectionListenerTest extends \PHPUnit_Framework_TestCase
$this->form->setData($originalData); $this->form->setData($originalData);
$event = new FilterDataEvent($this->form, $newData); $event = new FormEvent($this->form, $newData);
$listener->onBindNormData($event); $listener->onBind($event);
$this->assertSame($originalData, $event->getData()); $this->assertSame($originalData, $event->getData());
} }
@ -234,8 +234,8 @@ abstract class MergeCollectionListenerTest extends \PHPUnit_Framework_TestCase
$this->form->setData($originalData); $this->form->setData($originalData);
$event = new FilterDataEvent($this->form, $newData); $event = new FormEvent($this->form, $newData);
$listener->onBindNormData($event); $listener->onBind($event);
$this->assertSame($newData, $event->getData()); $this->assertSame($newData, $event->getData());
} }
@ -252,8 +252,8 @@ abstract class MergeCollectionListenerTest extends \PHPUnit_Framework_TestCase
$this->form->setData($originalData); $this->form->setData($originalData);
$event = new FilterDataEvent($this->form, $newData); $event = new FormEvent($this->form, $newData);
$listener->onBindNormData($event); $listener->onBind($event);
$this->assertNull($event->getData()); $this->assertNull($event->getData());
} }

View File

@ -11,8 +11,7 @@
namespace Symfony\Component\Form\Tests\Extension\Core\EventListener; namespace Symfony\Component\Form\Tests\Extension\Core\EventListener;
use Symfony\Component\Form\Event\DataEvent; use Symfony\Component\Form\FormEvent;
use Symfony\Component\Form\Event\FilterDataEvent;
use Symfony\Component\Form\Extension\Core\EventListener\ResizeFormListener; use Symfony\Component\Form\Extension\Core\EventListener\ResizeFormListener;
use Symfony\Component\Form\FormBuilder; use Symfony\Component\Form\FormBuilder;
@ -70,7 +69,7 @@ class ResizeFormListenerTest extends \PHPUnit_Framework_TestCase
->will($this->returnValue($this->getForm('2'))); ->will($this->returnValue($this->getForm('2')));
$data = array(1 => 'string', 2 => 'string'); $data = array(1 => 'string', 2 => 'string');
$event = new DataEvent($this->form, $data); $event = new FormEvent($this->form, $data);
$listener = new ResizeFormListener($this->factory, 'text', array('max_length' => '10'), false, false); $listener = new ResizeFormListener($this->factory, 'text', array('max_length' => '10'), false, false);
$listener->preSetData($event); $listener->preSetData($event);
@ -85,7 +84,7 @@ class ResizeFormListenerTest extends \PHPUnit_Framework_TestCase
public function testPreSetDataRequiresArrayOrTraversable() public function testPreSetDataRequiresArrayOrTraversable()
{ {
$data = 'no array or traversable'; $data = 'no array or traversable';
$event = new DataEvent($this->form, $data); $event = new FormEvent($this->form, $data);
$listener = new ResizeFormListener($this->factory, 'text', array(), false, false); $listener = new ResizeFormListener($this->factory, 'text', array(), false, false);
$listener->preSetData($event); $listener->preSetData($event);
} }
@ -95,7 +94,7 @@ class ResizeFormListenerTest extends \PHPUnit_Framework_TestCase
$this->factory->expects($this->never())->method('createNamed'); $this->factory->expects($this->never())->method('createNamed');
$data = null; $data = null;
$event = new DataEvent($this->form, $data); $event = new FormEvent($this->form, $data);
$listener = new ResizeFormListener($this->factory, 'text', array(), false, false); $listener = new ResizeFormListener($this->factory, 'text', array(), false, false);
$listener->preSetData($event); $listener->preSetData($event);
} }
@ -110,7 +109,7 @@ class ResizeFormListenerTest extends \PHPUnit_Framework_TestCase
->will($this->returnValue($this->getForm('1'))); ->will($this->returnValue($this->getForm('1')));
$data = array(0 => 'string', 1 => 'string'); $data = array(0 => 'string', 1 => 'string');
$event = new DataEvent($this->form, $data); $event = new FormEvent($this->form, $data);
$listener = new ResizeFormListener($this->factory, 'text', array('max_length' => 10), true, false); $listener = new ResizeFormListener($this->factory, 'text', array('max_length' => 10), true, false);
$listener->preBind($event); $listener->preBind($event);
@ -124,7 +123,7 @@ class ResizeFormListenerTest extends \PHPUnit_Framework_TestCase
$this->form->add($this->getForm('1')); $this->form->add($this->getForm('1'));
$data = array(0 => 'string'); $data = array(0 => 'string');
$event = new DataEvent($this->form, $data); $event = new FormEvent($this->form, $data);
$listener = new ResizeFormListener($this->factory, 'text', array(), false, true); $listener = new ResizeFormListener($this->factory, 'text', array(), false, true);
$listener->preBind($event); $listener->preBind($event);
@ -138,7 +137,7 @@ class ResizeFormListenerTest extends \PHPUnit_Framework_TestCase
$this->form->add($this->getForm('0')); $this->form->add($this->getForm('0'));
$data = array(); $data = array();
$event = new DataEvent($this->form, $data); $event = new FormEvent($this->form, $data);
$listener = new ResizeFormListener($this->factory, 'text', array(), false, true); $listener = new ResizeFormListener($this->factory, 'text', array(), false, true);
$listener->preBind($event); $listener->preBind($event);
@ -151,7 +150,7 @@ class ResizeFormListenerTest extends \PHPUnit_Framework_TestCase
$this->form->add($this->getForm('1')); $this->form->add($this->getForm('1'));
$data = array(0 => 'string', 2 => 'string'); $data = array(0 => 'string', 2 => 'string');
$event = new DataEvent($this->form, $data); $event = new FormEvent($this->form, $data);
$listener = new ResizeFormListener($this->factory, 'text', array(), false, false); $listener = new ResizeFormListener($this->factory, 'text', array(), false, false);
$listener->preBind($event); $listener->preBind($event);
@ -166,7 +165,7 @@ class ResizeFormListenerTest extends \PHPUnit_Framework_TestCase
public function testPreBindRequiresArrayOrTraversable() public function testPreBindRequiresArrayOrTraversable()
{ {
$data = 'no array or traversable'; $data = 'no array or traversable';
$event = new DataEvent($this->form, $data); $event = new FormEvent($this->form, $data);
$listener = new ResizeFormListener($this->factory, 'text', array(), false, false); $listener = new ResizeFormListener($this->factory, 'text', array(), false, false);
$listener->preBind($event); $listener->preBind($event);
} }
@ -176,7 +175,7 @@ class ResizeFormListenerTest extends \PHPUnit_Framework_TestCase
$this->form->add($this->getForm('1')); $this->form->add($this->getForm('1'));
$data = null; $data = null;
$event = new DataEvent($this->form, $data); $event = new FormEvent($this->form, $data);
$listener = new ResizeFormListener($this->factory, 'text', array(), false, true); $listener = new ResizeFormListener($this->factory, 'text', array(), false, true);
$listener->preBind($event); $listener->preBind($event);
@ -189,7 +188,7 @@ class ResizeFormListenerTest extends \PHPUnit_Framework_TestCase
$this->form->add($this->getForm('1')); $this->form->add($this->getForm('1'));
$data = ''; $data = '';
$event = new DataEvent($this->form, $data); $event = new FormEvent($this->form, $data);
$listener = new ResizeFormListener($this->factory, 'text', array(), false, true); $listener = new ResizeFormListener($this->factory, 'text', array(), false, true);
$listener->preBind($event); $listener->preBind($event);
@ -201,9 +200,9 @@ class ResizeFormListenerTest extends \PHPUnit_Framework_TestCase
$this->form->add($this->getForm('1')); $this->form->add($this->getForm('1'));
$data = array(0 => 'first', 1 => 'second', 2 => 'third'); $data = array(0 => 'first', 1 => 'second', 2 => 'third');
$event = new FilterDataEvent($this->form, $data); $event = new FormEvent($this->form, $data);
$listener = new ResizeFormListener($this->factory, 'text', array(), false, true); $listener = new ResizeFormListener($this->factory, 'text', array(), false, true);
$listener->onBindNormData($event); $listener->onBind($event);
$this->assertEquals(array(1 => 'second'), $event->getData()); $this->assertEquals(array(1 => 'second'), $event->getData());
} }
@ -213,9 +212,9 @@ class ResizeFormListenerTest extends \PHPUnit_Framework_TestCase
$this->form->add($this->getForm('1')); $this->form->add($this->getForm('1'));
$data = array(0 => 'first', 1 => 'second', 2 => 'third'); $data = array(0 => 'first', 1 => 'second', 2 => 'third');
$event = new FilterDataEvent($this->form, $data); $event = new FormEvent($this->form, $data);
$listener = new ResizeFormListener($this->factory, 'text', array(), false, false); $listener = new ResizeFormListener($this->factory, 'text', array(), false, false);
$listener->onBindNormData($event); $listener->onBind($event);
$this->assertEquals($data, $event->getData()); $this->assertEquals($data, $event->getData());
} }
@ -226,9 +225,9 @@ class ResizeFormListenerTest extends \PHPUnit_Framework_TestCase
public function testOnBindNormDataRequiresArrayOrTraversable() public function testOnBindNormDataRequiresArrayOrTraversable()
{ {
$data = 'no array or traversable'; $data = 'no array or traversable';
$event = new FilterDataEvent($this->form, $data); $event = new FormEvent($this->form, $data);
$listener = new ResizeFormListener($this->factory, 'text', array(), false, false); $listener = new ResizeFormListener($this->factory, 'text', array(), false, false);
$listener->onBindNormData($event); $listener->onBind($event);
} }
public function testOnBindNormDataDealsWithNullData() public function testOnBindNormDataDealsWithNullData()
@ -236,9 +235,9 @@ class ResizeFormListenerTest extends \PHPUnit_Framework_TestCase
$this->form->add($this->getForm('1')); $this->form->add($this->getForm('1'));
$data = null; $data = null;
$event = new FilterDataEvent($this->form, $data); $event = new FormEvent($this->form, $data);
$listener = new ResizeFormListener($this->factory, 'text', array(), false, true); $listener = new ResizeFormListener($this->factory, 'text', array(), false, true);
$listener->onBindNormData($event); $listener->onBind($event);
$this->assertEquals(array(), $event->getData()); $this->assertEquals(array(), $event->getData());
} }

View File

@ -11,7 +11,7 @@
namespace Symfony\Component\Form\Tests\Extension\Core\EventListener; namespace Symfony\Component\Form\Tests\Extension\Core\EventListener;
use Symfony\Component\Form\Event\FilterDataEvent; use Symfony\Component\Form\FormEvent;
use Symfony\Component\Form\Extension\Core\EventListener\TrimListener; use Symfony\Component\Form\Extension\Core\EventListener\TrimListener;
class TrimListenerTest extends \PHPUnit_Framework_TestCase class TrimListenerTest extends \PHPUnit_Framework_TestCase
@ -27,10 +27,10 @@ class TrimListenerTest extends \PHPUnit_Framework_TestCase
{ {
$data = " Foo! "; $data = " Foo! ";
$form = $this->getMock('Symfony\Component\Form\Tests\FormInterface'); $form = $this->getMock('Symfony\Component\Form\Tests\FormInterface');
$event = new FilterDataEvent($form, $data); $event = new FormEvent($form, $data);
$filter = new TrimListener(); $filter = new TrimListener();
$filter->onBindClientData($event); $filter->preBind($event);
$this->assertEquals('Foo!', $event->getData()); $this->assertEquals('Foo!', $event->getData());
} }
@ -39,10 +39,10 @@ class TrimListenerTest extends \PHPUnit_Framework_TestCase
{ {
$data = 1234; $data = 1234;
$form = $this->getMock('Symfony\Component\Form\Tests\FormInterface'); $form = $this->getMock('Symfony\Component\Form\Tests\FormInterface');
$event = new FilterDataEvent($form, $data); $event = new FormEvent($form, $data);
$filter = new TrimListener(); $filter = new TrimListener();
$filter->onBindClientData($event); $filter->preBind($event);
$this->assertSame(1234, $event->getData()); $this->assertSame(1234, $event->getData());
} }

View File

@ -58,7 +58,7 @@ class CheckboxTypeTest extends TypeTestCase
$form->bind('foobar'); $form->bind('foobar');
$this->assertTrue($form->getData()); $this->assertTrue($form->getData());
$this->assertEquals('foobar', $form->getClientData()); $this->assertEquals('foobar', $form->getViewData());
} }
public function testBindWithRandomValueChecked() public function testBindWithRandomValueChecked()
@ -69,7 +69,7 @@ class CheckboxTypeTest extends TypeTestCase
$form->bind('krixikraxi'); $form->bind('krixikraxi');
$this->assertTrue($form->getData()); $this->assertTrue($form->getData());
$this->assertEquals('foobar', $form->getClientData()); $this->assertEquals('foobar', $form->getViewData());
} }
public function testBindWithValueUnchecked() public function testBindWithValueUnchecked()
@ -80,7 +80,7 @@ class CheckboxTypeTest extends TypeTestCase
$form->bind(null); $form->bind(null);
$this->assertFalse($form->getData()); $this->assertFalse($form->getData());
$this->assertNull($form->getClientData()); $this->assertNull($form->getViewData());
} }
public function testBindWithEmptyValueChecked() public function testBindWithEmptyValueChecked()
@ -91,7 +91,7 @@ class CheckboxTypeTest extends TypeTestCase
$form->bind(''); $form->bind('');
$this->assertTrue($form->getData()); $this->assertTrue($form->getData());
$this->assertSame('', $form->getClientData()); $this->assertSame('', $form->getViewData());
} }
public function testBindWithEmptyValueUnchecked() public function testBindWithEmptyValueUnchecked()
@ -102,7 +102,7 @@ class CheckboxTypeTest extends TypeTestCase
$form->bind(null); $form->bind(null);
$this->assertFalse($form->getData()); $this->assertFalse($form->getData());
$this->assertNull($form->getClientData()); $this->assertNull($form->getViewData());
} }
/** /**

View File

@ -180,7 +180,7 @@ class ChoiceTypeTest extends TypeTestCase
$form->bind('b'); $form->bind('b');
$this->assertEquals('b', $form->getData()); $this->assertEquals('b', $form->getData());
$this->assertEquals('b', $form->getClientData()); $this->assertEquals('b', $form->getViewData());
} }
public function testBindSingleNonExpandedObjectChoices() public function testBindSingleNonExpandedObjectChoices()
@ -203,7 +203,7 @@ class ChoiceTypeTest extends TypeTestCase
$form->bind('2'); $form->bind('2');
$this->assertEquals($this->objectChoices[1], $form->getData()); $this->assertEquals($this->objectChoices[1], $form->getData());
$this->assertEquals('2', $form->getClientData()); $this->assertEquals('2', $form->getViewData());
} }
public function testBindMultipleNonExpanded() public function testBindMultipleNonExpanded()
@ -217,7 +217,7 @@ class ChoiceTypeTest extends TypeTestCase
$form->bind(array('a', 'b')); $form->bind(array('a', 'b'));
$this->assertEquals(array('a', 'b'), $form->getData()); $this->assertEquals(array('a', 'b'), $form->getData());
$this->assertEquals(array('a', 'b'), $form->getClientData()); $this->assertEquals(array('a', 'b'), $form->getViewData());
} }
public function testBindMultipleNonExpandedObjectChoices() public function testBindMultipleNonExpandedObjectChoices()
@ -239,7 +239,7 @@ class ChoiceTypeTest extends TypeTestCase
$form->bind(array('2', '3')); $form->bind(array('2', '3'));
$this->assertEquals(array($this->objectChoices[1], $this->objectChoices[2]), $form->getData()); $this->assertEquals(array($this->objectChoices[1], $this->objectChoices[2]), $form->getData());
$this->assertEquals(array('2', '3'), $form->getClientData()); $this->assertEquals(array('2', '3'), $form->getViewData());
} }
public function testBindSingleExpanded() public function testBindSingleExpanded()
@ -258,11 +258,11 @@ class ChoiceTypeTest extends TypeTestCase
$this->assertFalse($form[2]->getData()); $this->assertFalse($form[2]->getData());
$this->assertFalse($form[3]->getData()); $this->assertFalse($form[3]->getData());
$this->assertFalse($form[4]->getData()); $this->assertFalse($form[4]->getData());
$this->assertNull($form[0]->getClientData()); $this->assertNull($form[0]->getViewData());
$this->assertSame('b', $form[1]->getClientData()); $this->assertSame('b', $form[1]->getViewData());
$this->assertNull($form[2]->getClientData()); $this->assertNull($form[2]->getViewData());
$this->assertNull($form[3]->getClientData()); $this->assertNull($form[3]->getViewData());
$this->assertNull($form[4]->getClientData()); $this->assertNull($form[4]->getViewData());
} }
public function testBindSingleExpandedNothingChecked() public function testBindSingleExpandedNothingChecked()
@ -281,11 +281,11 @@ class ChoiceTypeTest extends TypeTestCase
$this->assertFalse($form[2]->getData()); $this->assertFalse($form[2]->getData());
$this->assertFalse($form[3]->getData()); $this->assertFalse($form[3]->getData());
$this->assertFalse($form[4]->getData()); $this->assertFalse($form[4]->getData());
$this->assertNull($form[0]->getClientData()); $this->assertNull($form[0]->getViewData());
$this->assertNull($form[1]->getClientData()); $this->assertNull($form[1]->getViewData());
$this->assertNull($form[2]->getClientData()); $this->assertNull($form[2]->getViewData());
$this->assertNull($form[3]->getClientData()); $this->assertNull($form[3]->getViewData());
$this->assertNull($form[4]->getClientData()); $this->assertNull($form[4]->getViewData());
} }
public function testBindSingleExpandedWithFalseDoesNotHaveExtraChildren() public function testBindSingleExpandedWithFalseDoesNotHaveExtraChildren()
@ -318,8 +318,8 @@ class ChoiceTypeTest extends TypeTestCase
$this->assertNull($form->getData()); $this->assertNull($form->getData());
$this->assertTrue($form[0]->getData()); $this->assertTrue($form[0]->getData());
$this->assertFalse($form[1]->getData()); $this->assertFalse($form[1]->getData());
$this->assertSame('', $form[0]->getClientData()); $this->assertSame('', $form[0]->getViewData());
$this->assertNull($form[1]->getClientData()); $this->assertNull($form[1]->getViewData());
} }
public function testBindSingleExpandedObjectChoices() public function testBindSingleExpandedObjectChoices()
@ -346,11 +346,11 @@ class ChoiceTypeTest extends TypeTestCase
$this->assertFalse($form[2]->getData()); $this->assertFalse($form[2]->getData());
$this->assertFalse($form[3]->getData()); $this->assertFalse($form[3]->getData());
$this->assertFalse($form[4]->getData()); $this->assertFalse($form[4]->getData());
$this->assertNull($form[0]->getClientData()); $this->assertNull($form[0]->getViewData());
$this->assertSame('2', $form[1]->getClientData()); $this->assertSame('2', $form[1]->getViewData());
$this->assertNull($form[2]->getClientData()); $this->assertNull($form[2]->getViewData());
$this->assertNull($form[3]->getClientData()); $this->assertNull($form[3]->getViewData());
$this->assertNull($form[4]->getClientData()); $this->assertNull($form[4]->getViewData());
} }
public function testBindSingleExpandedNumericChoices() public function testBindSingleExpandedNumericChoices()
@ -369,11 +369,11 @@ class ChoiceTypeTest extends TypeTestCase
$this->assertFalse($form[2]->getData()); $this->assertFalse($form[2]->getData());
$this->assertFalse($form[3]->getData()); $this->assertFalse($form[3]->getData());
$this->assertFalse($form[4]->getData()); $this->assertFalse($form[4]->getData());
$this->assertNull($form[0]->getClientData()); $this->assertNull($form[0]->getViewData());
$this->assertSame('1', $form[1]->getClientData()); $this->assertSame('1', $form[1]->getViewData());
$this->assertNull($form[2]->getClientData()); $this->assertNull($form[2]->getViewData());
$this->assertNull($form[3]->getClientData()); $this->assertNull($form[3]->getViewData());
$this->assertNull($form[4]->getClientData()); $this->assertNull($form[4]->getViewData());
} }
public function testBindMultipleExpanded() public function testBindMultipleExpanded()
@ -392,11 +392,11 @@ class ChoiceTypeTest extends TypeTestCase
$this->assertTrue($form[2]->getData()); $this->assertTrue($form[2]->getData());
$this->assertFalse($form[3]->getData()); $this->assertFalse($form[3]->getData());
$this->assertFalse($form[4]->getData()); $this->assertFalse($form[4]->getData());
$this->assertSame('a', $form[0]->getClientData()); $this->assertSame('a', $form[0]->getViewData());
$this->assertNull($form[1]->getClientData()); $this->assertNull($form[1]->getViewData());
$this->assertSame('c', $form[2]->getClientData()); $this->assertSame('c', $form[2]->getViewData());
$this->assertNull($form[3]->getClientData()); $this->assertNull($form[3]->getViewData());
$this->assertNull($form[4]->getClientData()); $this->assertNull($form[4]->getViewData());
} }
public function testBindMultipleExpandedEmpty() public function testBindMultipleExpandedEmpty()
@ -415,11 +415,11 @@ class ChoiceTypeTest extends TypeTestCase
$this->assertFalse($form[2]->getData()); $this->assertFalse($form[2]->getData());
$this->assertFalse($form[3]->getData()); $this->assertFalse($form[3]->getData());
$this->assertFalse($form[4]->getData()); $this->assertFalse($form[4]->getData());
$this->assertNull($form[0]->getClientData()); $this->assertNull($form[0]->getViewData());
$this->assertNull($form[1]->getClientData()); $this->assertNull($form[1]->getViewData());
$this->assertNull($form[2]->getClientData()); $this->assertNull($form[2]->getViewData());
$this->assertNull($form[3]->getClientData()); $this->assertNull($form[3]->getViewData());
$this->assertNull($form[4]->getClientData()); $this->assertNull($form[4]->getViewData());
} }
public function testBindMultipleExpandedWithEmptyChild() public function testBindMultipleExpandedWithEmptyChild()
@ -440,9 +440,9 @@ class ChoiceTypeTest extends TypeTestCase
$this->assertTrue($form[0]->getData()); $this->assertTrue($form[0]->getData());
$this->assertFalse($form[1]->getData()); $this->assertFalse($form[1]->getData());
$this->assertTrue($form[2]->getData()); $this->assertTrue($form[2]->getData());
$this->assertSame('', $form[0]->getClientData()); $this->assertSame('', $form[0]->getViewData());
$this->assertNull($form[1]->getClientData()); $this->assertNull($form[1]->getViewData());
$this->assertSame('2', $form[2]->getClientData()); $this->assertSame('2', $form[2]->getViewData());
} }
public function testBindMultipleExpandedObjectChoices() public function testBindMultipleExpandedObjectChoices()
@ -469,11 +469,11 @@ class ChoiceTypeTest extends TypeTestCase
$this->assertFalse($form[2]->getData()); $this->assertFalse($form[2]->getData());
$this->assertFalse($form[3]->getData()); $this->assertFalse($form[3]->getData());
$this->assertFalse($form[4]->getData()); $this->assertFalse($form[4]->getData());
$this->assertSame('1', $form[0]->getClientData()); $this->assertSame('1', $form[0]->getViewData());
$this->assertSame('2', $form[1]->getClientData()); $this->assertSame('2', $form[1]->getViewData());
$this->assertNull($form[2]->getClientData()); $this->assertNull($form[2]->getViewData());
$this->assertNull($form[3]->getClientData()); $this->assertNull($form[3]->getViewData());
$this->assertNull($form[4]->getClientData()); $this->assertNull($form[4]->getViewData());
} }
public function testBindMultipleExpandedNumericChoices() public function testBindMultipleExpandedNumericChoices()
@ -492,11 +492,11 @@ class ChoiceTypeTest extends TypeTestCase
$this->assertTrue($form[2]->getData()); $this->assertTrue($form[2]->getData());
$this->assertFalse($form[3]->getData()); $this->assertFalse($form[3]->getData());
$this->assertFalse($form[4]->getData()); $this->assertFalse($form[4]->getData());
$this->assertNull($form[0]->getClientData()); $this->assertNull($form[0]->getViewData());
$this->assertSame('1', $form[1]->getClientData()); $this->assertSame('1', $form[1]->getViewData());
$this->assertSame('2', $form[2]->getClientData()); $this->assertSame('2', $form[2]->getViewData());
$this->assertNull($form[3]->getClientData()); $this->assertNull($form[3]->getViewData());
$this->assertNull($form[4]->getClientData()); $this->assertNull($form[4]->getViewData());
} }
/* /*
@ -514,7 +514,7 @@ class ChoiceTypeTest extends TypeTestCase
$form->setData(false); $form->setData(false);
$this->assertFalse($form->getData()); $this->assertFalse($form->getData());
$this->assertEquals('0', $form->getClientData()); $this->assertEquals('0', $form->getViewData());
} }
public function testSetDataMultipleNonExpandedAcceptsBoolean() public function testSetDataMultipleNonExpandedAcceptsBoolean()
@ -528,7 +528,7 @@ class ChoiceTypeTest extends TypeTestCase
$form->setData(array(false, true)); $form->setData(array(false, true));
$this->assertEquals(array(false, true), $form->getData()); $this->assertEquals(array(false, true), $form->getData());
$this->assertEquals(array('0', '1'), $form->getClientData()); $this->assertEquals(array('0', '1'), $form->getViewData());
} }
public function testPassRequiredToView() public function testPassRequiredToView()

View File

@ -173,7 +173,7 @@ class DateTimeTypeTest extends LocalizedTestCase
$outputTime->setTimezone(new \DateTimeZone('America/New_York')); $outputTime->setTimezone(new \DateTimeZone('America/New_York'));
$this->assertDateTimeEquals($outputTime, $form->getData()); $this->assertDateTimeEquals($outputTime, $form->getData());
$this->assertEquals('2010-06-02 03:04', $form->getClientData()); $this->assertEquals('2010-06-02 03:04', $form->getViewData());
} }
public function testSubmit_stringSingleText() public function testSubmit_stringSingleText()
@ -188,7 +188,7 @@ class DateTimeTypeTest extends LocalizedTestCase
$form->bind('2010-06-02 03:04:05'); $form->bind('2010-06-02 03:04:05');
$this->assertEquals('2010-06-02 03:04:00', $form->getData()); $this->assertEquals('2010-06-02 03:04:00', $form->getData());
$this->assertEquals('2010-06-02 03:04', $form->getClientData()); $this->assertEquals('2010-06-02 03:04', $form->getViewData());
} }
public function testSubmit_stringSingleText_withSeconds() public function testSubmit_stringSingleText_withSeconds()
@ -204,7 +204,7 @@ class DateTimeTypeTest extends LocalizedTestCase
$form->bind('2010-06-02 03:04:05'); $form->bind('2010-06-02 03:04:05');
$this->assertEquals('2010-06-02 03:04:05', $form->getData()); $this->assertEquals('2010-06-02 03:04:05', $form->getData());
$this->assertEquals('2010-06-02 03:04:05', $form->getClientData()); $this->assertEquals('2010-06-02 03:04:05', $form->getViewData());
} }
public function testSubmit_differentPattern() public function testSubmit_differentPattern()

View File

@ -54,7 +54,7 @@ class DateTypeTest extends LocalizedTestCase
$form->bind('2.6.2010'); $form->bind('2.6.2010');
$this->assertDateTimeEquals(new \DateTime('2010-06-02 UTC'), $form->getData()); $this->assertDateTimeEquals(new \DateTime('2010-06-02 UTC'), $form->getData());
$this->assertEquals('02.06.2010', $form->getClientData()); $this->assertEquals('02.06.2010', $form->getViewData());
} }
public function testSubmitFromSingleTextString() public function testSubmitFromSingleTextString()
@ -69,7 +69,7 @@ class DateTypeTest extends LocalizedTestCase
$form->bind('2.6.2010'); $form->bind('2.6.2010');
$this->assertEquals('2010-06-02', $form->getData()); $this->assertEquals('2010-06-02', $form->getData());
$this->assertEquals('02.06.2010', $form->getClientData()); $this->assertEquals('02.06.2010', $form->getViewData());
} }
public function testSubmitFromSingleTextTimestamp() public function testSubmitFromSingleTextTimestamp()
@ -86,7 +86,7 @@ class DateTypeTest extends LocalizedTestCase
$dateTime = new \DateTime('2010-06-02 UTC'); $dateTime = new \DateTime('2010-06-02 UTC');
$this->assertEquals($dateTime->format('U'), $form->getData()); $this->assertEquals($dateTime->format('U'), $form->getData());
$this->assertEquals('02.06.2010', $form->getClientData()); $this->assertEquals('02.06.2010', $form->getViewData());
} }
public function testSubmitFromSingleTextRaw() public function testSubmitFromSingleTextRaw()
@ -107,7 +107,7 @@ class DateTypeTest extends LocalizedTestCase
); );
$this->assertEquals($output, $form->getData()); $this->assertEquals($output, $form->getData());
$this->assertEquals('02.06.2010', $form->getClientData()); $this->assertEquals('02.06.2010', $form->getViewData());
} }
public function testSubmitFromText() public function testSubmitFromText()
@ -129,7 +129,7 @@ class DateTypeTest extends LocalizedTestCase
$dateTime = new \DateTime('2010-06-02 UTC'); $dateTime = new \DateTime('2010-06-02 UTC');
$this->assertDateTimeEquals($dateTime, $form->getData()); $this->assertDateTimeEquals($dateTime, $form->getData());
$this->assertEquals($text, $form->getClientData()); $this->assertEquals($text, $form->getViewData());
} }
public function testSubmitFromChoice() public function testSubmitFromChoice()
@ -151,7 +151,7 @@ class DateTypeTest extends LocalizedTestCase
$dateTime = new \DateTime('2010-06-02 UTC'); $dateTime = new \DateTime('2010-06-02 UTC');
$this->assertDateTimeEquals($dateTime, $form->getData()); $this->assertDateTimeEquals($dateTime, $form->getData());
$this->assertEquals($text, $form->getClientData()); $this->assertEquals($text, $form->getViewData());
} }
public function testSubmitFromChoiceEmpty() public function testSubmitFromChoiceEmpty()
@ -172,7 +172,7 @@ class DateTypeTest extends LocalizedTestCase
$form->bind($text); $form->bind($text);
$this->assertNull($form->getData()); $this->assertNull($form->getData());
$this->assertEquals($text, $form->getClientData()); $this->assertEquals($text, $form->getViewData());
} }
public function testSubmitFromInputDateTimeDifferentPattern() public function testSubmitFromInputDateTimeDifferentPattern()
@ -188,7 +188,7 @@ class DateTypeTest extends LocalizedTestCase
$form->bind('06*2010*02'); $form->bind('06*2010*02');
$this->assertDateTimeEquals(new \DateTime('2010-06-02 UTC'), $form->getData()); $this->assertDateTimeEquals(new \DateTime('2010-06-02 UTC'), $form->getData());
$this->assertEquals('06*2010*02', $form->getClientData()); $this->assertEquals('06*2010*02', $form->getViewData());
} }
public function testSubmitFromInputStringDifferentPattern() public function testSubmitFromInputStringDifferentPattern()
@ -204,7 +204,7 @@ class DateTypeTest extends LocalizedTestCase
$form->bind('06*2010*02'); $form->bind('06*2010*02');
$this->assertEquals('2010-06-02', $form->getData()); $this->assertEquals('2010-06-02', $form->getData());
$this->assertEquals('06*2010*02', $form->getClientData()); $this->assertEquals('06*2010*02', $form->getViewData());
} }
public function testSubmitFromInputTimestampDifferentPattern() public function testSubmitFromInputTimestampDifferentPattern()
@ -222,7 +222,7 @@ class DateTypeTest extends LocalizedTestCase
$dateTime = new \DateTime('2010-06-02 UTC'); $dateTime = new \DateTime('2010-06-02 UTC');
$this->assertEquals($dateTime->format('U'), $form->getData()); $this->assertEquals($dateTime->format('U'), $form->getData());
$this->assertEquals('06*2010*02', $form->getClientData()); $this->assertEquals('06*2010*02', $form->getViewData());
} }
public function testSubmitFromInputRawDifferentPattern() public function testSubmitFromInputRawDifferentPattern()
@ -244,7 +244,7 @@ class DateTypeTest extends LocalizedTestCase
); );
$this->assertEquals($output, $form->getData()); $this->assertEquals($output, $form->getData());
$this->assertEquals('06*2010*02', $form->getClientData()); $this->assertEquals('06*2010*02', $form->getViewData());
} }
/** /**
@ -262,7 +262,7 @@ class DateTypeTest extends LocalizedTestCase
$form->setData('2010-06-02'); $form->setData('2010-06-02');
// This would be what would be outputed if '0' was mistaken for \IntlDateFormatter::FULL // This would be what would be outputed if '0' was mistaken for \IntlDateFormatter::FULL
$this->assertNotEquals('Mittwoch, 02. Juni 2010', $form->getClientData()); $this->assertNotEquals('Mittwoch, 02. Juni 2010', $form->getViewData());
} }
/** /**
@ -296,7 +296,7 @@ class DateTypeTest extends LocalizedTestCase
$form->setData('2010-06-02'); $form->setData('2010-06-02');
$this->assertEquals('01.06.2010', $form->getClientData()); $this->assertEquals('01.06.2010', $form->getViewData());
} }
public function testSetData_differentTimezonesDateTime() public function testSetData_differentTimezonesDateTime()
@ -313,7 +313,7 @@ class DateTypeTest extends LocalizedTestCase
$form->setData($dateTime); $form->setData($dateTime);
$this->assertDateTimeEquals($dateTime, $form->getData()); $this->assertDateTimeEquals($dateTime, $form->getData());
$this->assertEquals('01.06.2010', $form->getClientData()); $this->assertEquals('01.06.2010', $form->getViewData());
} }
public function testYearsOption() public function testYearsOption()

View File

@ -81,7 +81,7 @@ class FormTypeTest extends TypeTestCase
$form->bind(' a '); $form->bind(' a ');
$this->assertEquals('a', $form->getClientData()); $this->assertEquals('a', $form->getViewData());
$this->assertEquals('reverse[a]', $form->getData()); $this->assertEquals('reverse[a]', $form->getData());
} }
@ -96,7 +96,7 @@ class FormTypeTest extends TypeTestCase
$form->bind(' a '); $form->bind(' a ');
$this->assertEquals(' a ', $form->getClientData()); $this->assertEquals(' a ', $form->getViewData());
$this->assertEquals('reverse[ a ]', $form->getData()); $this->assertEquals('reverse[ a ]', $form->getData());
} }

View File

@ -20,6 +20,6 @@ class IntegerTypeTest extends LocalizedTestCase
$form->bind('1.678'); $form->bind('1.678');
$this->assertSame(1, $form->getData()); $this->assertSame(1, $form->getData());
$this->assertSame('1', $form->getClientData()); $this->assertSame('1', $form->getViewData());
} }
} }

View File

@ -93,10 +93,10 @@ class RepeatedTypeTest extends TypeTestCase
$this->form->bind($input); $this->form->bind($input);
$this->assertEquals('foo', $this->form['first']->getClientData()); $this->assertEquals('foo', $this->form['first']->getViewData());
$this->assertEquals('bar', $this->form['second']->getClientData()); $this->assertEquals('bar', $this->form['second']->getViewData());
$this->assertFalse($this->form->isSynchronized()); $this->assertFalse($this->form->isSynchronized());
$this->assertEquals($input, $this->form->getClientData()); $this->assertEquals($input, $this->form->getViewData());
$this->assertNull($this->form->getData()); $this->assertNull($this->form->getData());
} }
@ -106,10 +106,10 @@ class RepeatedTypeTest extends TypeTestCase
$this->form->bind($input); $this->form->bind($input);
$this->assertEquals('foo', $this->form['first']->getClientData()); $this->assertEquals('foo', $this->form['first']->getViewData());
$this->assertEquals('foo', $this->form['second']->getClientData()); $this->assertEquals('foo', $this->form['second']->getViewData());
$this->assertTrue($this->form->isSynchronized()); $this->assertTrue($this->form->isSynchronized());
$this->assertEquals($input, $this->form->getClientData()); $this->assertEquals($input, $this->form->getViewData());
$this->assertEquals('foo', $this->form->getData()); $this->assertEquals('foo', $this->form->getData());
} }
} }

View File

@ -33,7 +33,7 @@ class TimeTypeTest extends LocalizedTestCase
$dateTime = new \DateTime('1970-01-01 03:04:00 UTC'); $dateTime = new \DateTime('1970-01-01 03:04:00 UTC');
$this->assertEquals($dateTime, $form->getData()); $this->assertEquals($dateTime, $form->getData());
$this->assertEquals($input, $form->getClientData()); $this->assertEquals($input, $form->getViewData());
} }
public function testSubmit_string() public function testSubmit_string()
@ -52,7 +52,7 @@ class TimeTypeTest extends LocalizedTestCase
$form->bind($input); $form->bind($input);
$this->assertEquals('03:04:00', $form->getData()); $this->assertEquals('03:04:00', $form->getData());
$this->assertEquals($input, $form->getClientData()); $this->assertEquals($input, $form->getViewData());
} }
public function testSubmit_timestamp() public function testSubmit_timestamp()
@ -73,7 +73,7 @@ class TimeTypeTest extends LocalizedTestCase
$dateTime = new \DateTime('1970-01-01 03:04:00 UTC'); $dateTime = new \DateTime('1970-01-01 03:04:00 UTC');
$this->assertEquals($dateTime->format('U'), $form->getData()); $this->assertEquals($dateTime->format('U'), $form->getData());
$this->assertEquals($input, $form->getClientData()); $this->assertEquals($input, $form->getViewData());
} }
public function testSubmit_array() public function testSubmit_array()
@ -92,7 +92,7 @@ class TimeTypeTest extends LocalizedTestCase
$form->bind($input); $form->bind($input);
$this->assertEquals($input, $form->getData()); $this->assertEquals($input, $form->getData());
$this->assertEquals($input, $form->getClientData()); $this->assertEquals($input, $form->getViewData());
} }
public function testSubmit_datetimeSingleText() public function testSubmit_datetimeSingleText()
@ -107,7 +107,7 @@ class TimeTypeTest extends LocalizedTestCase
$form->bind('03:04:05'); $form->bind('03:04:05');
$this->assertEquals(new \DateTime('03:04:00 UTC'), $form->getData()); $this->assertEquals(new \DateTime('03:04:00 UTC'), $form->getData());
$this->assertEquals('03:04', $form->getClientData()); $this->assertEquals('03:04', $form->getViewData());
} }
public function testSubmit_arraySingleText() public function testSubmit_arraySingleText()
@ -127,7 +127,7 @@ class TimeTypeTest extends LocalizedTestCase
$form->bind('03:04'); $form->bind('03:04');
$this->assertEquals($data, $form->getData()); $this->assertEquals($data, $form->getData());
$this->assertEquals('03:04', $form->getClientData()); $this->assertEquals('03:04', $form->getViewData());
} }
public function testSubmit_arraySingleTextWithSeconds() public function testSubmit_arraySingleTextWithSeconds()
@ -149,7 +149,7 @@ class TimeTypeTest extends LocalizedTestCase
$form->bind('03:04:05'); $form->bind('03:04:05');
$this->assertEquals($data, $form->getData()); $this->assertEquals($data, $form->getData());
$this->assertEquals('03:04:05', $form->getClientData()); $this->assertEquals('03:04:05', $form->getViewData());
} }
public function testSubmit_stringSingleText() public function testSubmit_stringSingleText()
@ -164,7 +164,7 @@ class TimeTypeTest extends LocalizedTestCase
$form->bind('03:04:05'); $form->bind('03:04:05');
$this->assertEquals('03:04:00', $form->getData()); $this->assertEquals('03:04:00', $form->getData());
$this->assertEquals('03:04', $form->getClientData()); $this->assertEquals('03:04', $form->getViewData());
} }
public function testSetData_withSeconds() public function testSetData_withSeconds()
@ -178,7 +178,7 @@ class TimeTypeTest extends LocalizedTestCase
$form->setData(new \DateTime('03:04:05 UTC')); $form->setData(new \DateTime('03:04:05 UTC'));
$this->assertEquals(array('hour' => 3, 'minute' => 4, 'second' => 5), $form->getClientData()); $this->assertEquals(array('hour' => 3, 'minute' => 4, 'second' => 5), $form->getViewData());
} }
public function testSetData_differentTimezones() public function testSetData_differentTimezones()
@ -204,7 +204,7 @@ class TimeTypeTest extends LocalizedTestCase
'second' => (int)$outputTime->format('s') 'second' => (int)$outputTime->format('s')
); );
$this->assertEquals($displayedData, $form->getClientData()); $this->assertEquals($displayedData, $form->getViewData());
} }
public function testSetData_differentTimezonesDateTime() public function testSetData_differentTimezonesDateTime()
@ -231,7 +231,7 @@ class TimeTypeTest extends LocalizedTestCase
); );
$this->assertDateTimeEquals($dateTime, $form->getData()); $this->assertDateTimeEquals($dateTime, $form->getData());
$this->assertEquals($displayedData, $form->getClientData()); $this->assertEquals($displayedData, $form->getViewData());
} }
public function testHoursOption() public function testHoursOption()

View File

@ -20,7 +20,7 @@ class UrlTypeTest extends LocalizedTestCase
$form->bind('www.domain.com'); $form->bind('www.domain.com');
$this->assertSame('http://www.domain.com', $form->getData()); $this->assertSame('http://www.domain.com', $form->getData());
$this->assertSame('http://www.domain.com', $form->getClientData()); $this->assertSame('http://www.domain.com', $form->getViewData());
} }
public function testSubmitAddsNoDefaultProtocolIfAlreadyIncluded() public function testSubmitAddsNoDefaultProtocolIfAlreadyIncluded()
@ -32,7 +32,7 @@ class UrlTypeTest extends LocalizedTestCase
$form->bind('ftp://www.domain.com'); $form->bind('ftp://www.domain.com');
$this->assertSame('ftp://www.domain.com', $form->getData()); $this->assertSame('ftp://www.domain.com', $form->getData());
$this->assertSame('ftp://www.domain.com', $form->getClientData()); $this->assertSame('ftp://www.domain.com', $form->getViewData());
} }
public function testSubmitAddsNoDefaultProtocolIfEmpty() public function testSubmitAddsNoDefaultProtocolIfEmpty()
@ -44,7 +44,7 @@ class UrlTypeTest extends LocalizedTestCase
$form->bind(''); $form->bind('');
$this->assertSame('', $form->getData()); $this->assertSame('', $form->getData());
$this->assertSame('', $form->getClientData()); $this->assertSame('', $form->getViewData());
} }
public function testSubmitAddsNoDefaultProtocolIfSetToNull() public function testSubmitAddsNoDefaultProtocolIfSetToNull()
@ -56,6 +56,6 @@ class UrlTypeTest extends LocalizedTestCase
$form->bind('www.domain.com'); $form->bind('www.domain.com');
$this->assertSame('www.domain.com', $form->getData()); $this->assertSame('www.domain.com', $form->getData());
$this->assertSame('www.domain.com', $form->getClientData()); $this->assertSame('www.domain.com', $form->getViewData());
} }
} }

View File

@ -12,7 +12,7 @@
namespace Symfony\Component\Form\Tests\Fixtures; namespace Symfony\Component\Form\Tests\Fixtures;
use Symfony\Component\Form\FormEvents; use Symfony\Component\Form\FormEvents;
use Symfony\Component\Form\Event\FilterDataEvent; use Symfony\Component\Form\FormEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class FixedFilterListener implements EventSubscriberInterface class FixedFilterListener implements EventSubscriberInterface
@ -22,45 +22,45 @@ class FixedFilterListener implements EventSubscriberInterface
public function __construct(array $mapping) public function __construct(array $mapping)
{ {
$this->mapping = array_merge(array( $this->mapping = array_merge(array(
'onBindClientData' => array(), 'preBind' => array(),
'onBindNormData' => array(), 'onBind' => array(),
'onSetData' => array(), 'preSetData' => array(),
), $mapping); ), $mapping);
} }
public function onBindClientData(FilterDataEvent $event) public function preBind(FormEvent $event)
{ {
$data = $event->getData(); $data = $event->getData();
if (isset($this->mapping['onBindClientData'][$data])) { if (isset($this->mapping['preBind'][$data])) {
$event->setData($this->mapping['onBindClientData'][$data]); $event->setData($this->mapping['preBind'][$data]);
} }
} }
public function onBindNormData(FilterDataEvent $event) public function onBind(FormEvent $event)
{ {
$data = $event->getData(); $data = $event->getData();
if (isset($this->mapping['onBindNormData'][$data])) { if (isset($this->mapping['onBind'][$data])) {
$event->setData($this->mapping['onBindNormData'][$data]); $event->setData($this->mapping['onBind'][$data]);
} }
} }
public function onSetData(FilterDataEvent $event) public function preSetData(FormEvent $event)
{ {
$data = $event->getData(); $data = $event->getData();
if (isset($this->mapping['onSetData'][$data])) { if (isset($this->mapping['preSetData'][$data])) {
$event->setData($this->mapping['onSetData'][$data]); $event->setData($this->mapping['preSetData'][$data]);
} }
} }
public static function getSubscribedEvents() public static function getSubscribedEvents()
{ {
return array( return array(
FormEvents::BIND_CLIENT_DATA => 'onBindClientData', FormEvents::PRE_BIND => 'preBind',
FormEvents::BIND_NORM_DATA => 'onBindNormData', FormEvents::BIND => 'onBind',
FormEvents::SET_DATA => 'onSetData', FormEvents::PRE_SET_DATA => 'preSetData',
); );
} }
} }

View File

@ -55,16 +55,16 @@ class FormTest extends \PHPUnit_Framework_TestCase
public function testDataIsInitializedEmpty() public function testDataIsInitializedEmpty()
{ {
$norm = new FixedDataTransformer(array( $model = new FixedDataTransformer(array(
'' => 'foo', '' => 'foo',
)); ));
$client = new FixedDataTransformer(array( $view = new FixedDataTransformer(array(
'foo' => 'bar', 'foo' => 'bar',
)); ));
$config = new FormConfig('name', null, $this->dispatcher); $config = new FormConfig('name', null, $this->dispatcher);
$config->addViewTransformer($client); $config->addViewTransformer($view);
$config->appendNormTransformer($norm); $config->addModelTransformer($model);
$form = new Form($config); $form = new Form($config);
$this->assertNull($form->getData()); $this->assertNull($form->getData());
@ -488,11 +488,11 @@ class FormTest extends \PHPUnit_Framework_TestCase
// use real event dispatcher now // use real event dispatcher now
$form = $this->getBuilder('name', new EventDispatcher()) $form = $this->getBuilder('name', new EventDispatcher())
->addEventSubscriber(new FixedFilterListener(array( ->addEventSubscriber(new FixedFilterListener(array(
'onSetData' => array( 'preSetData' => array(
'app' => 'filtered', 'app' => 'filtered',
), ),
))) )))
->appendNormTransformer(new FixedDataTransformer(array( ->addModelTransformer(new FixedDataTransformer(array(
'' => '', '' => '',
'filtered' => 'norm', 'filtered' => 'norm',
))) )))
@ -506,10 +506,10 @@ class FormTest extends \PHPUnit_Framework_TestCase
$this->assertEquals('filtered', $form->getData()); $this->assertEquals('filtered', $form->getData());
$this->assertEquals('norm', $form->getNormData()); $this->assertEquals('norm', $form->getNormData());
$this->assertEquals('client', $form->getClientData()); $this->assertEquals('client', $form->getViewData());
} }
public function testSetDataExecutesClientTransformersInOrder() public function testSetDataExecutesViewTransformersInOrder()
{ {
$form = $this->getBuilder() $form = $this->getBuilder()
->addViewTransformer(new FixedDataTransformer(array( ->addViewTransformer(new FixedDataTransformer(array(
@ -524,20 +524,20 @@ class FormTest extends \PHPUnit_Framework_TestCase
$form->setData('first'); $form->setData('first');
$this->assertEquals('third', $form->getClientData()); $this->assertEquals('third', $form->getViewData());
} }
public function testSetDataExecutesNormTransformersInOrder() public function testSetDataExecutesModelTransformersInReverseOrder()
{ {
$form = $this->getBuilder() $form = $this->getBuilder()
->appendNormTransformer(new FixedDataTransformer(array( ->addModelTransformer(new FixedDataTransformer(array(
'' => '',
'first' => 'second',
)))
->appendNormTransformer(new FixedDataTransformer(array(
'' => '', '' => '',
'second' => 'third', 'second' => 'third',
))) )))
->addModelTransformer(new FixedDataTransformer(array(
'' => '',
'first' => 'second',
)))
->getForm(); ->getForm();
$form->setData('first'); $form->setData('first');
@ -564,10 +564,10 @@ class FormTest extends \PHPUnit_Framework_TestCase
* Data in client format should, if possible, always be a string to * Data in client format should, if possible, always be a string to
* facilitate differentiation between '0' and '' * facilitate differentiation between '0' and ''
*/ */
public function testSetDataConvertsScalarToStringIfOnlyNormTransformer() public function testSetDataConvertsScalarToStringIfOnlyModelTransformer()
{ {
$form = $this->getBuilder() $form = $this->getBuilder()
->appendNormTransformer(new FixedDataTransformer(array( ->addModelTransformer(new FixedDataTransformer(array(
'' => '', '' => '',
1 => 23, 1 => 23,
))) )))
@ -577,7 +577,7 @@ class FormTest extends \PHPUnit_Framework_TestCase
$this->assertSame(1, $form->getData()); $this->assertSame(1, $form->getData());
$this->assertSame(23, $form->getNormData()); $this->assertSame(23, $form->getNormData());
$this->assertSame('23', $form->getClientData()); $this->assertSame('23', $form->getViewData());
} }
/* /*
@ -611,10 +611,10 @@ class FormTest extends \PHPUnit_Framework_TestCase
// use real event dispatcher now // use real event dispatcher now
$form = $this->getBuilder('name', new EventDispatcher()) $form = $this->getBuilder('name', new EventDispatcher())
->addEventSubscriber(new FixedFilterListener(array( ->addEventSubscriber(new FixedFilterListener(array(
'onBindClientData' => array( 'preBind' => array(
'client' => 'filteredclient', 'client' => 'filteredclient',
), ),
'onBindNormData' => array( 'onBind' => array(
'norm' => 'filterednorm', 'norm' => 'filterednorm',
), ),
))) )))
@ -624,7 +624,7 @@ class FormTest extends \PHPUnit_Framework_TestCase
'norm' => 'filteredclient', 'norm' => 'filteredclient',
'filterednorm' => 'cleanedclient' 'filterednorm' => 'cleanedclient'
))) )))
->appendNormTransformer(new FixedDataTransformer(array( ->addModelTransformer(new FixedDataTransformer(array(
'' => '', '' => '',
// direction is reversed! // direction is reversed!
'app' => 'filterednorm', 'app' => 'filterednorm',
@ -635,10 +635,10 @@ class FormTest extends \PHPUnit_Framework_TestCase
$this->assertEquals('app', $form->getData()); $this->assertEquals('app', $form->getData());
$this->assertEquals('filterednorm', $form->getNormData()); $this->assertEquals('filterednorm', $form->getNormData());
$this->assertEquals('cleanedclient', $form->getClientData()); $this->assertEquals('cleanedclient', $form->getViewData());
} }
public function testBindExecutesClientTransformersInReverseOrder() public function testBindExecutesViewTransformersInReverseOrder()
{ {
$form = $this->getBuilder() $form = $this->getBuilder()
->addViewTransformer(new FixedDataTransformer(array( ->addViewTransformer(new FixedDataTransformer(array(
@ -656,17 +656,17 @@ class FormTest extends \PHPUnit_Framework_TestCase
$this->assertEquals('third', $form->getNormData()); $this->assertEquals('third', $form->getNormData());
} }
public function testBindExecutesNormTransformersInReverseOrder() public function testBindExecutesModelTransformersInOrder()
{ {
$form = $this->getBuilder() $form = $this->getBuilder()
->appendNormTransformer(new FixedDataTransformer(array( ->addModelTransformer(new FixedDataTransformer(array(
'' => '',
'third' => 'second',
)))
->appendNormTransformer(new FixedDataTransformer(array(
'' => '', '' => '',
'second' => 'first', 'second' => 'first',
))) )))
->addModelTransformer(new FixedDataTransformer(array(
'' => '',
'third' => 'second',
)))
->getForm(); ->getForm();
$form->bind('first'); $form->bind('first');