예제 #1
0
$t->is(count($f), 3, '"sfForm" implements the Countable interface');
// Iterator interface
$t->diag('Iterator interface');
$f = new FormTest();
$f->setWidgetSchema(new sfWidgetFormSchema(array('first_name' => new sfWidgetFormInputText(array('default' => 'Fabien')), 'last_name' => new sfWidgetFormInputText(), 'image' => new sfWidgetFormInputFile())));
foreach ($f as $name => $value) {
    $values[$name] = $value;
}
$t->is(isset($values['first_name']), true, '"sfForm" implements the Iterator interface');
$t->is(isset($values['last_name']), true, '"sfForm" implements the Iterator interface');
$t->is_deeply(array_keys($values), array('first_name', 'last_name', 'image'), '"sfForm" implements the Iterator interface');
// ->useFields()
$t->diag('->useFields()');
$f = new FormTest();
$f->setWidgetSchema(new sfWidgetFormSchema(array('first_name' => new sfWidgetFormInputText(), 'last_name' => new sfWidgetFormInputText(), 'email' => new sfWidgetFormInputText())));
$f->useFields(array('first_name', 'last_name'));
$t->is($f->getWidgetSchema()->getPositions(), array('first_name', 'last_name'), '->useFields() removes all fields except the ones given as an argument');
$f->setWidgetSchema(new sfWidgetFormSchema(array('first_name' => new sfWidgetFormInputText(), 'last_name' => new sfWidgetFormInputText(), 'email' => new sfWidgetFormInputText())));
$f->useFields(array('email', 'first_name'));
$t->is($f->getWidgetSchema()->getPositions(), array('email', 'first_name'), '->useFields() reorders the fields');
$f->setWidgetSchema(new sfWidgetFormSchema(array('first_name' => new sfWidgetFormInputText(), 'last_name' => new sfWidgetFormInputText(), 'email' => new sfWidgetFormInputText())));
$f->useFields(array('email', 'first_name'), false);
$t->is($f->getWidgetSchema()->getPositions(), array('first_name', 'email'), '->useFields() does not reorder the fields if the second argument is false');
$f->setWidgetSchema(new sfWidgetFormSchema(array('id' => new sfWidgetFormInputHidden(), 'first_name' => new sfWidgetFormInputText(), 'last_name' => new sfWidgetFormInputText(), 'email' => new sfWidgetFormInputText())));
$f->useFields(array('first_name', 'last_name'));
$t->is($f->getWidgetSchema()->getPositions(), array('first_name', 'last_name', 'id'), '->useFields() does not remove hidden fields');
// ->bind() ->isValid() ->hasErrors() ->getValues() ->getValue() ->isBound() ->getErrorSchema()
$t->diag('->bind() ->isValid() ->getValues() ->isBound() ->getErrorSchema()');
$f = new FormTest();
$f->setValidatorSchema(new sfValidatorSchema(array('first_name' => new sfValidatorString(array('min_length' => 2)), 'last_name' => new sfValidatorString(array('min_length' => 2)))));
$t->ok(!$f->isBound(), '->isBound() returns false if the form is not bound');