Beispiel #1
0
$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');
$t->is($forms['company'], $company, '->getEmbeddedForms() returns the embedded forms');
$t->isa_ok($article->getEmbeddedForm('company'), 'FormTest', '->getEmbeddedForm() return an embedded form');
try {
    $article->getEmbeddedForm('nonexistant');
    $t->fail('->getEmbeddedForm() throws an exception if the embedded form does not exist');
} catch (InvalidArgumentException $e) {
    $t->pass('->getEmbeddedForm() throws an exception if the embedded form does not exist');
}
// ::convertFileInformation()
$t->diag('::convertFileInformation()');
$input = array('file' => array('name' => 'test1.txt', 'type' => 'text/plain', 'tmp_name' => '/tmp/test1.txt', 'error' => 0, 'size' => 100), 'file1' => array('name' => 'test2.txt', 'type' => 'text/plain', 'tmp_name' => '/tmp/test1.txt', 'error' => 0, 'size' => 200));
$t->is_deeply(sfForm::convertFileInformation($input), $input, '::convertFileInformation() converts $_FILES to be coherent with $_GET and $_POST naming convention');
$input = array('article' => array('name' => array('file1' => 'test1.txt', 'file2' => 'test2.txt'), 'type' => array('file1' => 'text/plain', 'file2' => 'text/plain'), 'tmp_name' => array('file1' => '/tmp/test1.txt', 'file2' => '/tmp/test2.txt'), 'error' => array('file1' => 0, 'file2' => 0), 'size' => array('file1' => 100, 'file2' => 200)));
$expected = array('article' => array('file1' => array('name' => 'test1.txt', 'type' => 'text/plain', 'tmp_name' => '/tmp/test1.txt', 'error' => 0, 'size' => 100), 'file2' => array('name' => 'test2.txt', 'type' => 'text/plain', 'tmp_name' => '/tmp/test2.txt', 'error' => 0, 'size' => 200)));