$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))); $t->is_deeply(sfForm::convertFileInformation($input), $expected, '::convertFileInformation() converts $_FILES to be coherent with $_GET and $_POST naming convention'); $t->is_deeply(sfForm::convertFileInformation($expected), $expected, '::convertFileInformation() only changes the input array if needed'); $input = array('file' => array('name' => 'test.txt', 'type' => 'text/plain', 'tmp_name' => '/tmp/test.txt', 'error' => 0, 'size' => 100), 'article' => array('name' => array('name' => array('name' => 'test1.txt', 'another' => array('file2' => 'test2.txt'))), 'type' => array('name' => array('name' => 'text/plain', 'another' => array('file2' => 'text/plain'))), 'tmp_name' => array('name' => array('name' => '/tmp/test1.txt', 'another' => array('file2' => '/tmp/test2.txt'))), 'error' => array('name' => array('name' => 0, 'another' => array('file2' => 0))), 'size' => array('name' => array('name' => 100, 'another' => array('file2' => 200)))));