} 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() $t->diag('->getJavaScripts() ->getStylesheets()'); class MyWidget extends sfWidgetForm { protected function configure($options = array(), $attributes = array()) { $this->addRequiredOption('name'); } public function render($name, $value = null, $attributes = array(), $errors = array()) {
public function getJavaScripts() { return array('/path/to/a/' . $this->getOption('name') . '.js'); } public function getStylesheets() { return array('/path/to/a/' . $this->getOption('name') . '.css' => 'all'); } } $f = new FormTest(); $f->setWidgets(array('foo' => new MyWidget(array('name' => 'foo')), 'bar' => new MyWidget(array('name' => 'bar')))); $t->is($f->getJavaScripts(), array('/path/to/a/foo.js', '/path/to/a/bar.js'), '->getJavaScripts() returns the stylesheets of all widgets'); $t->is($f->getStylesheets(), array('/path/to/a/foo.css' => 'all', '/path/to/a/bar.css' => 'all'), '->getStylesheets() returns the JavaScripts of all widgets'); // ->getFormFieldSchema() $t->diag('->getFormFieldSchema()'); $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')); $t->is_deeply($f->getFormFieldSchema()->getValue(), array('5' => 'bound'), '->getFormFieldSchema() includes bound numeric fields'); // ->getErrors() $t->diag('->getErrors()'); $f1 = new TestForm1(); $f21 = new TestForm1(); $f2 = new TestForm2(); $f2->embedForm('F21', $f21); $f1->embedForm('F2', $f2); $f1->bind(array()); $expected = array('1_a' => 'Required.', '1_b' => 'Required.', '1_c' => 'Required.', 'F2' => array('2_d' => 'Required.', 'F21' => array('1_a' => 'Required.', '1_b' => 'Required.', '1_c' => 'Required.'))); $t->is($f1->getErrors(), $expected, '->getErrors() return array of errors'); // bind with a simulated file upload in the POST array $f = new FormTest();