use Test::More;
-plan tests => 66;
+plan tests => 80;
use_ok('HTML::Form::Simple');
my $form = HTML::Form::Simple->new;
ok($form, 'new form');
+# basics
+
+is(
+ $form->quote('<"test">'),
+ '<"test">',
+ 'quote'
+);
+
+is(
+ $form->quote(\'<"test">'),
+ '<"test">',
+ 'quote unquoted'
+);
+
+is(
+ $form->tag('foo'),
+ '<foo>',
+ 'tag'
+);
+
+is(
+ $form->tag('a "' => {'b"' => 'c"'}),
+ '<a " b"="c"">',
+ 'tag attributes'
+);
+
# form
is(
'multiple radio labels'
);
+is_deeply(
+ [ $form->radio(undef, [0, 1], undef, 0) ],
+ [
+ '<input checked type="radio" value="0">',
+ '<input type="radio" value="1">',
+ ],
+ 'radio default'
+);
+
is_deeply(
[ $form->radio(foo => ['foo', ''], 'test', {value => '', id => ''}) ],
[
is(
$form->check('foo'),
- '<input id="foo_1" name="foo" type="checkbox" value="1">',
+ '<input id="foo" name="foo" type="checkbox" value="1">',
'check method'
);
is(
$form->check(foo => '<">'),
- '<label><input id="foo_1" name="foo" type="checkbox" value="1"> <"></label>',
+ '<label><input id="foo" name="foo" type="checkbox" value="1"> <"></label>',
'labeled checkbox'
);
'anonymous checkbox'
);
+is(
+ $form->check(foo => [undef]),
+ '<input id="foo_1" name="foo" type="checkbox" value="1">',
+ 'multipart check'
+);
+
+is_deeply(
+ [ $form->check(foo => [{value => undef}, undef]) ],
+ [
+ '<input id="foo" name="foo" type="checkbox">',
+ '<input id="foo_2" name="foo" type="checkbox" value="2">',
+ ],
+ 'multiple checkboxes'
+);
+
+is(
+ $form->check(foo => [undef], {id => ''}),
+ '<input name="foo" type="checkbox" value="1">',
+ 'idless checks'
+);
+
+is_deeply(
+ [ $form->check(
+ foo => [ {id => 'quux'}, {name => 'name'}, {value => 0}, {id => ''}, undef ], {id => 'bar'}
+ ) ],
+ [
+ '<input id="quux" name="foo" type="checkbox" value="1">',
+ '<input id="bar_2" name="name" type="checkbox" value="2">',
+ '<input id="bar_0" name="foo" type="checkbox" value="0">',
+ '<input name="foo" type="checkbox" value="4">',
+ '<input id="bar_5" name="foo" type="checkbox" value="5">',
+ ],
+ 'check overrides'
+);
+
+is_deeply(
+ [ $form->check(foo => ['bar', {name => 'bar'}], {name => 'ignored'}) ],
+ [
+ '<label><input id="foo_1" name="foo" type="checkbox" value="1"> bar</label>',
+ '<input id="foo_2" name="bar" type="checkbox" value="2">',
+ ],
+ 'checkbox names'
+);
+
is_deeply(
[ $form->check(undef, ['', '<">']) ],
[
'<input type="checkbox" value="1">',
'<label><input type="checkbox" value="2"> <"></label>',
],
- 'multiple checkboxes'
+ 'anonymous checkboxes'
);
is_deeply(
'various checkboxes'
);
+# row
+
+is(
+ $form->row(undef),
+ '<label></label> <input type="text">',
+ 'empty row'
+);
+
+is(
+ $form->row('test'),
+ '<label for="test">test</label> <input id="test" name="test" type="text">',
+ 'standard row'
+);
+
+is(
+ $form->row('test', {type => 'password'}, {for => '', label => '"blah"'}),
+ '<label>"blah"</label> <input id="test" name="test" type="password">',
+ 'row options'
+);
+
+is(
+ $form->row('test', '"scalar"', {for => ''}),
+ '<label>test</label> "scalar"',
+ 'row scalar'
+);
+
# defaults
my $defform = HTML::Form::Simple->new({foo => '<">', '' => 'empty', 0 => 0});