Exemplo n.º 1
0
$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 sfWidgetFormInputText(array('default' => 'Thomas')), 'last_name' => new sfWidgetFormInputText()));
// 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(), fix_linebreaks($output), '->__toString() renders the form as HTML');
$output = <<<EOF
<tr>
  <th><label for="first_name">First name</label></th>
  <td><input type="text" name="first_name" value="Fabien" class="foo" 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->render(array('first_name' => array('class' => 'foo'))), fix_linebreaks($output), '->render() renders the form as HTML');
$t->is((string) $f['id'], '<input type="hidden" name="id" value="3" id="id" />', '->offsetGet() returns a sfFormField');
$t->is((string) $f['first_name'], '<input type="text" name="first_name" value="Fabien" id="first_name" />', '->offsetGet() returns a sfFormField');
$t->is((string) $f['last_name'], '<input type="text" name="last_name" value="Potencier" id="last_name" />', '->offsetGet() returns a sfFormField');
Exemplo n.º 2
0
$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
<tr>
  <th><label for="first_name">First name</label></th>
  <td><input type="text" name="first_name" value="Fabien" class="foo" 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->render(array('first_name' => array('class' => 'foo'))), $output, '->render() renders the form as HTML');
$t->is((string) $f['id'], '<input type="hidden" name="id" value="3" id="id" />', '->offsetGet() returns a sfFormField');
$t->is((string) $f['first_name'], '<input type="text" name="first_name" value="Fabien" id="first_name" />', '->offsetGet() returns a sfFormField');
$t->is((string) $f['last_name'], '<input type="text" name="last_name" value="Potencier" id="last_name" />', '->offsetGet() returns a sfFormField');