Permalink
Browse files

[Form] Merged various form events and added class FormEvent

  • Loading branch information...
1 parent adc9c6d commit ef6132d61b30639eda1d0776b1d787e18a539b02 @webmozart webmozart committed May 23, 2012
Showing with 300 additions and 246 deletions.
  1. +7 −0 CHANGELOG.md
  2. +16 −0 Event/DataEvent.php
  3. +6 −9 Event/FilterDataEvent.php
  4. +3 −3 Extension/Core/EventListener/FixCheckboxInputListener.php
  5. +3 −3 Extension/Core/EventListener/FixRadioInputListener.php
  6. +3 −3 Extension/Core/EventListener/FixUrlProtocolListener.php
  7. +3 −5 Extension/Core/EventListener/MergeCollectionListener.php
  8. +5 −6 Extension/Core/EventListener/ResizeFormListener.php
  9. +3 −3 Extension/Core/EventListener/TrimListener.php
  10. +3 −3 Extension/Csrf/EventListener/CsrfValidationListener.php
  11. +12 −13 Form.php
  12. +21 −0 FormEvent.php
  13. +18 −0 FormEvents.php
  14. +7 −7 Tests/Extension/Core/EventListener/FixRadioInputListenerTest.php
  15. +7 −7 Tests/Extension/Core/EventListener/FixUrlProtocolListenerTest.php
  16. +19 −19 Tests/Extension/Core/EventListener/MergeCollectionListenerTest.php
  17. +19 −20 Tests/Extension/Core/EventListener/ResizeFormListenerTest.php
  18. +5 −5 Tests/Extension/Core/EventListener/TrimListenerTest.php
  19. +5 −5 Tests/Extension/Core/Type/CheckboxTypeTest.php
  20. +51 −51 Tests/Extension/Core/Type/ChoiceTypeTest.php
  21. +3 −3 Tests/Extension/Core/Type/DateTimeTypeTest.php
  22. +14 −14 Tests/Extension/Core/Type/DateTypeTest.php
  23. +2 −2 Tests/Extension/Core/Type/FormTypeTest.php
  24. +1 −1 Tests/Extension/Core/Type/IntegerTypeTest.php
  25. +6 −6 Tests/Extension/Core/Type/RepeatedTypeTest.php
  26. +11 −11 Tests/Extension/Core/Type/TimeTypeTest.php
  27. +4 −4 Tests/Extension/Core/Type/UrlTypeTest.php
  28. +16 −16 Tests/Fixtures/FixedFilterListener.php
  29. +27 −27 Tests/FormTest.php
View
7 CHANGELOG.md
@@ -124,3 +124,10 @@ CHANGELOG
* `finishView`
in FormTypeInterface and FormTypeExtensionInterface
* [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
16 Event/DataEvent.php
@@ -14,6 +14,12 @@
use Symfony\Component\EventDispatcher\Event;
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
{
private $form;
@@ -50,4 +56,14 @@ public function getData()
{
return $this->data;
}
+
+ /**
+ * Allows updating with some filtered data
+ *
+ * @param mixed $data
+ */
+ public function setData($data)
+ {
+ $this->data = $data;
+ }
}
View
15 Event/FilterDataEvent.php
@@ -11,15 +11,12 @@
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
{
- /**
- * Allows updating with some filtered data
- *
- * @param mixed $data
- */
- public function setData($data)
- {
- $this->data = $data;
- }
}
View
6 Extension/Core/EventListener/FixCheckboxInputListener.php
@@ -12,7 +12,7 @@
namespace Symfony\Component\Form\Extension\Core\EventListener;
use Symfony\Component\Form\FormEvents;
-use Symfony\Component\Form\Event\FilterDataEvent;
+use Symfony\Component\Form\FormEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Form\Extension\Core\ChoiceList\ChoiceListInterface;
@@ -36,7 +36,7 @@ public function __construct(ChoiceListInterface $choiceList)
$this->choiceList = $choiceList;
}
- public function onBindClientData(FilterDataEvent $event)
+ public function preBind(FormEvent $event)
{
$values = (array) $event->getData();
$indices = $this->choiceList->getIndicesForValues($values);
@@ -46,6 +46,6 @@ public function onBindClientData(FilterDataEvent $event)
static public function getSubscribedEvents()
{
- return array(FormEvents::BIND_CLIENT_DATA => 'onBindClientData');
+ return array(FormEvents::PRE_BIND => 'preBind');
}
}
View
6 Extension/Core/EventListener/FixRadioInputListener.php
@@ -12,7 +12,7 @@
namespace Symfony\Component\Form\Extension\Core\EventListener;
use Symfony\Component\Form\FormEvents;
-use Symfony\Component\Form\Event\FilterDataEvent;
+use Symfony\Component\Form\FormEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Form\Extension\Core\ChoiceList\ChoiceListInterface;
@@ -36,7 +36,7 @@ public function __construct(ChoiceListInterface $choiceList)
$this->choiceList = $choiceList;
}
- public function onBindClientData(FilterDataEvent $event)
+ public function preBind(FormEvent $event)
{
$value = $event->getData();
$index = current($this->choiceList->getIndicesForValues(array($value)));
@@ -46,6 +46,6 @@ public function onBindClientData(FilterDataEvent $event)
static public function getSubscribedEvents()
{
- return array(FormEvents::BIND_CLIENT_DATA => 'onBindClientData');
+ return array(FormEvents::PRE_BIND => 'preBind');
}
}
View
6 Extension/Core/EventListener/FixUrlProtocolListener.php
@@ -12,7 +12,7 @@
namespace Symfony\Component\Form\Extension\Core\EventListener;
use Symfony\Component\Form\FormEvents;
-use Symfony\Component\Form\Event\FilterDataEvent;
+use Symfony\Component\Form\FormEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
/**
@@ -29,7 +29,7 @@ public function __construct($defaultProtocol = 'http')
$this->defaultProtocol = $defaultProtocol;
}
- public function onBindNormData(FilterDataEvent $event)
+ public function onBind(FormEvent $event)
{
$data = $event->getData();
@@ -40,6 +40,6 @@ public function onBindNormData(FilterDataEvent $event)
static public function getSubscribedEvents()
{
- return array(FormEvents::BIND_NORM_DATA => 'onBindNormData');
+ return array(FormEvents::BIND => 'onBind');
}
}
View
8 Extension/Core/EventListener/MergeCollectionListener.php
@@ -13,7 +13,7 @@
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Form\FormEvents;
-use Symfony\Component\Form\Event\FilterDataEvent;
+use Symfony\Component\Form\FormEvent;
use Symfony\Component\Form\Exception\UnexpectedTypeException;
/**
@@ -50,15 +50,13 @@ public function __construct($allowAdd = false, $allowDelete = false)
static public function getSubscribedEvents()
{
return array(
- FormEvents::BIND_NORM_DATA => 'onBindNormData',
+ FormEvents::BIND => 'onBind',
);
}
- public function onBindNormData(FilterDataEvent $event)
+ public function onBind(FormEvent $event)
{
$dataToMergeInto = $event->getForm()->getNormData();
-
- $form = $event->getForm();
$data = $event->getData();
if (null === $data) {
View
11 Extension/Core/EventListener/ResizeFormListener.php
@@ -12,8 +12,7 @@
namespace Symfony\Component\Form\Extension\Core\EventListener;
use Symfony\Component\Form\FormEvents;
-use Symfony\Component\Form\Event\DataEvent;
-use Symfony\Component\Form\Event\FilterDataEvent;
+use Symfony\Component\Form\FormEvent;
use Symfony\Component\Form\FormFactoryInterface;
use Symfony\Component\Form\Exception\UnexpectedTypeException;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
@@ -67,11 +66,11 @@ static public function getSubscribedEvents()
FormEvents::PRE_SET_DATA => 'preSetData',
FormEvents::PRE_BIND => 'preBind',
// (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();
$data = $event->getData();
@@ -97,7 +96,7 @@ public function preSetData(DataEvent $event)
}
}
- public function preBind(DataEvent $event)
+ public function preBind(FormEvent $event)
{
$form = $event->getForm();
$data = $event->getData();
@@ -131,7 +130,7 @@ public function preBind(DataEvent $event)
}
}
- public function onBindNormData(FilterDataEvent $event)
+ public function onBind(FormEvent $event)
{
$form = $event->getForm();
$data = $event->getData();
View
6 Extension/Core/EventListener/TrimListener.php
@@ -12,7 +12,7 @@
namespace Symfony\Component\Form\Extension\Core\EventListener;
use Symfony\Component\Form\FormEvents;
-use Symfony\Component\Form\Event\FilterDataEvent;
+use Symfony\Component\Form\FormEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
/**
@@ -22,7 +22,7 @@
*/
class TrimListener implements EventSubscriberInterface
{
- public function onBindClientData(FilterDataEvent $event)
+ public function preBind(FormEvent $event)
{
$data = $event->getData();
@@ -33,6 +33,6 @@ public function onBindClientData(FilterDataEvent $event)
static public function getSubscribedEvents()
{
- return array(FormEvents::BIND_CLIENT_DATA => 'onBindClientData');
+ return array(FormEvents::PRE_BIND => 'preBind');
}
}
View
6 Extension/Csrf/EventListener/CsrfValidationListener.php
@@ -14,7 +14,7 @@
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Form\FormEvents;
use Symfony\Component\Form\FormError;
-use Symfony\Component\Form\Event\FilterDataEvent;
+use Symfony\Component\Form\FormEvent;
use Symfony\Component\Form\Extension\Csrf\CsrfProvider\CsrfProviderInterface;
/**
@@ -47,7 +47,7 @@ class CsrfValidationListener implements EventSubscriberInterface
static public function getSubscribedEvents()
{
return array(
- FormEvents::BIND_CLIENT_DATA => 'onBindClientData',
+ FormEvents::PRE_BIND => 'preBind',
);
}
@@ -58,7 +58,7 @@ public function __construct($fieldName, CsrfProviderInterface $csrfProvider, $in
$this->intention = $intention;
}
- public function onBindClientData(FilterDataEvent $event)
+ public function preBind(FormEvent $event)
{
$form = $event->getForm();
$data = $event->getData();
View
25 Form.php
@@ -11,8 +11,6 @@
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\AlreadyBoundException;
use Symfony\Component\Form\Exception\UnexpectedTypeException;
@@ -329,11 +327,10 @@ public function setData($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
- $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);
$modelData = $event->getData();
@@ -383,7 +380,7 @@ public function setData($modelData)
$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);
return $this;
@@ -465,16 +462,15 @@ public function bind($submittedData)
// errors added during listeners
$this->errors = array();
- $event = new DataEvent($this, $submittedData);
- $this->config->getEventDispatcher()->dispatch(FormEvents::PRE_BIND, $event);
-
$modelData = null;
$normData = null;
$extraData = array();
$synchronized = false;
// 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);
$submittedData = $event->getData();
@@ -537,10 +533,13 @@ public function bind($submittedData)
if ($synchronized) {
// Hook to change content of the data into the normalized
// 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);
$normData = $event->getData();
+
// Synchronize representations - must not change the content!
$modelData = $this->normToModel($normData);
$viewData = $this->normToView($normData);
@@ -553,7 +552,7 @@ public function bind($submittedData)
$this->extraData = $extraData;
$this->synchronized = $synchronized;
- $event = new DataEvent($this, $viewData);
+ $event = new FormEvent($this, $viewData);
$this->config->getEventDispatcher()->dispatch(FormEvents::POST_BIND, $event);
foreach ($this->config->getValidators() as $validator) {
View
21 FormEvent.php
@@ -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
18 FormEvents.php
@@ -18,15 +18,33 @@
{
const PRE_BIND = 'form.pre_bind';
+ const BIND = 'form.bind';
+
const POST_BIND = 'form.post_bind';
const PRE_SET_DATA = 'form.pre_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';
+ /**
+ * @deprecated Deprecated since version 2.1, to be removed in 2.3.
+ * Use {@link BIND} instead.
+ */
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';
+
+ private function __construct()
+ {
+ }
}
View
14 Tests/Extension/Core/EventListener/FixRadioInputListenerTest.php
@@ -11,7 +11,7 @@
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\ChoiceList\SimpleChoiceList;
@@ -42,9 +42,9 @@ public function testFixRadio()
{
$data = '1';
$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());
}
@@ -53,9 +53,9 @@ public function testFixZero()
{
$data = '0';
$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());
}
@@ -64,9 +64,9 @@ public function testIgnoreEmptyString()
{
$data = '';
$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());
}
View
14 Tests/Extension/Core/EventListener/FixUrlProtocolListenerTest.php
@@ -11,7 +11,7 @@
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;
class FixUrlProtocolListenerTest extends \PHPUnit_Framework_TestCase
@@ -27,10 +27,10 @@ public function testFixHttpUrl()
{
$data = "www.symfony.com";
$form = $this->getMock('Symfony\Component\Form\Tests\FormInterface');
- $event = new FilterDataEvent($form, $data);
+ $event = new FormEvent($form, $data);
$filter = new FixUrlProtocolListener('http');
- $filter->onBindNormData($event);
+ $filter->onBind($event);
$this->assertEquals('http://www.symfony.com', $event->getData());
}
@@ -39,10 +39,10 @@ public function testSkipKnownUrl()
{
$data = "http://www.symfony.com";
$form = $this->getMock('Symfony\Component\Form\Tests\FormInterface');
- $event = new FilterDataEvent($form, $data);
+ $event = new FormEvent($form, $data);
$filter = new FixUrlProtocolListener('http');
- $filter->onBindNormData($event);
+ $filter->onBind($event);
$this->assertEquals('http://www.symfony.com', $event->getData());
}
@@ -51,10 +51,10 @@ public function testSkipOtherProtocol()
{
$data = "ftp://www.symfony.com";
$form = $this->getMock('Symfony\Component\Form\Tests\FormInterface');
- $event = new FilterDataEvent($form, $data);
+ $event = new FormEvent($form, $data);
$filter = new FixUrlProtocolListener('http');
- $filter->onBindNormData($event);
+ $filter->onBind($event);
$this->assertEquals('ftp://www.symfony.com', $event->getData());
}
View
38 Tests/Extension/Core/EventListener/MergeCollectionListenerTest.php
@@ -11,7 +11,7 @@
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\FormBuilder;
@@ -85,8 +85,8 @@ public function testAddExtraEntriesIfAllowAdd($allowDelete)
$this->form->setData($originalData);
- $event = new FilterDataEvent($this->form, $newData);
- $listener->onBindNormData($event);
+ $event = new FormEvent($this->form, $newData);
+ $listener->onBind($event);
// The original object was modified
if (is_object($originalData)) {
@@ -109,8 +109,8 @@ public function testAddExtraEntriesIfAllowAddDontOverwriteExistingIndices($allow
$this->form->setData($originalData);
- $event = new FilterDataEvent($this->form, $newData);
- $listener->onBindNormData($event);
+ $event = new FormEvent($this->form, $newData);
+ $listener->onBind($event);
// The original object was modified
if (is_object($originalData)) {
@@ -134,8 +134,8 @@ public function testDoNothingIfNotAllowAdd($allowDelete)
$this->form->setData($originalData);
- $event = new FilterDataEvent($this->form, $newData);
- $listener->onBindNormData($event);
+ $event = new FormEvent($this->form, $newData);
+ $listener->onBind($event);
// We still have the original object
if (is_object($originalData)) {
@@ -158,8 +158,8 @@ public function testRemoveMissingEntriesIfAllowDelete($allowAdd)
$this->form->setData($originalData);
- $event = new FilterDataEvent($this->form, $newData);
- $listener->onBindNormData($event);
+ $event = new FormEvent($this->form, $newData);
+ $listener->onBind($event);
// The original object was modified
if (is_object($originalData)) {
@@ -183,8 +183,8 @@ public function testDoNothingIfNotAllowDelete($allowAdd)
$this->form->setData($originalData);
- $event = new FilterDataEvent($this->form, $newData);
- $listener->onBindNormData($event);
+ $event = new FormEvent($this->form, $newData);
+ $listener->onBind($event);
// We still have the original object
if (is_object($originalData)) {
@@ -202,9 +202,9 @@ public function testDoNothingIfNotAllowDelete($allowAdd)
public function testRequireArrayOrTraversable($allowAdd, $allowDelete)
{
$newData = 'no array or traversable';
- $event = new FilterDataEvent($this->form, $newData);
+ $event = new FormEvent($this->form, $newData);
$listener = new MergeCollectionListener($allowAdd, $allowDelete);
- $listener->onBindNormData($event);
+ $listener->onBind($event);
}
public function testDealWithNullData()
@@ -216,8 +216,8 @@ public function testDealWithNullData()
$this->form->setData($originalData);
- $event = new FilterDataEvent($this->form, $newData);
- $listener->onBindNormData($event);
+ $event = new FormEvent($this->form, $newData);
+ $listener->onBind($event);
$this->assertSame($originalData, $event->getData());
}
@@ -234,8 +234,8 @@ public function testDealWithNullOriginalDataIfAllowAdd($allowDelete)
$this->form->setData($originalData);
- $event = new FilterDataEvent($this->form, $newData);
- $listener->onBindNormData($event);
+ $event = new FormEvent($this->form, $newData);
+ $listener->onBind($event);
$this->assertSame($newData, $event->getData());
}
@@ -252,8 +252,8 @@ public function testDontDealWithNullOriginalDataIfNotAllowAdd($allowDelete)
$this->form->setData($originalData);
- $event = new FilterDataEvent($this->form, $newData);
- $listener->onBindNormData($event);
+ $event = new FormEvent($this->form, $newData);
+ $listener->onBind($event);
$this->assertNull($event->getData());
}
View
39 Tests/Extension/Core/EventListener/ResizeFormListenerTest.php
@@ -11,8 +11,7 @@
namespace Symfony\Component\Form\Tests\Extension\Core\EventListener;
-use Symfony\Component\Form\Event\DataEvent;
-use Symfony\Component\Form\Event\FilterDataEvent;
+use Symfony\Component\Form\FormEvent;
use Symfony\Component\Form\Extension\Core\EventListener\ResizeFormListener;
use Symfony\Component\Form\FormBuilder;
@@ -70,7 +69,7 @@ public function testPreSetDataResizesForm()
->will($this->returnValue($this->getForm('2')));
$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->preSetData($event);
@@ -85,7 +84,7 @@ public function testPreSetDataResizesForm()
public function testPreSetDataRequiresArrayOrTraversable()
{
$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->preSetData($event);
}
@@ -95,7 +94,7 @@ public function testPreSetDataDealsWithNullData()
$this->factory->expects($this->never())->method('createNamed');
$data = null;
- $event = new DataEvent($this->form, $data);
+ $event = new FormEvent($this->form, $data);
$listener = new ResizeFormListener($this->factory, 'text', array(), false, false);
$listener->preSetData($event);
}
@@ -110,7 +109,7 @@ public function testPreBindResizesUpIfAllowAdd()
->will($this->returnValue($this->getForm('1')));
$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->preBind($event);
@@ -124,7 +123,7 @@ public function testPreBindResizesDownIfAllowDelete()
$this->form->add($this->getForm('1'));
$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->preBind($event);
@@ -138,7 +137,7 @@ public function testPreBindRemovesZeroKeys()
$this->form->add($this->getForm('0'));
$data = array();
- $event = new DataEvent($this->form, $data);
+ $event = new FormEvent($this->form, $data);
$listener = new ResizeFormListener($this->factory, 'text', array(), false, true);
$listener->preBind($event);
@@ -151,7 +150,7 @@ public function testPreBindDoesNothingIfNotAllowAddNorAllowDelete()
$this->form->add($this->getForm('1'));
$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->preBind($event);
@@ -166,7 +165,7 @@ public function testPreBindDoesNothingIfNotAllowAddNorAllowDelete()
public function testPreBindRequiresArrayOrTraversable()
{
$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->preBind($event);
}
@@ -176,7 +175,7 @@ public function testPreBindDealsWithNullData()
$this->form->add($this->getForm('1'));
$data = null;
- $event = new DataEvent($this->form, $data);
+ $event = new FormEvent($this->form, $data);
$listener = new ResizeFormListener($this->factory, 'text', array(), false, true);
$listener->preBind($event);
@@ -189,7 +188,7 @@ public function testPreBindDealsWithEmptyData()
$this->form->add($this->getForm('1'));
$data = '';
- $event = new DataEvent($this->form, $data);
+ $event = new FormEvent($this->form, $data);
$listener = new ResizeFormListener($this->factory, 'text', array(), false, true);
$listener->preBind($event);
@@ -201,9 +200,9 @@ public function testOnBindNormDataRemovesEntriesMissingInTheFormIfAllowDelete()
$this->form->add($this->getForm('1'));
$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->onBindNormData($event);
+ $listener->onBind($event);
$this->assertEquals(array(1 => 'second'), $event->getData());
}
@@ -213,9 +212,9 @@ public function testOnBindNormDataDoesNothingIfNotAllowDelete()
$this->form->add($this->getForm('1'));
$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->onBindNormData($event);
+ $listener->onBind($event);
$this->assertEquals($data, $event->getData());
}
@@ -226,19 +225,19 @@ public function testOnBindNormDataDoesNothingIfNotAllowDelete()
public function testOnBindNormDataRequiresArrayOrTraversable()
{
$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->onBindNormData($event);
+ $listener->onBind($event);
}
public function testOnBindNormDataDealsWithNullData()
{
$this->form->add($this->getForm('1'));
$data = null;
- $event = new FilterDataEvent($this->form, $data);
+ $event = new FormEvent($this->form, $data);
$listener = new ResizeFormListener($this->factory, 'text', array(), false, true);
- $listener->onBindNormData($event);
+ $listener->onBind($event);
$this->assertEquals(array(), $event->getData());
}
View
10 Tests/Extension/Core/EventListener/TrimListenerTest.php
@@ -11,7 +11,7 @@
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;
class TrimListenerTest extends \PHPUnit_Framework_TestCase
@@ -27,10 +27,10 @@ public function testTrim()
{
$data = " Foo! ";
$form = $this->getMock('Symfony\Component\Form\Tests\FormInterface');
- $event = new FilterDataEvent($form, $data);
+ $event = new FormEvent($form, $data);
$filter = new TrimListener();
- $filter->onBindClientData($event);
+ $filter->preBind($event);
$this->assertEquals('Foo!', $event->getData());
}
@@ -39,10 +39,10 @@ public function testTrimSkipNonStrings()
{
$data = 1234;
$form = $this->getMock('Symfony\Component\Form\Tests\FormInterface');
- $event = new FilterDataEvent($form, $data);
+ $event = new FormEvent($form, $data);
$filter = new TrimListener();
- $filter->onBindClientData($event);
+ $filter->preBind($event);
$this->assertSame(1234, $event->getData());
}
View
10 Tests/Extension/Core/Type/CheckboxTypeTest.php
@@ -58,7 +58,7 @@ public function testBindWithValueChecked()
$form->bind('foobar');
$this->assertTrue($form->getData());
- $this->assertEquals('foobar', $form->getClientData());
+ $this->assertEquals('foobar', $form->getViewData());
}
public function testBindWithRandomValueChecked()
@@ -69,7 +69,7 @@ public function testBindWithRandomValueChecked()
$form->bind('krixikraxi');
$this->assertTrue($form->getData());
- $this->assertEquals('foobar', $form->getClientData());
+ $this->assertEquals('foobar', $form->getViewData());
}
public function testBindWithValueUnchecked()
@@ -80,7 +80,7 @@ public function testBindWithValueUnchecked()
$form->bind(null);
$this->assertFalse($form->getData());
- $this->assertNull($form->getClientData());
+ $this->assertNull($form->getViewData());
}
public function testBindWithEmptyValueChecked()
@@ -91,7 +91,7 @@ public function testBindWithEmptyValueChecked()
$form->bind('');
$this->assertTrue($form->getData());
- $this->assertSame('', $form->getClientData());
+ $this->assertSame('', $form->getViewData());
}
public function testBindWithEmptyValueUnchecked()
@@ -102,7 +102,7 @@ public function testBindWithEmptyValueUnchecked()
$form->bind(null);
$this->assertFalse($form->getData());
- $this->assertNull($form->getClientData());
+ $this->assertNull($form->getViewData());
}
/**
View
102 Tests/Extension/Core/Type/ChoiceTypeTest.php
@@ -180,7 +180,7 @@ public function testBindSingleNonExpanded()
$form->bind('b');
$this->assertEquals('b', $form->getData());
- $this->assertEquals('b', $form->getClientData());
+ $this->assertEquals('b', $form->getViewData());
}
public function testBindSingleNonExpandedObjectChoices()
@@ -203,7 +203,7 @@ public function testBindSingleNonExpandedObjectChoices()
$form->bind('2');
$this->assertEquals($this->objectChoices[1], $form->getData());
- $this->assertEquals('2', $form->getClientData());
+ $this->assertEquals('2', $form->getViewData());
}
public function testBindMultipleNonExpanded()
@@ -217,7 +217,7 @@ public function testBindMultipleNonExpanded()
$form->bind(array('a', 'b'));
$this->assertEquals(array('a', 'b'), $form->getData());
- $this->assertEquals(array('a', 'b'), $form->getClientData());
+ $this->assertEquals(array('a', 'b'), $form->getViewData());
}
public function testBindMultipleNonExpandedObjectChoices()
@@ -239,7 +239,7 @@ public function testBindMultipleNonExpandedObjectChoices()
$form->bind(array('2', '3'));
$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()
@@ -258,11 +258,11 @@ public function testBindSingleExpanded()
$this->assertFalse($form[2]->getData());
$this->assertFalse($form[3]->getData());
$this->assertFalse($form[4]->getData());
- $this->assertNull($form[0]->getClientData());
- $this->assertSame('b', $form[1]->getClientData());
- $this->assertNull($form[2]->getClientData());
- $this->assertNull($form[3]->getClientData());
- $this->assertNull($form[4]->getClientData());
+ $this->assertNull($form[0]->getViewData());
+ $this->assertSame('b', $form[1]->getViewData());
+ $this->assertNull($form[2]->getViewData());
+ $this->assertNull($form[3]->getViewData());
+ $this->assertNull($form[4]->getViewData());
}
public function testBindSingleExpandedNothingChecked()
@@ -281,11 +281,11 @@ public function testBindSingleExpandedNothingChecked()
$this->assertFalse($form[2]->getData());
$this->assertFalse($form[3]->getData());
$this->assertFalse($form[4]->getData());
- $this->assertNull($form[0]->getClientData());
- $this->assertNull($form[1]->getClientData());
- $this->assertNull($form[2]->getClientData());
- $this->assertNull($form[3]->getClientData());
- $this->assertNull($form[4]->getClientData());
+ $this->assertNull($form[0]->getViewData());
+ $this->assertNull($form[1]->getViewData());
+ $this->assertNull($form[2]->getViewData());
+ $this->assertNull($form[3]->getViewData());
+ $this->assertNull($form[4]->getViewData());
}
public function testBindSingleExpandedWithFalseDoesNotHaveExtraChildren()
@@ -318,8 +318,8 @@ public function testBindSingleExpandedWithEmptyChild()
$this->assertNull($form->getData());
$this->assertTrue($form[0]->getData());
$this->assertFalse($form[1]->getData());
- $this->assertSame('', $form[0]->getClientData());
- $this->assertNull($form[1]->getClientData());
+ $this->assertSame('', $form[0]->getViewData());
+ $this->assertNull($form[1]->getViewData());
}
public function testBindSingleExpandedObjectChoices()
@@ -346,11 +346,11 @@ public function testBindSingleExpandedObjectChoices()
$this->assertFalse($form[2]->getData());
$this->assertFalse($form[3]->getData());
$this->assertFalse($form[4]->getData());
- $this->assertNull($form[0]->getClientData());
- $this->assertSame('2', $form[1]->getClientData());
- $this->assertNull($form[2]->getClientData());
- $this->assertNull($form[3]->getClientData());
- $this->assertNull($form[4]->getClientData());
+ $this->assertNull($form[0]->getViewData());
+ $this->assertSame('2', $form[1]->getViewData());
+ $this->assertNull($form[2]->getViewData());
+ $this->assertNull($form[3]->getViewData());
+ $this->assertNull($form[4]->getViewData());
}
public function testBindSingleExpandedNumericChoices()
@@ -369,11 +369,11 @@ public function testBindSingleExpandedNumericChoices()
$this->assertFalse($form[2]->getData());
$this->assertFalse($form[3]->getData());
$this->assertFalse($form[4]->getData());
- $this->assertNull($form[0]->getClientData());
- $this->assertSame('1', $form[1]->getClientData());
- $this->assertNull($form[2]->getClientData());
- $this->assertNull($form[3]->getClientData());
- $this->assertNull($form[4]->getClientData());
+ $this->assertNull($form[0]->getViewData());
+ $this->assertSame('1', $form[1]->getViewData());
+ $this->assertNull($form[2]->getViewData());
+ $this->assertNull($form[3]->getViewData());
+ $this->assertNull($form[4]->getViewData());
}
public function testBindMultipleExpanded()
@@ -392,11 +392,11 @@ public function testBindMultipleExpanded()
$this->assertTrue($form[2]->getData());
$this->assertFalse($form[3]->getData());
$this->assertFalse($form[4]->getData());
- $this->assertSame('a', $form[0]->getClientData());
- $this->assertNull($form[1]->getClientData());
- $this->assertSame('c', $form[2]->getClientData());
- $this->assertNull($form[3]->getClientData());
- $this->assertNull($form[4]->getClientData());
+ $this->assertSame('a', $form[0]->getViewData());
+ $this->assertNull($form[1]->getViewData());
+ $this->assertSame('c', $form[2]->getViewData());
+ $this->assertNull($form[3]->getViewData());
+ $this->assertNull($form[4]->getViewData());
}
public function testBindMultipleExpandedEmpty()
@@ -415,11 +415,11 @@ public function testBindMultipleExpandedEmpty()
$this->assertFalse($form[2]->getData());
$this->assertFalse($form[3]->getData());
$this->assertFalse($form[4]->getData());
- $this->assertNull($form[0]->getClientData());
- $this->assertNull($form[1]->getClientData());
- $this->assertNull($form[2]->getClientData());
- $this->assertNull($form[3]->getClientData());
- $this->assertNull($form[4]->getClientData());
+ $this->assertNull($form[0]->getViewData());
+ $this->assertNull($form[1]->getViewData());
+ $this->assertNull($form[2]->getViewData());
+ $this->assertNull($form[3]->getViewData());
+ $this->assertNull($form[4]->getViewData());
}
public function testBindMultipleExpandedWithEmptyChild()
@@ -440,9 +440,9 @@ public function testBindMultipleExpandedWithEmptyChild()
$this->assertTrue($form[0]->getData());
$this->assertFalse($form[1]->getData());
$this->assertTrue($form[2]->getData());
- $this->assertSame('', $form[0]->getClientData());
- $this->assertNull($form[1]->getClientData());
- $this->assertSame('2', $form[2]->getClientData());
+ $this->assertSame('', $form[0]->getViewData());
+ $this->assertNull($form[1]->getViewData());
+ $this->assertSame('2', $form[2]->getViewData());
}
public function testBindMultipleExpandedObjectChoices()
@@ -469,11 +469,11 @@ public function testBindMultipleExpandedObjectChoices()
$this->assertFalse($form[2]->getData());
$this->assertFalse($form[3]->getData());
$this->assertFalse($form[4]->getData());
- $this->assertSame('1', $form[0]->getClientData());
- $this->assertSame('2', $form[1]->getClientData());
- $this->assertNull($form[2]->getClientData());
- $this->assertNull($form[3]->getClientData());
- $this->assertNull($form[4]->getClientData());
+ $this->assertSame('1', $form[0]->getViewData());
+ $this->assertSame('2', $form[1]->getViewData());
+ $this->assertNull($form[2]->getViewData());
+ $this->assertNull($form[3]->getViewData());
+ $this->assertNull($form[4]->getViewData());
}
public function testBindMultipleExpandedNumericChoices()
@@ -492,11 +492,11 @@ public function testBindMultipleExpandedNumericChoices()
$this->assertTrue($form[2]->getData());
$this->assertFalse($form[3]->getData());
$this->assertFalse($form[4]->getData());
- $this->assertNull($form[0]->getClientData());
- $this->assertSame('1', $form[1]->getClientData());
- $this->assertSame('2', $form[2]->getClientData());
- $this->assertNull($form[3]->getClientData());
- $this->assertNull($form[4]->getClientData());
+ $this->assertNull($form[0]->getViewData());
+ $this->assertSame('1', $form[1]->getViewData());
+ $this->assertSame('2', $form[2]->getViewData());
+ $this->assertNull($form[3]->getViewData());
+ $this->assertNull($form[4]->getViewData());
}
/*
@@ -514,7 +514,7 @@ public function testSetDataSingleNonExpandedAcceptsBoolean()
$form->setData(false);
$this->assertFalse($form->getData());
- $this->assertEquals('0', $form->getClientData());
+ $this->assertEquals('0', $form->getViewData());
}
public function testSetDataMultipleNonExpandedAcceptsBoolean()
@@ -528,7 +528,7 @@ public function testSetDataMultipleNonExpandedAcceptsBoolean()
$form->setData(array(false, true));
$this->assertEquals(array(false, true), $form->getData());
- $this->assertEquals(array('0', '1'), $form->getClientData());
+ $this->assertEquals(array('0', '1'), $form->getViewData());
}
public function testPassRequiredToView()
View
6 Tests/Extension/Core/Type/DateTimeTypeTest.php
@@ -173,7 +173,7 @@ public function testSubmit_differentTimezonesDateTime()
$outputTime->setTimezone(new \DateTimeZone('America/New_York'));
$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()
@@ -188,7 +188,7 @@ public function testSubmit_stringSingleText()
$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', $form->getClientData());
+ $this->assertEquals('2010-06-02 03:04', $form->getViewData());
}
public function testSubmit_stringSingleText_withSeconds()
@@ -204,7 +204,7 @@ public function testSubmit_stringSingleText_withSeconds()
$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->getClientData());
+ $this->assertEquals('2010-06-02 03:04:05', $form->getViewData());
}
public function testSubmit_differentPattern()
View
28 Tests/Extension/Core/Type/DateTypeTest.php
@@ -54,7 +54,7 @@ public function testSubmitFromSingleTextDateTime()
$form->bind('2.6.2010');
$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()
@@ -69,7 +69,7 @@ public function testSubmitFromSingleTextString()
$form->bind('2.6.2010');
$this->assertEquals('2010-06-02', $form->getData());
- $this->assertEquals('02.06.2010', $form->getClientData());
+ $this->assertEquals('02.06.2010', $form->getViewData());
}
public function testSubmitFromSingleTextTimestamp()
@@ -86,7 +86,7 @@ public function testSubmitFromSingleTextTimestamp()
$dateTime = new \DateTime('2010-06-02 UTC');
$this->assertEquals($dateTime->format('U'), $form->getData());
- $this->assertEquals('02.06.2010', $form->getClientData());
+ $this->assertEquals('02.06.2010', $form->getViewData());
}
public function testSubmitFromSingleTextRaw()
@@ -107,7 +107,7 @@ public function testSubmitFromSingleTextRaw()
);
$this->assertEquals($output, $form->getData());
- $this->assertEquals('02.06.2010', $form->getClientData());
+ $this->assertEquals('02.06.2010', $form->getViewData());
}
public function testSubmitFromText()
@@ -129,7 +129,7 @@ public function testSubmitFromText()
$dateTime = new \DateTime('2010-06-02 UTC');
$this->assertDateTimeEquals($dateTime, $form->getData());
- $this->assertEquals($text, $form->getClientData());
+ $this->assertEquals($text, $form->getViewData());
}
public function testSubmitFromChoice()
@@ -151,7 +151,7 @@ public function testSubmitFromChoice()
$dateTime = new \DateTime('2010-06-02 UTC');
$this->assertDateTimeEquals($dateTime, $form->getData());
- $this->assertEquals($text, $form->getClientData());
+ $this->assertEquals($text, $form->getViewData());
}
public function testSubmitFromChoiceEmpty()
@@ -172,7 +172,7 @@ public function testSubmitFromChoiceEmpty()
$form->bind($text);
$this->assertNull($form->getData());
- $this->assertEquals($text, $form->getClientData());
+ $this->assertEquals($text, $form->getViewData());
}
public function testSubmitFromInputDateTimeDifferentPattern()
@@ -188,7 +188,7 @@ public function testSubmitFromInputDateTimeDifferentPattern()
$form->bind('06*2010*02');
$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()
@@ -204,7 +204,7 @@ public function testSubmitFromInputStringDifferentPattern()
$form->bind('06*2010*02');
$this->assertEquals('2010-06-02', $form->getData());
- $this->assertEquals('06*2010*02', $form->getClientData());
+ $this->assertEquals('06*2010*02', $form->getViewData());
}
public function testSubmitFromInputTimestampDifferentPattern()
@@ -222,7 +222,7 @@ public function testSubmitFromInputTimestampDifferentPattern()
$dateTime = new \DateTime('2010-06-02 UTC');
$this->assertEquals($dateTime->format('U'), $form->getData());
- $this->assertEquals('06*2010*02', $form->getClientData());
+ $this->assertEquals('06*2010*02', $form->getViewData());
}
public function testSubmitFromInputRawDifferentPattern()
@@ -244,7 +244,7 @@ public function testSubmitFromInputRawDifferentPattern()
);
$this->assertEquals($output, $form->getData());
- $this->assertEquals('06*2010*02', $form->getClientData());
+ $this->assertEquals('06*2010*02', $form->getViewData());
}
/**
@@ -262,7 +262,7 @@ public function testFormatOptionCustomPatternCollapsingIntlDateFormatterConstant
$form->setData('2010-06-02');
// 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 @@ public function testSetData_differentTimezones()
$form->setData('2010-06-02');
- $this->assertEquals('01.06.2010', $form->getClientData());
+ $this->assertEquals('01.06.2010', $form->getViewData());
}
public function testSetData_differentTimezonesDateTime()
@@ -313,7 +313,7 @@ public function testSetData_differentTimezonesDateTime()
$form->setData($dateTime);
$this->assertDateTimeEquals($dateTime, $form->getData());
- $this->assertEquals('01.06.2010', $form->getClientData());
+ $this->assertEquals('01.06.2010', $form->getViewData());
}
public function testYearsOption()
View
4 Tests/Extension/Core/Type/FormTypeTest.php
@@ -81,7 +81,7 @@ public function testBoundDataIsTrimmedBeforeTransforming()
$form->bind(' a ');
- $this->assertEquals('a', $form->getClientData());
+ $this->assertEquals('a', $form->getViewData());
$this->assertEquals('reverse[a]', $form->getData());
}
@@ -96,7 +96,7 @@ public function testBoundDataIsNotTrimmedBeforeTransformingIfNoTrimming()
$form->bind(' a ');
- $this->assertEquals(' a ', $form->getClientData());
+ $this->assertEquals(' a ', $form->getViewData());
$this->assertEquals('reverse[ a ]', $form->getData());
}
View
2 Tests/Extension/Core/Type/IntegerTypeTest.php
@@ -20,6 +20,6 @@ public function testSubmitCastsToInteger()
$form->bind('1.678');
$this->assertSame(1, $form->getData());
- $this->assertSame('1', $form->getClientData());
+ $this->assertSame('1', $form->getViewData());
}
}
View
12 Tests/Extension/Core/Type/RepeatedTypeTest.php
@@ -93,10 +93,10 @@ public function testSubmitUnequal()
$this->form->bind($input);
- $this->assertEquals('foo', $this->form['first']->getClientData());
- $this->assertEquals('bar', $this->form['second']->getClientData());
+ $this->assertEquals('foo', $this->form['first']->getViewData());
+ $this->assertEquals('bar', $this->form['second']->getViewData());
$this->assertFalse($this->form->isSynchronized());
- $this->assertEquals($input, $this->form->getClientData());
+ $this->assertEquals($input, $this->form->getViewData());
$this->assertNull($this->form->getData());
}
@@ -106,10 +106,10 @@ public function testSubmitEqual()
$this->form->bind($input);
- $this->assertEquals('foo', $this->form['first']->getClientData());
- $this->assertEquals('foo', $this->form['second']->getClientData());
+ $this->assertEquals('foo', $this->form['first']->getViewData());
+ $this->assertEquals('foo', $this->form['second']->getViewData());
$this->assertTrue($this->form->isSynchronized());
- $this->assertEquals($input, $this->form->getClientData());
+ $this->assertEquals($input, $this->form->getViewData());
$this->assertEquals('foo', $this->form->getData());
}
}
View
22 Tests/Extension/Core/Type/TimeTypeTest.php
@@ -33,7 +33,7 @@ public function testSubmit_dateTime()
$dateTime = new \DateTime('1970-01-01 03:04:00 UTC');
$this->assertEquals($dateTime, $form->getData());
- $this->assertEquals($input, $form->getClientData());
+ $this->assertEquals($input, $form->getViewData());
}
public function testSubmit_string()
@@ -52,7 +52,7 @@ public function testSubmit_string()
$form->bind($input);
$this->assertEquals('03:04:00', $form->getData());
- $this->assertEquals($input, $form->getClientData());
+ $this->assertEquals($input, $form->getViewData());
}
public function testSubmit_timestamp()
@@ -73,7 +73,7 @@ public function testSubmit_timestamp()
$dateTime = new \DateTime('1970-01-01 03:04:00 UTC');
$this->assertEquals($dateTime->format('U'), $form->getData());
- $this->assertEquals($input, $form->getClientData());
+ $this->assertEquals($input, $form->getViewData());
}
public function testSubmit_array()
@@ -92,7 +92,7 @@ public function testSubmit_array()
$form->bind($input);
$this->assertEquals($input, $form->getData());
- $this->assertEquals($input, $form->getClientData());
+ $this->assertEquals($input, $form->getViewData());
}
public function testSubmit_datetimeSingleText()
@@ -107,7 +107,7 @@ public function testSubmit_datetimeSingleText()
$form->bind('03:04:05');
$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()
@@ -127,7 +127,7 @@ public function testSubmit_arraySingleText()
$form->bind('03:04');
$this->assertEquals($data, $form->getData());
- $this->assertEquals('03:04', $form->getClientData());
+ $this->assertEquals('03:04', $form->getViewData());
}
public function testSubmit_arraySingleTextWithSeconds()
@@ -149,7 +149,7 @@ public function testSubmit_arraySingleTextWithSeconds()
$form->bind('03:04:05');
$this->assertEquals($data, $form->getData());
- $this->assertEquals('03:04:05', $form->getClientData());
+ $this->assertEquals('03:04:05', $form->getViewData());
}
public function testSubmit_stringSingleText()
@@ -164,7 +164,7 @@ public function testSubmit_stringSingleText()
$form->bind('03:04:05');
$this->assertEquals('03:04:00', $form->getData());
- $this->assertEquals('03:04', $form->getClientData());
+ $this->assertEquals('03:04', $form->getViewData());
}
public function testSetData_withSeconds()
@@ -178,7 +178,7 @@ public function testSetData_withSeconds()
$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()
@@ -204,7 +204,7 @@ public function testSetData_differentTimezones()
'second' => (int)$outputTime->format('s')
);
- $this->assertEquals($displayedData, $form->getClientData());
+ $this->assertEquals($displayedData, $form->getViewData());
}
public function testSetData_differentTimezonesDateTime()
@@ -231,7 +231,7 @@ public function testSetData_differentTimezonesDateTime()
);
$this->assertDateTimeEquals($dateTime, $form->getData());
- $this->assertEquals($displayedData, $form->getClientData());
+ $this->assertEquals($displayedData, $form->getViewData());
}
public function testHoursOption()
View
8 Tests/Extension/Core/Type/UrlTypeTest.php
@@ -20,7 +20,7 @@ public function testSubmitAddsDefaultProtocolIfNoneIsIncluded()
$form->bind('www.domain.com');
$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()
@@ -32,7 +32,7 @@ public function testSubmitAddsNoDefaultProtocolIfAlreadyIncluded()
$form->bind('ftp://www.domain.com');
$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()
@@ -44,7 +44,7 @@ public function testSubmitAddsNoDefaultProtocolIfEmpty()
$form->bind('');
$this->assertSame('', $form->getData());
- $this->assertSame('', $form->getClientData());
+ $this->assertSame('', $form->getViewData());
}
public function testSubmitAddsNoDefaultProtocolIfSetToNull()
@@ -56,6 +56,6 @@ public function testSubmitAddsNoDefaultProtocolIfSetToNull()
$form->bind('www.domain.com');
$this->assertSame('www.domain.com', $form->getData());
- $this->assertSame('www.domain.com', $form->getClientData());
+ $this->assertSame('www.domain.com', $form->getViewData());
}
}
View
32 Tests/Fixtures/FixedFilterListener.php
@@ -12,7 +12,7 @@
namespace Symfony\Component\Form\Tests\Fixtures;
use Symfony\Component\Form\FormEvents;
-use Symfony\Component\Form\Event\FilterDataEvent;
+use Symfony\Component\Form\FormEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class FixedFilterListener implements EventSubscriberInterface
@@ -22,45 +22,45 @@ class FixedFilterListener implements EventSubscriberInterface
public function __construct(array $mapping)
{
$this->mapping = array_merge(array(
- 'onBindClientData' => array(),
- 'onBindNormData' => array(),
- 'onSetData' => array(),
+ 'preBind' => array(),
+ 'onBind' => array(),
+ 'preSetData' => array(),
), $mapping);
}
- public function onBindClientData(FilterDataEvent $event)
+ public function preBind(FormEvent $event)
{
$data = $event->getData();
- if (isset($this->mapping['onBindClientData'][$data])) {
- $event->setData($this->mapping['onBindClientData'][$data]);
+ if (isset($this->mapping['preBind'][$data])) {
+ $event->setData($this->mapping['preBind'][$data]);
}
}
- public function onBindNormData(FilterDataEvent $event)
+ public function onBind(FormEvent $event)
{
$data = $event->getData();
- if (isset($this->mapping['onBindNormData'][$data])) {
- $event->setData($this->mapping['onBindNormData'][$data]);
+ if (isset($this->mapping['onBind'][$data])) {
+ $event->setData($this->mapping['onBind'][$data]);
}
}
- public function onSetData(FilterDataEvent $event)
+ public function preSetData(FormEvent $event)
{
$data = $event->getData();
- if (isset($this->mapping['onSetData'][$data])) {
- $event->setData($this->mapping['onSetData'][$data]);
+ if (isset($this->mapping['preSetData'][$data])) {
+ $event->setData($this->mapping['preSetData'][$data]);
}
}
public static function getSubscribedEvents()
{
return array(
- FormEvents::BIND_CLIENT_DATA => 'onBindClientData',
- FormEvents::BIND_NORM_DATA => 'onBindNormData',
- FormEvents::SET_DATA => 'onSetData',
+ FormEvents::PRE_BIND => 'preBind',
+ FormEvents::BIND => 'onBind',
+ FormEvents::PRE_SET_DATA => 'preSetData',
);
}
}
View
54 Tests/FormTest.php
@@ -55,16 +55,16 @@ protected function tearDown()
public function testDataIsInitializedEmpty()
{
- $norm = new FixedDataTransformer(array(
+ $model = new FixedDataTransformer(array(
'' => 'foo',
));
- $client = new FixedDataTransformer(array(
+ $view = new FixedDataTransformer(array(
'foo' => 'bar',
));
$config = new FormConfig('name', null, $this->dispatcher);
- $config->addViewTransformer($client);
- $config->appendNormTransformer($norm);
+ $config->addViewTransformer($view);
+ $config->addModelTransformer($model);
$form = new Form($config);
$this->assertNull($form->getData());
@@ -488,11 +488,11 @@ public function testSetDataExecutesTransformationChain()
// use real event dispatcher now
$form = $this->getBuilder('name', new EventDispatcher())
->addEventSubscriber(new FixedFilterListener(array(
- 'onSetData' => array(
+ 'preSetData' => array(
'app' => 'filtered',
),
)))
- ->appendNormTransformer(new FixedDataTransformer(array(
+ ->addModelTransformer(new FixedDataTransformer(array(
'' => '',
'filtered' => 'norm',
)))
@@ -506,10 +506,10 @@ public function testSetDataExecutesTransformationChain()
$this->assertEquals('filtered', $form->getData());
$this->assertEquals('norm', $form->getNormData());
- $this->assertEquals('client', $form->getClientData());
+ $this->assertEquals('client', $form->getViewData());
}
- public function testSetDataExecutesClientTransformersInOrder()
+ public function testSetDataExecutesViewTransformersInOrder()
{
$form = $this->getBuilder()
->addViewTransformer(new FixedDataTransformer(array(
@@ -524,19 +524,19 @@ public function testSetDataExecutesClientTransformersInOrder()
$form->setData('first');
- $this->assertEquals('third', $form->getClientData());
+ $this->assertEquals('third', $form->getViewData());
}
- public function testSetDataExecutesNormTransformersInOrder()
+ public function testSetDataExecutesModelTransformersInReverseOrder()
{
$form = $this->getBuilder()
- ->appendNormTransformer(new FixedDataTransformer(array(
+ ->addModelTransformer(new FixedDataTransformer(array(
'' => '',
- 'first' => 'second',
+ 'second' => 'third',
)))
- ->appendNormTransformer(new FixedDataTransformer(array(
+ ->addModelTransformer(new FixedDataTransformer(array(
'' => '',
- 'second' => 'third',
+ 'first' => 'second',
)))
->getForm();
@@ -564,10 +564,10 @@ public function testSetDataConvertsScalarToStringIfNoTransformer()
* Data in client format should, if possible, always be a string to
* facilitate differentiation between '0' and ''
*/
- public function testSetDataConvertsScalarToStringIfOnlyNormTransformer()
+ public function testSetDataConvertsScalarToStringIfOnlyModelTransformer()
{
$form = $this->getBuilder()
- ->appendNormTransformer(new FixedDataTransformer(array(
+ ->addModelTransformer(new FixedDataTransformer(array(
'' => '',
1 => 23,
)))
@@ -577,7 +577,7 @@ public function testSetDataConvertsScalarToStringIfOnlyNormTransformer()
$this->assertSame(1, $form->getData());
$this->assertSame(23, $form->getNormData());
- $this->assertSame('23', $form->getClientData());
+ $this->assertSame('23', $form->getViewData());
}
/*
@@ -611,10 +611,10 @@ public function testBindExecutesTransformationChain()
// use real event dispatcher now