Exemplo n.º 1
0
$f = new FormTest();
$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)))));