Ejemplo n.º 1
0
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(array_keys($forms), array('company', 'author'), '->getEmbeddedForms() returns the embedded forms');
Ejemplo n.º 2
0
$t->diag('->renderGlobalErrors()');
$f = new FormTest();
$f->setValidatorSchema(new sfValidatorSchema(array('id' => new sfValidatorInteger(), 'first_name' => new sfValidatorString(array('min_length' => 2)), 'last_name' => new sfValidatorString(array('min_length' => 2)))));
$f->setWidgetSchema(new sfWidgetFormSchema(array('id' => new sfWidgetFormInputHidden(), 'first_name' => new sfWidgetFormInput(), 'last_name' => new sfWidgetFormInput())));
$f->bind(array('id' => 'dddd', 'first_name' => 'f', 'last_name' => 'potencier'));
$output = <<<EOF
  <ul class="error_list">
    <li>Id: "dddd" is not an integer.</li>
  </ul>

EOF;
$t->is($f->renderGlobalErrors(), $output, '->renderGlobalErrors() renders global errors as an HTML list');
// ->render()
$t->diag('->render()');
$f = new FormTest(array('first_name' => 'Fabien', 'last_name' => 'Potencier'));
$f->setValidators(array('id' => new sfValidatorInteger(), 'first_name' => new sfValidatorString(array('min_length' => 2)), 'last_name' => new sfValidatorString(array('min_length' => 2))));
$f->setWidgets(array('id' => new sfWidgetFormInputHidden(array('default' => 3)), 'first_name' => new sfWidgetFormInput(array('default' => 'Thomas')), 'last_name' => new sfWidgetFormInput()));
// unbound
$output = <<<EOF
<tr>
  <th><label for="first_name">First name</label></th>
  <td><input type="text" name="first_name" value="Fabien" id="first_name" /></td>
</tr>
<tr>
  <th><label for="last_name">Last name</label></th>
  <td><input type="text" name="last_name" value="Potencier" id="last_name" /><input type="hidden" name="id" value="3" id="id" /></td>
</tr>

EOF;
$t->is($f->__toString(), $output, '->__toString() renders the form as HTML');
$output = <<<EOF