X-Git-Url: http://git.shiar.nl/perl/html-form-simple.git/blobdiff_plain/be81b5d559a8ed87ee6493f27b698343fada60c4..d74d61d638a9f0c83f3860de02225c16309ccf2d:/t/html.t diff --git a/t/html.t b/t/html.t index d12d6ef..3c6d8f4 100644 --- a/t/html.t +++ b/t/html.t @@ -5,7 +5,7 @@ use warnings; use Test::More; -plan tests => 43; +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( @@ -269,17 +289,53 @@ is_deeply( ); is( - $form->radio(foo => 1), - '', + $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'), '', @@ -287,28 +343,62 @@ is( ); is( - $form->check(foo => 'test', {value => undef}), - '', - 'check parameters' + $form->check(foo => '<">'), + '', + 'labeled checkbox' ); is( - $form->check(undef, '', 1), - '', - 'simple checkbox' + $form->check(foo => {label => 'test', value => undef}, {disabled => 1}), + '', + 'check parameters' +); + +is_deeply( + [ $form->check(undef, '', 1) ], + [ '' ], + 'anonymous checkbox' ); -TODO: { - local $TODO = 'shorthand'; 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