$t->is($f->render(array('first_name' => array('class' => 'foo'))), fix_linebreaks($output), '->render() renders the form as HTML'); $t->is((string) $f['id'], '<input type="hidden" name="id" value="1" id="id" />', '->offsetGet() returns a sfFormField'); $t->is((string) $f['first_name'], '<input type="text" name="first_name" value="Fabien" id="first_name" />', '->offsetGet() returns a sfFormField'); $t->is((string) $f['last_name'], '<input type="text" name="last_name" value="Potencier" id="last_name" />', '->offsetGet() returns a sfFormField'); // renderUsing() $t->diag('->renderUsing()'); $f = new sfForm(); $f->setWidgets(array('name' => new sfWidgetFormInputText())); $output = <<<EOF <li> <label for="name">Name</label> <input type="text" name="name" id="name" /> </li> EOF; $t->is($f->renderUsing('list'), fix_linebreaks($output), 'renderUsing() renders the widget schema using the given form formatter'); $t->is($f->getWidgetSchema()->getFormFormatterName(), 'table', 'renderUsing() does not persist form formatter name for the current form instance'); $w = $f->getWidgetSchema(); $w->addFormFormatter('custom', new sfWidgetFormSchemaFormatterList($w)); $t->is($f->renderUsing('custom'), fix_linebreaks($output), 'renderUsing() renders a custom form formatter'); try { $f->renderUsing('nonexistant'); $t->fail('renderUsing() throws an exception if formatter name does not exist'); } catch (InvalidArgumentException $e) { $t->pass('renderUsing() throws an exception if formatter name does not exist'); } // renderHiddenFields() $t->diag('->renderHiddenFields()'); $f = new sfForm(); $f->setWidgets(array('id' => new sfWidgetFormInputHidden(), 'name' => new sfWidgetFormInputText(), 'is_admin' => new sfWidgetFormInputHidden())); $output = '<input type="hidden" name="id" id="id" /><input type="hidden" name="is_admin" id="is_admin" />';
$t->is($f->render(array('first_name' => array('class' => 'foo'))), $output, '->render() renders the form as HTML'); $t->is((string) $f['id'], '<input type="hidden" name="id" value="1" id="id" />', '->offsetGet() returns a sfFormField'); $t->is((string) $f['first_name'], '<input type="text" name="first_name" value="Fabien" id="first_name" />', '->offsetGet() returns a sfFormField'); $t->is((string) $f['last_name'], '<input type="text" name="last_name" value="Potencier" id="last_name" />', '->offsetGet() returns a sfFormField'); // renderUsing() $t->diag('->renderUsing()'); $f = new sfForm(); $f->setWidgets(array('name' => new sfWidgetFormInput())); $output = <<<EOF <li> <label for="name">Name</label> <input type="text" name="name" id="name" /> </li> EOF; $t->is($f->renderUsing('list'), $output, 'renderUsing() renders the widget schema using the given form formatter'); $t->is($f->getWidgetSchema()->getFormFormatterName(), 'table', 'renderUsing() does not persist form formatter name for the current form instance'); // renderHiddenFields() $t->diag('->renderHiddenFields()'); $f = new sfForm(); $f->setWidgets(array('id' => new sfWidgetFormInputHidden(), 'name' => new sfWidgetFormInput(), 'is_admin' => new sfWidgetFormInputHidden())); $output = '<input type="hidden" name="id" id="id" /><input type="hidden" name="is_admin" id="is_admin" />'; $t->is($f->renderHiddenFields(), $output, 'renderHiddenFields() renders all hidden fields, no visible fields'); $t->is(count($f->getFormFieldSchema()), 3, 'renderHiddenFields() does not modify the form fields'); // ->embedForm() $t->diag('->embedForm()'); $author = new FormTest(array('first_name' => 'Fabien')); $author->setWidgetSchema($author_widget_schema = new sfWidgetFormSchema(array('first_name' => new sfWidgetFormInput()))); $author->setValidatorSchema($author_validator_schema = new sfValidatorSchema(array('first_name' => new sfValidatorString(array('min_length' => 2))))); $company = new FormTest(); $company->setWidgetSchema($company_widget_schema = new sfWidgetFormSchema(array('name' => new sfWidgetFormInput())));