示例#1
0
$f2 = new TestForm2();
$f1->mergeForm($f2);
$widgetSchema = $f1->getWidgetSchema();
$validatorSchema = $f1->getValidatorSchema();
$t->is(count($widgetSchema->getFields()), 4, 'mergeForm() merges a widget form schema');
$t->is(count($validatorSchema->getFields()), 4, 'mergeForm() merges a validator schema');
$t->is(array_keys($widgetSchema->getFields()), array('a', 'b', 'c', 'd'), 'mergeForms() merges the correct widgets');
$t->is(array_keys($validatorSchema->getFields()), array('a', 'b', 'c', 'd'), 'mergeForms() merges the correct validators');
$t->is($widgetSchema->getLabels(), array('a' => '1_a', 'b' => '1_b', 'c' => '2_c', 'd' => '2_d'), 'mergeForm() merges labels correctly');
$t->is($widgetSchema->getHelps(), array('a' => '1_a', 'b' => '1_b', 'c' => '2_c', 'd' => '2_d'), 'mergeForm() merges helps correctly');
$t->isa_ok($widgetSchema['c'], 'sfWidgetFormTextarea', 'mergeForm() overrides original form widget');
$t->isa_ok($validatorSchema['c'], 'sfValidatorPass', 'mergeForm() overrides original form validator');
$t->isa_ok($validatorSchema->getPreValidator(), 'sfValidatorPass', 'mergeForm() merges pre validator');
$t->isa_ok($validatorSchema->getPostValidator(), 'sfValidatorPass', 'mergeForm() merges post validator');
try {
    $f1->bind(array('a' => 'foo', 'b' => 'bar', 'd' => 'far_too_long_value'));
    $f1->mergeForm($f2);
    $t->fail('mergeForm() disallows merging already bound forms');
} catch (LogicException $e) {
    $t->pass('mergeForm() disallows merging already bound forms');
}
$errorSchema = $f1->getErrorSchema();
$t->ok(array_key_exists('d', $errorSchema->getErrors()), 'mergeForm() merges errors after having been bound');
$f1 = new TestForm1();
$f1->getWidgetSchema()->moveField('a', 'last');
// is moved field well positioned when accessed with iterator interface? (#5551)
foreach ($f1 as $f1name => $f1field) {
    $t->is($f1name, 'b', 'iterating on form takes in account ->moveField() operations.');
    break;
}
$f2 = new TestForm2();
示例#2
0
$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');
} catch (InvalidArgumentException $e) {