$t->is($w->renderTag('input', array('id' => 'foo')), '<input id="foo" />', '->renderTag() does not add an id if one is given'); $t->is($w->renderTag('input', array('name' => 'foo')), '<input name="foo" id="foo" />', '->renderTag() adds an id if none is given and a name is given'); $w->setIdFormat('id_%s'); $t->is($w->renderTag('input', array('name' => 'foo')), '<input name="foo" id="id_foo" />', '->renderTag() uses the id_format to generate an id'); sfWidget::setXhtml(false); $t->is($w->renderTag('input'), '<input>', '->renderTag() does not close tag if not in XHTML mode'); sfWidget::setXhtml(true); // ->renderContentTag() $t->diag('->renderContentTag()'); $w = new MyWidgetForm(); $t->is($w->renderContentTag('textarea'), '<textarea></textarea>', '->renderContentTag() does not add an id if no name is given'); $t->is($w->renderContentTag('textarea', '', array('id' => 'foo')), '<textarea id="foo"></textarea>', '->renderContentTag() does not add an id if one is given'); $t->is($w->renderContentTag('textarea', '', array('name' => 'foo')), '<textarea name="foo" id="foo"></textarea>', '->renderContentTag() adds an id if none is given and a name is given'); $w->setIdFormat('id_%s'); $t->is($w->renderContentTag('textarea', '', array('name' => 'foo')), '<textarea name="foo" id="id_foo"></textarea>', '->renderContentTag() uses the id_format to generate an id'); // ->generateId() $t->diag('->generateId()'); $w = new MyWidgetForm(); $w->setIdFormat('id_for_%s_works'); $t->is($w->generateId('foo'), 'id_for_foo_works', '->setIdFormat() sets the format of the widget id'); $t->is($w->generateId('foo[]'), 'id_for_foo_works', '->generateId() removes the [] from the name'); $t->is($w->generateId('foo[]', array()), 'id_for_foo_works', '->generateId() accepts array value'); $t->is($w->generateId('foo[bar][]'), 'id_for_foo_bar_works', '->generateId() replaces [] with _'); $t->is($w->generateId('foo[bar][]', 'test'), 'id_for_foo_bar_test_works', '->generateId() takes the value into account if provided'); $t->is($w->generateId('_foo[bar][]', 'test'), 'id_for__foo_bar_test_works', '->generateId() leaves valid ids'); $w->setIdFormat('id'); $t->is($w->generateId('foo[bar][]', 'test'), 'foo_bar_test', '->generateId() returns the name if the id format does not contain %s'); $w->setIdFormat('%s'); $t->is($w->generateId('_foo[bar][]', 'test'), 'foo_bar_test', '->generateId() removes invalid characters'); $t->is($w->generateId('_foo@bar'), 'foo_bar', '->generateId() removes invalid characters'); $t->is($w->generateId('_____foo@bar'), 'foo_bar', '->generateId() removes invalid characters');
$w = new MyWidgetForm(array('needs_multipart' => true)); $t->is($w->needsMultipartForm(), true, '->needsMultipartForm() returns false if the widget needs a multipart form'); // ->renderTag() $t->diag('->renderTag()'); $w = new MyWidgetForm(); $t->is($w->renderTag('input'), '<input />', '->renderTag() does not add an id if no name is given'); $t->is($w->renderTag('input', array('id' => 'foo')), '<input id="foo" />', '->renderTag() does not add an id if one is given'); $t->is($w->renderTag('input', array('name' => 'foo')), '<input name="foo" id="foo" />', '->renderTag() adds an id if none is given and a name is given'); $w->setIdFormat('id_%s'); $t->is($w->renderTag('input', array('name' => 'foo')), '<input name="foo" id="id_foo" />', '->renderTag() uses the id_format to generate an id'); sfWidget::setXhtml(false); $t->is($w->renderTag('input'), '<input>', '->renderTag() does not close tag if not in XHTML mode'); sfWidget::setXhtml(true); // ->renderContentTag() $t->diag('->renderContentTag()'); $w = new MyWidgetForm(); $t->is($w->renderContentTag('textarea'), '<textarea></textarea>', '->renderContentTag() does not add an id if no name is given'); $t->is($w->renderContentTag('textarea', '', array('id' => 'foo')), '<textarea id="foo"></textarea>', '->renderContentTag() does not add an id if one is given'); $t->is($w->renderContentTag('textarea', '', array('name' => 'foo')), '<textarea name="foo" id="foo"></textarea>', '->renderContentTag() adds an id if none is given and a name is given'); $w->setIdFormat('id_%s'); $t->is($w->renderContentTag('textarea', '', array('name' => 'foo')), '<textarea name="foo" id="id_foo"></textarea>', '->renderContentTag() uses the id_format to generate an id'); // ->generateId() $t->diag('->generateId()'); $w = new MyWidgetForm(); $w->setIdFormat('id_for_%s_works'); $t->is($w->generateId('foo'), 'id_for_foo_works', '->setIdFormat() sets the format of the widget id'); $t->is($w->generateId('foo[]'), 'id_for_foo_works', '->generateId() removes the [] from the name'); $t->is($w->generateId('foo[bar][]'), 'id_for_foo_bar_works', '->generateId() replaces [] with _'); $t->is($w->generateId('foo[bar][]', 'test'), 'id_for_foo_bar_test_works', '->generateId() takes the value into account if provided'); $w->setIdFormat('id'); $t->is($w->generateId('foo[bar][]', 'test'), 'foo_bar_test', '->generateId() returns the name if the id format does not contain %s');