Ejemplo n.º 1
0
$t->ok($f->getValidator('name') == $v3, '->setValidator() sets a validator for a field');
// ->setWidgets() ->setWidgetSchema() ->getWidgetSchema() ->getWidget() ->setWidget()
$t->diag('->setWidgets() ->setWidgetSchema() ->getWidgetSchema()');
$f = new FormTest();
$widgets = array('first_name' => new WidgetInputText(), 'last_name' => new WidgetInputText());
$widgetSchema = new WidgetSchema($widgets);
$f->setWidgetSchema($widgetSchema);
$t->ok($f->getWidgetSchema() == $widgetSchema, '->setWidgetSchema() sets the current widget schema');
$f->setWidgets($widgets);
$schema = $f->getWidgetSchema();
$widgets['first_name']->setParent($schema);
$widgets['last_name']->setParent($schema);
$t->ok($schema['first_name'] == $widgets['first_name'], '->setWidgets() sets field widgets');
$t->ok($schema['last_name'] == $widgets['last_name'], '->setWidgets() sets field widgets');
$f->setWidget('name', $w3 = new WidgetInputText());
$w3->setParent($schema);
$t->ok($f->getWidget('name') == $w3, '->setWidget() sets a widget for a field');
// \ArrayAccess interface
$t->diag('ArrayAccess interface');
$f = new FormTest();
$f->setWidgetSchema(new WidgetSchema(array('first_name' => new WidgetInputText(array('default' => 'Fabien')), 'last_name' => new WidgetInputText(), 'image' => new WidgetInputFile())));
$f->setValidatorSchema(new ValidatorSchema(array('first_name' => new ValidatorPass(), 'last_name' => new ValidatorPass(), 'image' => new ValidatorPass())));
$f->setDefaults(array('image' => 'default.gif'));
$f->embedForm('embedded', new Form());
$t->ok($f['first_name'] instanceof Field, '"sfForm" implements the \\ArrayAccess interface');
$t->is($f['first_name']->render(), '<input type="text" name="first_name" value="Fabien" id="first_name" />', '"sfForm" implements the \\ArrayAccess interface');
try {
    $f['image'] = 'image';
    $t->fail('"sfForm" \\ArrayAccess implementation does not permit to set a form field');
} catch (\LogicException $e) {
    $t->pass('"sfForm" \\ArrayAccess implementation does not permit to set a form field');
Ejemplo n.º 2
0
// ->render()
$t->diag('->render()');
$output = <<<EOF
<table>
<tr>
  <th><label for="w1">W1</label></th>
  <td><input type="text" name="w1" id="w1" /></td>
</tr>
</table>
EOF;
$t->is($w->render(null), fix_linebreaks($output), '->render() decorates the widget');
// implements \ArrayAccess
$t->diag('implements \\ArrayAccess');
$w['w2'] = $w2;
$w1->setParent($ws);
$w2->setParent($ws);
$t->ok($w->getFields() == array('w1' => $w1, 'w2' => $w2), 'SchemaDecorator implements the \\ArrayAccess interface for the fields');
$t->ok($ws->getFields() == array('w1' => $w1, 'w2' => $w2), 'SchemaDecorator implements the \\ArrayAccess interface for the fields');
try {
    $w['w1'] = 'string';
    $t->fail('SchemaDecorator implements the \\ArrayAccess interface for the fields');
} catch (\LogicException $e) {
    $t->pass('SchemaDecorator implements the \\ArrayAccess interface for the fields');
}
$w = new SchemaDecorator($ws, "<table>\n%content%</table>");
$t->is(isset($w['w1']), true, 'SchemaDecorator implements the \\ArrayAccess interface for the fields');
$t->is(isset($w['w2']), true, 'SchemaDecorator implements the \\ArrayAccess interface for the fields');
$t->is(isset($ws['w1']), true, 'SchemaDecorator implements the \\ArrayAccess interface for the fields');
$t->is(isset($ws['w2']), true, 'SchemaDecorator implements the \\ArrayAccess interface for the fields');
$w = new SchemaDecorator($ws, "<table>\n%content%</table>");
$t->ok($w['w1'] == $w1, 'SchemaDecorator implements the \\ArrayAccess interface for the fields');
Ejemplo n.º 3
0
use Bundle\sfFormBundle\Field;
use Bundle\sfFormBundle\FieldSchema;
use Bundle\sfFormBundle\Widget\Form as WidgetForm;
use Bundle\sfFormBundle\Widget\Schema as WidgetFormSchema;
use Bundle\sfFormBundle\Widget\InputText as WidgetInputText;
use Bundle\sfFormBundle\Widget\InputHidden as WidgetInputHidden;
use Bundle\sfFormBundle\Validator\Error as ValidatorError;
use Bundle\sfFormBundle\Validator\String as ValidatorString;
use Bundle\sfFormBundle\Validator\ErrorSchema as ValidatorErrorSchema;
$t = new lime_test(31);
// widgets
$authorSchema = new WidgetFormSchema(array('id' => new WidgetInputHidden(), 'name' => $nameWidget = new WidgetInputText()));
$authorSchema->setNameFormat('article[author][%s]');
$schema = new WidgetFormSchema(array('title' => $titleWidget = new WidgetInputText(), 'author' => $authorSchema));
$schema->setNameFormat('article[%s]');
$titleWidget->setParent($schema);
// errors
$authorErrorSchema = new ValidatorErrorSchema(new ValidatorString());
$authorErrorSchema->addError(new ValidatorError(new ValidatorString(), 'name error'), 'name');
$articleErrorSchema = new ValidatorErrorSchema(new ValidatorString());
$articleErrorSchema->addError($titleError = new ValidatorError(new ValidatorString(), 'title error'), 'title');
$articleErrorSchema->addError($authorErrorSchema, 'author');
$parent = new FieldSchema($schema, null, 'article', array('title' => 'symfony', 'author' => array('name' => 'Fabien')), $articleErrorSchema);
$f = $parent['title'];
$child = $parent['author'];
// ->getValue() ->getWidget() ->getParent() ->getError() ->hasError()
$t->diag('->getValue() ->getName() ->getWidget() ->getParent() ->getError() ->hasError()');
$t->ok($f->getWidget() == $titleWidget, '->getWidget() returns the form field widget');
$t->is($f->getName(), 'title', '->getName() returns the form field name');
$t->is($f->getValue(), 'symfony', '->getValue() returns the form field value');
$t->is($f->getParent(), $parent, '->getParent() returns the form field parent');