$t->is($widgetSchema->getHelps(), array('a' => '1_a', 'b' => '1_b', 'c' => '2_c', 'd' => '2_d'), 'mergeForm() merges helps correctly'); $t->isa_ok($widgetSchema['c'], 'sfWidgetFormTextarea', 'mergeForm() overrides original form widget'); $t->isa_ok($validatorSchema['c'], 'sfValidatorPass', 'mergeForm() overrides original form validator'); $t->isa_ok($validatorSchema->getPreValidator(), 'sfValidatorPass', 'mergeForm() merges pre validator'); $t->isa_ok($validatorSchema->getPostValidator(), 'sfValidatorPass', 'mergeForm() merges post validator'); try { $f1->bind(array('a' => 'foo', 'b' => 'bar', 'd' => 'far_too_long_value')); $f1->mergeForm($f2); $t->fail('mergeForm() disallows merging already bound forms'); } catch (LogicException $e) { $t->pass('mergeForm() disallows merging already bound forms'); } $errorSchema = $f1->getErrorSchema(); $t->ok(array_key_exists('d', $errorSchema->getErrors()), 'mergeForm() merges errors after having been bound'); $f1 = new TestForm1(); $f1->getWidgetSchema()->moveField('a', 'last'); // is moved field well positioned when accessed with iterator interface? (#5551) foreach ($f1 as $f1name => $f1field) { $t->is($f1name, 'b', 'iterating on form takes in account ->moveField() operations.'); break; } $f2 = new TestForm2(); $f2->mergeForm($f1); $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()
class TestForm2 extends FormTest { public function configure() { $this->disableCSRFProtection(); $this->setWidgets(array('c' => new sfWidgetFormTextarea(), 'd' => new sfWidgetFormTextarea())); $this->setValidators(array('c' => new sfValidatorPass(), 'd' => new sfValidatorString(array('max_length' => 5)))); $this->getWidgetSchema()->setLabels(array('c' => '2_c', 'd' => '2_d')); $this->validatorSchema->setPreValidator(new sfValidatorPass()); $this->validatorSchema->setPostValidator(new sfValidatorPass()); } } $f1 = new TestForm1(); $f2 = new TestForm2(); $f1->mergeForm($f2); $widgetSchema = $f1->getWidgetSchema(); $validatorSchema = $f1->getValidatorSchema(); $t->is(count($widgetSchema->getFields()), 4, 'mergeForm() merges a widget form schema'); $t->is(count($validatorSchema->getFields()), 4, 'mergeForm() merges a validator schema'); $t->is(array_keys($widgetSchema->getFields()), array('a', 'b', 'c', 'd'), 'mergeForms() merges the correct widgets'); $t->is(array_keys($validatorSchema->getFields()), array('a', 'b', 'c', 'd'), 'mergeForms() merges the correct validators'); $t->is($widgetSchema->getLabels(), array('a' => '1_a', 'b' => '1_b', 'c' => '2_c', 'd' => '2_d'), 'mergeForm() merges labels correctly'); $t->isa_ok($widgetSchema['c'], 'sfWidgetFormTextarea', 'mergeForm() overrides original form widget'); $t->isa_ok($validatorSchema['c'], 'sfValidatorPass', 'mergeForm() overrides original form validator'); $t->isa_ok($validatorSchema->getPreValidator(), 'sfValidatorPass', 'mergeForm() merges pre validator'); $t->isa_ok($validatorSchema->getPostValidator(), 'sfValidatorPass', 'mergeForm() merges post validator'); try { $f1->bind(array('a' => 'foo', 'b' => 'bar', 'd' => 'far_too_long_value')); $f1->mergeForm($f2); $t->fail('mergeForm() disallows merging already bound forms'); } catch (LogicException $e) {