public function configure() { $this->setWidget('captcha', new opWidgetFormCaptcha()); $this->setValidator('captcha', new sfValidatorPass()); $formatter = new sfWidgetFormSchemaFormatterList($this->widgetSchema); $formatter->setRowFormat("<li>%field%%help%\n%hidden_fields%</li>\n"); $formatter->setHelpFormat('<div class="help">%help%</div>'); $this->widgetSchema->addFormFormatter('opCaptchaFormFormatter', $formatter); $this->widgetSchema->setFormFormatterName('opCaptchaFormFormatter'); $this->validatorSchema->setPostValidator(new sfValidatorCallback(array('callback' => array($this, 'validateCaptchaString')))); $this->widgetSchema->setHelp('captcha', 'Please input the below keyword.'); }
<th><label for="w4_w3">W3</label></th> <td><input type="text" name="w4[w3]" id="w4_w3" /></td> </tr> </table> <input type="hidden" name="w1" id="w1" /> </td> </tr> EOF; $t->is(str_replace("\n", '', preg_replace('/^ +/m', '', $w->render(null))), str_replace("\n", '', preg_replace('/^ +/m', '', fix_linebreaks($expected))), '->render() is able to render widget schema that only contains hidden fields when the last field is a form'); // __clone() $t->diag('__clone()'); $w = new sfWidgetFormSchema(array('w1' => $w1, 'w2' => $w2)); $w1->setParent($w); $w2->setParent($w); $format1 = new sfWidgetFormSchemaFormatterList($w); $format1->setTranslationCatalogue('english'); $w->addFormFormatter('testFormatter', $format1); $w1 = clone $w; $f1 = $w1->getFields(); $f = $w->getFields(); $t->is(array_keys($f1), array_keys($f), '__clone() clones embedded widgets'); foreach ($f1 as $name => $widget) { $t->ok($widget !== $f[$name], '__clone() clones embedded widgets'); $t->ok($widget->getParent() === $w1, 'The parents hafe been changed'); // avoid recursive dependencies at comparing $widget->setParent(null); $f[$name]->setParent(null); $t->ok($widget == $f[$name], '__clone() clones embedded widgets'); } $format1->setTranslationCatalogue('french');
<?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/unit.php'; $t = new lime_test(2); $f = new sfWidgetFormSchemaFormatterList(new sfWidgetFormSchema()); // ->formatRow() $t->diag('->formatRow()'); $output = <<<EOF <li> label <input /><br />help </li> EOF; $t->is($f->formatRow('label', '<input />', array(), 'help', ''), fix_linebreaks($output), '->formatRow() formats a field in a row'); // ->formatErrorRow() $t->diag('->formatErrorRow()'); $output = <<<EOF <li> <ul class="error_list"> <li>Global error</li> <li>id: required</li> <li>1 > sub_id: required</li> </ul>