X-Git-Url: http://git.shiar.net/gitweb.cgi/perl/html-form-simple.git/blobdiff_plain/ac5c326058425050aa8f7ba5036f2f3bc0695350..d74d61d638a9f0c83f3860de02225c16309ccf2d:/t/html.t?ds=sidebyside
diff --git a/t/html.t b/t/html.t
index e023997..3c6d8f4 100644
--- a/t/html.t
+++ b/t/html.t
@@ -5,7 +5,7 @@ use warnings;
use Test::More;
-plan tests => 31;
+plan tests => 53;
use_ok('HTML::Form::Simple');
@@ -52,7 +52,20 @@ is(
'hidden'
);
-#TODO: hidden options
+is(
+ $form->hidden(undef, undef, {value => 'bar', name => 'foo', id => 'foo'}),
+ '',
+ 'hidden options'
+);
+
+is_deeply(
+ [ $form->hidden({2 => 0, 10 => 1}, {class => 'test'}) ],
+ [
+ '',
+ '',
+ ],
+ 'hidden hash'
+);
# submit
@@ -119,15 +132,22 @@ is(
);
is(
- $form->input('', '', {disabled => 0, something => undef, class => undef, style => ''}),
+ $form->input('', '', {
+ disabled => 0,
+ something => undef,
+ class => undef,
+ style => '',
+ name => 'ignore',
+ value => 'overrides',
+ }),
'',
'input with empty attributes'
);
is(
- $form->input(undef, undef, {name => 'override', value => 'override'}),
- '',
- 'ignore input overrides'
+ $form->input(undef, undef, {name => '0', value => '0'}),
+ '',
+ 'input overrides'
);
is(
@@ -176,29 +196,209 @@ is(
# select
-is(
- $form->select,
- '', # malformed html: at least 1 option required
+is_deeply(
+ [ $form->select ],
+ [ qw() ], # malformed html: at least 1 option required
'empty select'
);
-is(
- $form->select(undef, [], '', {name => ''}),
- '',
+is_deeply(
+ [ $form->select(undef, [], '', {name => '', class => ''}) ],
+ [ qw() ],
'explicit empty select'
);
-is(
- $form->select(undef, [undef]),
- '',
+is_deeply(
+ [ $form->select(undef, [undef]) ],
+ [ qw() ],
'minimal select'
);
-is(
- $form->select(foo => [1..2]),
- '',
+is_deeply(
+ [ $form->select(foo => [1, 2]) ],
+ [
+ ''
+ ],
'select contents'
);
+is_deeply(
+ [ $form->select(foo => [1, 2], 3) ],
+ [
+ ''
+ ],
+ 'select invalid default'
+);
+
+is_deeply(
+ [ $form->select(undef, [1, 2], 2) ],
+ [
+ ''
+ ],
+ 'select default'
+);
+
+is_deeply(
+ [
+ $form->select(foo => [
+ '<">', {value => 2, disabled => 1, selected => 0, class => 1}, {selected => 1}
+ ], '2', {id => '', class => 'a 1})
+ ],
+ [
+ ''
+ ],
+ 'complex select'
+);
+
+is(
+ scalar $form->select(foo => [1, 2]),
+ '',
+ 'select scalar'
+);
+
+# radio
+
+is_deeply(
+ [ $form->select(foo => [1], {type => 'radio'}) ],
+ [ '' ],
+ 'input select'
+);
+
+is_deeply(
+ [
+ $form->select(foo => [
+ 1, {value => 2, name => '', label => ''}, {value => 3, id => '', type => ''}
+ ], {type => 'checkbox', label => {3 => 'test', 2 => 'ignore'}, value => '1'})
+ ],
+ [
+ '',
+ '',
+ '',
+ ],
+ 'input selects'
+);
+
+is(
+ $form->radio(foo => 'test'),
+ '',
+ 'radio method'
+);
+
+is(
+ $form->radio(foo => undef, 2),
+ '',
+ 'labelless radio'
+);
+
+is(
+ $form->radio(undef, {checked => 1}),
+ '',
+ 'simple radio button'
+);
+
+is_deeply(
+ [ $form->radio(undef, ['', '<">']) ],
+ [
+ '',
+ '',
+ ],
+ 'multiple radios'
+);
+
+is_deeply(
+ [ $form->radio(foo => 'test', ['foo', ''], {value => '', id => ''}) ],
+ [
+ '',
+ '',
+ ],
+ 'multiple radios with custom value'
+);
+
+is_deeply(
+ [ $form->radio(foo => ['', 0], [0, 1, '']) ],
+ [
+ '',
+ '',
+ '',
+ ],
+ 'multiple radios with custom values'
+);
+
+# check
+
+is(
+ $form->check('foo'),
+ '',
+ 'check method'
+);
+
+is(
+ $form->check(foo => '<">'),
+ '',
+ 'labeled checkbox'
+);
+
+is(
+ $form->check(foo => {label => 'test', value => undef}, {disabled => 1}),
+ '',
+ 'check parameters'
+);
+
+is_deeply(
+ [ $form->check(undef, '', 1) ],
+ [ '' ],
+ 'anonymous checkbox'
+);
+
+is_deeply(
+ [ $form->check(undef, ['', '<">']) ],
+ [
+ '',
+ '',
+ ],
+ 'multiple checkboxes'
+);
+
+is_deeply(
+ [ $form->check(undef, [{}, undef], 1) ],
+ [
+ '',
+ '',
+ ],
+ 'multiple checked checkboxes'
+);
+
+{
+ local $, = ' | ';
+ is(
+ scalar $form->check(foo => [1, 0], {value => 0}),
+ join(' | ',
+ '',
+ '',
+ ),
+ 'merged checkboxes'
+ );
+}
+
+is_deeply(
+ [ $form->check(undef, [{value => 4, type => 'radio'}], [1, 0, 0], {value => 3}) ],
+ [
+ '',
+ '',
+ '',
+ ],
+ 'various checkboxes'
+);
+
#TODO