$ws = new sfWidgetFormSchema(array('w1' => $w1)); $w = new sfWidgetFormSchemaDecorator($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; $t->is($w->render(null), fix_linebreaks($output), '->render() decorates the widget'); // implements ArrayAccess $t->diag('implements ArrayAccess'); $w['w2'] = $w2; $t->is($w->getFields(), array('w1' => $w1, 'w2' => $w2), 'sfWidgetFormSchemaDecorator implements the ArrayAccess interface for the fields'); $t->is($ws->getFields(), array('w1' => $w1, 'w2' => $w2), 'sfWidgetFormSchemaDecorator implements the ArrayAccess interface for the fields'); try { $w['w1'] = 'string'; $t->fail('sfWidgetFormSchemaDecorator implements the ArrayAccess interface for the fields'); } catch (LogicException $e) { $t->pass('sfWidgetFormSchemaDecorator implements the ArrayAccess interface for the fields'); } $w = new sfWidgetFormSchemaDecorator($ws, "<table>\n%content%</table>"); $t->is(isset($w['w1']), true, 'sfWidgetFormSchemaDecorator implements the ArrayAccess interface for the fields'); $t->is(isset($w['w2']), true, 'sfWidgetFormSchemaDecorator implements the ArrayAccess interface for the fields'); $t->is(isset($ws['w1']), true, 'sfWidgetFormSchemaDecorator implements the ArrayAccess interface for the fields');
$ws = new sfWidgetFormSchema(array('w1' => $w1)); $w = new sfWidgetFormSchemaDecorator($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; $t->is($w->render(null), $output, '->render() decorates the widget'); // implements ArrayAccess $t->diag('implements ArrayAccess'); $w['w2'] = $w2; $t->is($w->getFields(), array('w1' => $w1, 'w2' => $w2), 'sfWidgetFormSchemaDecorator implements the ArrayAccess interface for the fields'); $t->is($ws->getFields(), array('w1' => $w1, 'w2' => $w2), 'sfWidgetFormSchemaDecorator implements the ArrayAccess interface for the fields'); try { $w['w1'] = 'string'; $t->fail('sfWidgetFormSchemaDecorator implements the ArrayAccess interface for the fields'); } catch (LogicException $e) { $t->pass('sfWidgetFormSchemaDecorator implements the ArrayAccess interface for the fields'); } $w = new sfWidgetFormSchemaDecorator($ws, "<table>\n%content%</table>"); $t->is(isset($w['w1']), true, 'sfWidgetFormSchemaDecorator implements the ArrayAccess interface for the fields'); $t->is(isset($w['w2']), true, 'sfWidgetFormSchemaDecorator implements the ArrayAccess interface for the fields'); $t->is(isset($ws['w1']), true, 'sfWidgetFormSchemaDecorator implements the ArrayAccess interface for the fields');