$w->setNameFormat('article[%s]'); for ($i = 0; $i < 2; $i++) { $t->ok($v['authors'][$i]['first_name'] == $author_validator_schema['first_name'], '->embedFormForEach() embeds the validator schema'); // ignore the parents in comparison $w['authors'][$i]['first_name']->setParent(null); $author_widget_schema['first_name']->setParent(null); $t->ok($w['authors'][$i]['first_name'] == $author_widget_schema['first_name'], '->embedFormForEach() embeds the widget schema'); $t->is($d['authors'][$i]['first_name'], 'Fabien', '->embedFormForEach() merges default values from the embedded forms'); $t->is($v['authors'][$i][sfForm::getCSRFFieldName()], null, '->embedFormForEach() removes the CSRF token for the embedded forms'); $t->is($w['authors'][$i][sfForm::getCSRFFieldName()], null, '->embedFormForEach() removes the CSRF token for the embedded forms'); } $t->is($w['authors'][0]->generateName('first_name'), 'article[authors][0][first_name]', '->embedFormForEach() changes the name format to reflect the embedding'); // bind too many values for embedded forms $t->diag('bind too many values for embedded forms'); $list = new FormTest(); $list->setWidgets(array('title' => new sfWidgetFormInputText())); $list->setValidators(array('title' => new sfValidatorString())); $list->embedFormForEach('items', clone $list, 2); $list->bind(array('title' => 'list title', 'items' => array(array('title' => 'item 1'), array('title' => 'item 2'), array('title' => 'extra item')))); $t->isa_ok($list['items'][0]->getError(), 'sfValidatorErrorSchema', '"sfFormFieldSchema" is given an error schema when an extra embedded form is bound'); // does this trigger a fatal error? $list['items']->render(); $t->pass('"sfFormFieldSchema" renders when an extra embedded form is bound'); // ->getEmbeddedForms() $t->diag('->getEmbeddedForms()'); $article = new FormTest(); $company = new FormTest(); $author = new FormTest(); $article->embedForm('company', $company); $article->embedForm('author', $author); $forms = $article->getEmbeddedForms();
$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'); // ->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()) { return null; } 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');