Example #1
0
// ->embedFormForEach()
$t->diag('->embedFormForEach()');
$article->embedFormForEach('authors', $author, 2, null, null, array('id_format' => '%s_id'), array('class' => 'embedded'));
$v = $article->getValidatorSchema();
$w = $article->getWidgetSchema();
$d = $article->getDefaults();
$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][Form::getCSRFFieldName()], null, '->embedFormForEach() removes the CSRF token for the embedded forms');
    $t->is($w['authors'][$i][Form::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 WidgetInputText()));
$list->setValidators(array('title' => new ValidatorString()));
$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(), 'Bundle\\sfFormBundle\\Validator\\ErrorSchema', '"Bundle\\sfFormBundle\\Validator\\ErrorSchema" is given an error schema when an extra embedded form is bound');
// does this trigger a fatal error?
$list['items']->render();
$t->pass('"Bundle\\sfFormBundle\\Validator\\ErrorSchema" renders when an extra embedded form is bound');
// ->getEmbeddedForms()
$t->diag('->getEmbeddedForms()');