$f->setValidator('name', $v3 = new ValidatorPass()); $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) {
<?php /* * This file is part of the symfony package. * (c) Fabien Potencier <*****@*****.**> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ require_once dirname(__FILE__) . '/../bootstrap.php'; use Bundle\sfFormBundle\Widget\InputText; use Bundle\sfFormBundle\Widget\Schema; use Bundle\sfFormBundle\Widget\SchemaDecorator; $t = new lime_test(16); $w1 = new InputText(); $w2 = new InputText(); $ws = new Schema(array('w1' => $w1)); $w = new SchemaDecorator($ws, "<table>\n%content%</table>"); // ->getWidget() $t->diag('->getWidget()'); $t->is($w->getWidget(), $ws, '->getWidget() returns the decorated widget'); // ->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;
*/ require_once dirname(__FILE__) . '/bootstrap.php'; 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');