Skip to content

Commit 2ef155c

Browse files
committed
Merge pull request #105 from jeromemacias/fix_56
[RFP] Fix #56
2 parents 0ec99c7 + 9a2a9ee commit 2ef155c

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

lib/form/sfForm.class.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -610,6 +610,10 @@ public function setValidators(array $validators)
610610
*/
611611
public function setValidator($name, sfValidatorBase $validator)
612612
{
613+
if (isset($this->embeddedForms[$name])) {
614+
throw new LogicException('You cannot set a validator for an embedded form.');
615+
}
616+
613617
$this->validatorSchema[$name] = $validator;
614618

615619
$this->resetFormFields();
@@ -631,6 +635,10 @@ public function getValidator($name)
631635
throw new InvalidArgumentException(sprintf('The validator "%s" does not exist.', $name));
632636
}
633637

638+
if (isset($this->embeddedForms[$name])) {
639+
return $this->embeddedForms[$name]->getValidatorSchema();
640+
}
641+
634642
return $this->validatorSchema[$name];
635643
}
636644

test/unit/form/sfFormTest.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
require_once(__DIR__.'/../../bootstrap/unit.php');
1212

13-
$t = new lime_test(155);
13+
$t = new lime_test(157);
1414

1515
class FormTest extends sfForm
1616
{
@@ -652,6 +652,18 @@ public function configure()
652652
$t->is($w['author']->generateName('first_name'), 'article[author][first_name]', '->embedForm() changes the name format to reflect the embedding');
653653
$t->is($w['author']['company']->generateName('name'), 'article[author][company][name]', '->embedForm() changes the name format to reflect the embedding');
654654

655+
// tests for ticket #56
656+
$t->ok($author->getValidator('company') == $company_validator_schema, '->getValidator() gets a validator schema for an embedded form');
657+
try
658+
{
659+
$author->setValidator('company', new sfValidatorPass());
660+
$t->fail('"sfForm" Trying to set a validator for an embedded form field throws a LogicException');
661+
}
662+
catch (LogicException $e)
663+
{
664+
$t->pass('"sfForm" Trying to set a validator for an embedded form field throws a LogicException');
665+
}
666+
655667
// tests for ticket #4754
656668
$f1 = new TestForm1();
657669
$f2 = new TestForm2();

0 commit comments

Comments
 (0)