Author: Kris.Wallsmith
Date: 2010-04-06 15:59:11 +0200 (Tue, 06 Apr 2010)
New Revision: 28996
Modified:
branches/1.3/lib/form/sfForm.class.php
branches/1.3/test/unit/form/sfFormTest.php
branches/1.4/lib/form/sfForm.class.php
branches/1.4/test/unit/form/sfFormTest.php
Log:
[1.3, 1.4] fixed merge of numeric field defaults, labels and helps in mergeForm
Modified: branches/1.3/lib/form/sfForm.class.php
===================================================================
--- branches/1.3/lib/form/sfForm.class.php 2010-04-06 13:43:02 UTC (rev
28995)
+++ branches/1.3/lib/form/sfForm.class.php 2010-04-06 13:59:11 UTC (rev
28996)
@@ -494,7 +494,7 @@
$form = clone $form;
unset($form[self::$CSRFFieldName]);
- $this->defaults = array_merge($this->defaults, $form->getDefaults());
+ $this->defaults = $form->getDefaults() + $this->defaults;
foreach ($form->getWidgetSchema()->getPositions() as $field)
{
@@ -506,8 +506,8 @@
$this->validatorSchema[$field] = $validator;
}
-
$this->getWidgetSchema()->setLabels(array_merge($this->getWidgetSchema()->getLabels(),
$form->getWidgetSchema()->getLabels()));
-
$this->getWidgetSchema()->setHelps(array_merge($this->getWidgetSchema()->getHelps(),
$form->getWidgetSchema()->getHelps()));
+ $this->getWidgetSchema()->setLabels($form->getWidgetSchema()->getLabels()
+ $this->getWidgetSchema()->getLabels());
+ $this->getWidgetSchema()->setHelps($form->getWidgetSchema()->getHelps() +
$this->getWidgetSchema()->getHelps());
$this->mergePreValidator($form->getValidatorSchema()->getPreValidator());
$this->mergePostValidator($form->getValidatorSchema()->getPostValidator());
Modified: branches/1.3/test/unit/form/sfFormTest.php
===================================================================
--- branches/1.3/test/unit/form/sfFormTest.php 2010-04-06 13:43:02 UTC (rev
28995)
+++ branches/1.3/test/unit/form/sfFormTest.php 2010-04-06 13:59:11 UTC (rev
28996)
@@ -10,7 +10,7 @@
require_once(dirname(__FILE__).'/../../bootstrap/unit.php');
-$t = new lime_test(159);
+$t = new lime_test(162);
class FormTest extends sfForm
{
@@ -90,6 +90,23 @@
}
}
+class NumericFieldsForm extends sfForm
+{
+ public function configure()
+ {
+ $this->setWidgets(array(
+ '5' => new sfWidgetFormInputText(),
+ ));
+
+ $this->setValidators(array(
+ '5' => new sfValidatorString(),
+ ));
+
+ $this->widgetSchema->setLabels(array('5' =>
'label'.$this->getOption('salt')));
+ $this->widgetSchema->setHelps(array('5' =>
'help'.$this->getOption('salt')));
+ }
+}
+
sfForm::disableCSRFProtection();
// __construct()
@@ -911,6 +928,14 @@
$t->is_deeply(array_keys($f2->getWidgetSchema()->getFields()), array('c', 'd',
'b', 'a'), 'mergeForm() merges fields in the correct order');
+$f1 = new NumericFieldsForm(array('5' => 'default1'), array('salt' => '1'));
+$f2 = new NumericFieldsForm(array('5' => 'default2'), array('salt' => '2'));
+$f1->mergeForm($f2);
+
+$t->is_deeply($f1->getDefaults(), array('5' => 'default2'), '->mergeForm()
merges numeric defaults');
+$t->is_deeply($f1->getWidgetSchema()->getLabels(), array('5' => 'label2'),
'->mergeForm() merges numeric labels');
+$t->is_deeply($f1->getWidgetSchema()->getHelps(), array('5' => 'help2'),
'->mergeForm() merges numeric helps');
+
// ->getJavaScripts() ->getStylesheets()
$t->diag('->getJavaScripts() ->getStylesheets()');
@@ -948,20 +973,6 @@
// ->getFormFieldSchema()
$t->diag('->getFormFieldSchema()');
-class NumericFieldsForm extends sfForm
-{
- public function configure()
- {
- $this->setWidgets(array(
- '5' => new sfWidgetFormInputText(),
- ));
-
- $this->setValidators(array(
- '5' => new sfValidatorString(),
- ));
- }
-}
-
$f = new NumericFieldsForm(array('5' => 'default'));
$t->is_deeply($f->getFormFieldSchema()->getValue(), array('5' => 'default'),
'->getFormFieldSchema() includes default numeric fields');
$f->bind(array('5' => 'bound'));
Modified: branches/1.4/lib/form/sfForm.class.php
===================================================================
--- branches/1.4/lib/form/sfForm.class.php 2010-04-06 13:43:02 UTC (rev
28995)
+++ branches/1.4/lib/form/sfForm.class.php 2010-04-06 13:59:11 UTC (rev
28996)
@@ -494,7 +494,7 @@
$form = clone $form;
unset($form[self::$CSRFFieldName]);
- $this->defaults = array_merge($this->defaults, $form->getDefaults());
+ $this->defaults = $form->getDefaults() + $this->defaults;
foreach ($form->getWidgetSchema()->getPositions() as $field)
{
@@ -506,8 +506,8 @@
$this->validatorSchema[$field] = $validator;
}
-
$this->getWidgetSchema()->setLabels(array_merge($this->getWidgetSchema()->getLabels(),
$form->getWidgetSchema()->getLabels()));
-
$this->getWidgetSchema()->setHelps(array_merge($this->getWidgetSchema()->getHelps(),
$form->getWidgetSchema()->getHelps()));
+ $this->getWidgetSchema()->setLabels($form->getWidgetSchema()->getLabels()
+ $this->getWidgetSchema()->getLabels());
+ $this->getWidgetSchema()->setHelps($form->getWidgetSchema()->getHelps() +
$this->getWidgetSchema()->getHelps());
$this->mergePreValidator($form->getValidatorSchema()->getPreValidator());
$this->mergePostValidator($form->getValidatorSchema()->getPostValidator());
Modified: branches/1.4/test/unit/form/sfFormTest.php
===================================================================
--- branches/1.4/test/unit/form/sfFormTest.php 2010-04-06 13:43:02 UTC (rev
28995)
+++ branches/1.4/test/unit/form/sfFormTest.php 2010-04-06 13:59:11 UTC (rev
28996)
@@ -10,7 +10,7 @@
require_once(dirname(__FILE__).'/../../bootstrap/unit.php');
-$t = new lime_test(159);
+$t = new lime_test(162);
class FormTest extends sfForm
{
@@ -90,6 +90,23 @@
}
}
+class NumericFieldsForm extends sfForm
+{
+ public function configure()
+ {
+ $this->setWidgets(array(
+ '5' => new sfWidgetFormInputText(),
+ ));
+
+ $this->setValidators(array(
+ '5' => new sfValidatorString(),
+ ));
+
+ $this->widgetSchema->setLabels(array('5' =>
'label'.$this->getOption('salt')));
+ $this->widgetSchema->setHelps(array('5' =>
'help'.$this->getOption('salt')));
+ }
+}
+
sfForm::disableCSRFProtection();
// __construct()
@@ -911,6 +928,14 @@
$t->is_deeply(array_keys($f2->getWidgetSchema()->getFields()), array('c', 'd',
'b', 'a'), 'mergeForm() merges fields in the correct order');
+$f1 = new NumericFieldsForm(array('5' => 'default1'), array('salt' => '1'));
+$f2 = new NumericFieldsForm(array('5' => 'default2'), array('salt' => '2'));
+$f1->mergeForm($f2);
+
+$t->is_deeply($f1->getDefaults(), array('5' => 'default2'), '->mergeForm()
merges numeric defaults');
+$t->is_deeply($f1->getWidgetSchema()->getLabels(), array('5' => 'label2'),
'->mergeForm() merges numeric labels');
+$t->is_deeply($f1->getWidgetSchema()->getHelps(), array('5' => 'help2'),
'->mergeForm() merges numeric helps');
+
// ->getJavaScripts() ->getStylesheets()
$t->diag('->getJavaScripts() ->getStylesheets()');
@@ -948,20 +973,6 @@
// ->getFormFieldSchema()
$t->diag('->getFormFieldSchema()');
-class NumericFieldsForm extends sfForm
-{
- public function configure()
- {
- $this->setWidgets(array(
- '5' => new sfWidgetFormInputText(),
- ));
-
- $this->setValidators(array(
- '5' => new sfValidatorString(),
- ));
- }
-}
-
$f = new NumericFieldsForm(array('5' => 'default'));
$t->is_deeply($f->getFormFieldSchema()->getValue(), array('5' => 'default'),
'->getFormFieldSchema() includes default numeric fields');
$f->bind(array('5' => 'bound'));
--
You received this message because you are subscribed to the Google Groups
"symfony SVN" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/symfony-svn?hl=en.