From: Mischa POSLAWSKY Date: Wed, 3 Sep 2008 23:15:08 +0000 (+0000) Subject: XXX: check() id-related improvements + tests X-Git-Url: http://git.shiar.net/perl/html-form-simple.git/commitdiff_plain/b54221df138e749a5c2fda079ea4d6241a278a7d XXX: check() id-related improvements + tests --- diff --git a/lib/HTML/Form/Simple.pm b/lib/HTML/Form/Simple.pm index 58e8753..f96149f 100644 --- a/lib/HTML/Form/Simple.pm +++ b/lib/HTML/Form/Simple.pm @@ -213,6 +213,8 @@ sub check { } } exists $rows->[$_]->{value} or $rows->[$_]->{value} = $_ + 1 for 0 .. $#$rows; + $rows->[0]->{id} = $attr->{id} || $rows->[0]->{name} || $attr->{name} || $name #XXX: // + if ref $label ne 'ARRAY' and defined $rows->[0] and not defined $rows->[0]->{id}; $self->select($name, $rows, {%$attr, type => 'checkbox'}); } diff --git a/t/html.t b/t/html.t index 757b248..166ab11 100644 --- a/t/html.t +++ b/t/html.t @@ -5,7 +5,7 @@ use warnings; use Test::More; -plan tests => 66; +plan tests => 68; use_ok('HTML::Form::Simple'); @@ -402,13 +402,13 @@ is_deeply( is( $form->check('foo'), - '', + '', 'check method' ); is( $form->check(foo => '<">'), - '', + '', 'labeled checkbox' ); @@ -424,13 +424,57 @@ is_deeply( 'anonymous checkbox' ); +is( + $form->check(foo => [undef]), + '', + 'multipart check' +); + +is_deeply( + [ $form->check(foo => [{value => undef}, undef]) ], + [ + '', + '', + ], + 'multiple checkboxes' +); + +is( + $form->check(foo => [undef], {id => ''}), + '', + 'idless checks' +); + +is_deeply( + [ $form->check( + foo => [ {id => 'quux'}, {name => 'name'}, {value => 0}, {id => ''}, undef ], {id => 'bar'} + ) ], + [ + '', + '', + '', + '', + '', + ], + 'check overrides' +); + +is_deeply( + [ $form->check(foo => ['bar', {name => 'bar'}], {name => 'ignored'}) ], + [ + '', + '', + ], + 'checkbox names' +); + is_deeply( [ $form->check(undef, ['', '<">']) ], [ '', '', ], - 'multiple checkboxes' + 'anonymous checkboxes' ); is_deeply(