コード例 #1
0
ファイル: sfFormTest.php プロジェクト: Tony-M/GrannySymfony
$t->ok($f->isBound(), '->isBound() returns true if the form is bound');
$t->is($f->getValues(), array('first_name' => 'Fabien', 'last_name' => 'Potencier'), '->getValues() returns an array of cleaned values if the form is bound');
$t->ok($f->isValid(), '->isValid() returns true if the form passes the validation');
$t->ok(!$f->hasErrors(), '->hasErrors() returns false if the form passes the validation');
$t->is($f->getValue('first_name'), 'Fabien', '->getValue() returns the cleaned value for a field name if the form is bound');
$t->is($f->getValue('nonsense'), null, '->getValue() returns null when non-existant param is requested');
$f->bind(array());
$t->ok(!$f->isValid(), '->isValid() returns false if the form does not pass the validation');
$t->ok($f->hasErrors(), '->isValid() returns true if the form does not pass the validation');
$t->is($f->getValues(), array(), '->getValues() returns an empty array if the form does not pass the validation');
$t->is($f->getErrorSchema()->getMessage(), 'first_name [Required.] last_name [Required.]', '->getErrorSchema() returns an error schema object with all errors');
$t->diag('bind when field names are numeric');
$f = new FormTest();
$f->setValidatorSchema(new sfValidatorSchema(array(1 => new sfValidatorString(array('min_length' => 2)), 2 => new sfValidatorString(array('min_length' => 2)))));
$f->bind(array(1 => 'fabien', 2 => 'potencier'));
$t->ok($f->isValid(), '->bind() behaves correctly when field names are numeric');
$t->diag('bind with files');
$f = new FormTest();
$f->setValidatorSchema(new sfValidatorSchema(array(1 => new sfValidatorString(array('min_length' => 2)), 2 => new sfValidatorString(array('min_length' => 2)), 'file' => new sfValidatorFile(array('max_size' => 2)))));
$f->setWidgetSchema(new sfWidgetFormSchema(array('file' => new sfWidgetFormInputFile())));
$f->bind(array(1 => 'f', 2 => 'potencier'), array('file' => array('name' => 'test1.txt', 'type' => 'text/plain', 'tmp_name' => '/tmp/test1.txt', 'error' => 0, 'size' => 100)));
$t->is($f->getErrorSchema()->getCode(), '1 [min_length] file [max_size]', '->bind() behaves correctly with files');
try {
    $f->bind(array(1 => 'f', 2 => 'potencier'));
    $t->fail('->bind() second argument is mandatory if the form is multipart');
} catch (InvalidArgumentException $e) {
    $t->pass('->bind() second argument is mandatory if the form is multipart');
}
$t->diag('bind with files in embed form');
$pf = new FormTest();
//parent form