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 WidgetSchema; 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(11); // widgets $authorSchema = new WidgetSchema(array('name' => $nameWidget = new WidgetInputText())); $authorSchema->setNameFormat('article[author][%s]'); $schema = new WidgetSchema(array('title' => $titleWidget = new WidgetInputText(), 'author' => $authorSchema)); $schema->setNameFormat('article[%s]'); // 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']; // \ArrayAccess interface $t->diag('ArrayAccess interface'); $t->is(isset($parent['title']), true, 'sfFormField implements the \\ArrayAccess interface'); $t->is(isset($parent['title1']), false, 'sfFormField implements the \\ArrayAccess interface'); $t->is($parent['title'], $f, 'sfFormField implements the \\ArrayAccess interface'); try {
* file that was distributed with this source code. */ 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');