XXX: hidden hash
[perl/html-form-simple.git] / t / html.t
index b7568b079cfa9ea14bfc9d0300c9d5d78009e008..3c6d8f4898b1284d9c061cf734535d95ca776dd3 100644 (file)
--- a/t/html.t
+++ b/t/html.t
@@ -5,7 +5,7 @@ use warnings;
 
 use Test::More;
 
-plan tests => 47;
+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'}),
+       '<input id="foo" name="foo" type="hidden" value="bar">',
+       'hidden options'
+);
+
+is_deeply(
+       [ $form->hidden({2 => 0, 10 => 1}, {class => 'test'}) ],
+       [
+               '<input class="test" name="10" type="hidden" value="1">',
+               '<input class="test" name="2" type="hidden" value="0">',
+       ],
+       'hidden hash'
+);
 
 # submit
 
@@ -282,7 +295,7 @@ is(
 );
 
 is(
-       $form->radio(foo => undef, [2]), #TODO
+       $form->radio(foo => undef, 2),
        '<input id="foo_2" name="foo" type="radio" value="2">',
        'labelless radio'
 );
@@ -330,28 +343,62 @@ is(
 );
 
 is(
-       $form->check(foo => 'test', {value => undef}),
-       '<label><input id="foo" name="foo" type="checkbox"> test</label>',
-       'check parameters'
+       $form->check(foo => '<">'),
+       '<label><input id="foo_1" name="foo" type="checkbox" value="1"> <"></label>',
+       'labeled checkbox'
 );
 
 is(
-       $form->check(undef, '', 1),
-       '<input checked type="checkbox" value="1">',
-       'simple checkbox'
+       $form->check(foo => {label => 'test', value => undef}, {disabled => 1}),
+       '<label><input disabled id="foo" name="foo" type="checkbox"> test</label>',
+       'check parameters'
+);
+
+is_deeply(
+       [ $form->check(undef, '', 1) ],
+       [ '<input checked type="checkbox" value="1">' ],
+       'anonymous checkbox'
 );
 
-TODO: {
-       local $TODO = 'shorthand';
 is_deeply(
        [ $form->check(undef, ['', '<">']) ],
        [
-               '<input checked type="checkbox" value="1">',
-               '<label><input checked type="checkbox" value="2"> &lt;&quot;></label>',
+               '<input type="checkbox" value="1">',
+               '<label><input type="checkbox" value="2"> <"></label>',
        ],
        'multiple checkboxes'
 );
-};
+
+is_deeply(
+       [ $form->check(undef, [{}, undef], 1) ],
+       [
+               '<input checked type="checkbox" value="1">',
+               '<input checked type="checkbox" value="2">',
+       ],
+       'multiple checked checkboxes'
+);
+
+{
+       local $, = ' | ';
+       is(
+               scalar $form->check(foo => [1, 0], {value => 0}),
+               join(' | ',
+                       '<label><input id="foo_1" name="foo" type="checkbox" value="1"> 1</label>',
+                       '<label><input id="foo_2" name="foo" type="checkbox" value="2"> 0</label>',
+               ),
+               'merged checkboxes'
+       );
+}
+
+is_deeply(
+       [ $form->check(undef, [{value => 4, type => 'radio'}], [1, 0, 0], {value => 3}) ],
+       [
+               '<input checked type="radio" value="4">',
+               '<input type="checkbox" value="2">',
+               '<input checked type="checkbox" value="3">',
+       ],
+       'various checkboxes'
+);
 
 #TODO