$d = $article->getDefaults(); $w->setNameFormat('article[%s]'); $t->ok($v['author']['first_name'] == $author_validator_schema['first_name'], '->embedForm() embeds the validator schema'); // ignore parents in comparison $w['author']['first_name']->setParent(null); $author_widget_schema['first_name']->setParent(null); $t->ok($w['author']['first_name'] == $author_widget_schema['first_name'], '->embedForm() embeds the widget schema'); $t->is($d['author']['first_name'], 'Fabien', '->embedForm() merges default values from the embedded form'); $t->is($v['author'][sfForm::getCSRFFieldName()], null, '->embedForm() removes the CSRF token for the embedded form'); $t->is($w['author'][sfForm::getCSRFFieldName()], null, '->embedForm() removes the CSRF token for the embedded form'); $t->is($w['author']->generateName('first_name'), 'article[author][first_name]', '->embedForm() changes the name format to reflect the embedding'); $t->is($w['author']['company']->generateName('name'), 'article[author][company][name]', '->embedForm() changes the name format to reflect the embedding'); // tests for ticket #4754 $f1 = new TestForm1(); $f2 = new TestForm2(); $f1->embedForm('f2', $f2); $t->is($f1['f2']['c']->render(), '<textarea rows="4" cols="30" name="f2[c]" id="f2_c"></textarea>', '->embedForm() generates a correct id in embedded form fields'); $t->is($f1['f2']['c']->renderLabel(), '<label for="f2_c">2_c</label>', '->embedForm() generates a correct label id correctly in embedded form fields'); // ->embedFormForEach() $t->diag('->embedFormForEach()'); $article->embedFormForEach('authors', $author, 2, null, null, array('id_format' => '%s_id'), array('class' => 'embedded')); $v = $article->getValidatorSchema(); $w = $article->getWidgetSchema(); $d = $article->getDefaults(); $w->setNameFormat('article[%s]'); for ($i = 0; $i < 2; $i++) { $t->ok($v['authors'][$i]['first_name'] == $author_validator_schema['first_name'], '->embedFormForEach() embeds the validator schema'); // ignore the parents in comparison $w['authors'][$i]['first_name']->setParent(null); $author_widget_schema['first_name']->setParent(null); $t->ok($w['authors'][$i]['first_name'] == $author_widget_schema['first_name'], '->embedFormForEach() embeds the widget schema');
$f->setWidgets(array('foo' => new MyWidget(array('name' => 'foo')), 'bar' => new MyWidget(array('name' => 'bar')))); $t->is($f->getJavaScripts(), array('/path/to/a/foo.js', '/path/to/a/bar.js'), '->getJavaScripts() returns the stylesheets of all widgets'); $t->is($f->getStylesheets(), array('/path/to/a/foo.css' => 'all', '/path/to/a/bar.css' => 'all'), '->getStylesheets() returns the JavaScripts of all widgets'); // ->getFormFieldSchema() $t->diag('->getFormFieldSchema()'); $f = new NumericFieldsForm(array('5' => 'default')); $t->is_deeply($f->getFormFieldSchema()->getValue(), array('5' => 'default'), '->getFormFieldSchema() includes default numeric fields'); $f->bind(array('5' => 'bound')); $t->is_deeply($f->getFormFieldSchema()->getValue(), array('5' => 'bound'), '->getFormFieldSchema() includes bound numeric fields'); // ->getErrors() $t->diag('->getErrors()'); $f1 = new TestForm1(); $f21 = new TestForm1(); $f2 = new TestForm2(); $f2->embedForm('F21', $f21); $f1->embedForm('F2', $f2); $f1->bind(array()); $expected = array('1_a' => 'Required.', '1_b' => 'Required.', '1_c' => 'Required.', 'F2' => array('2_d' => 'Required.', 'F21' => array('1_a' => 'Required.', '1_b' => 'Required.', '1_c' => 'Required.'))); $t->is($f1->getErrors(), $expected, '->getErrors() return array of errors'); // bind with a simulated file upload in the POST array $f = new FormTest(); try { $f->bind(array('file' => array('name' => 'foo.txt', 'type' => 'text/plain', 'tmp_name' => 'somefile', 'error' => 0, 'size' => 10))); $t->fail('Cannot fake a file upload with a POST'); } catch (InvalidArgumentException $e) { $t->pass('Cannot fake a file upload with a POST'); } $f = new FormTest(); try { $f->bind(array('foo' => array('bar' => array('file' => array('name' => 'foo.txt', 'type' => 'text/plain', 'tmp_name' => 'somefile', 'error' => 0, 'size' => 10))))); $t->fail('Cannot fake a file upload with a POST');