extended select() support
[perl/html-form-simple.git] / t / html.t
index e023997831b20a951b6fd949dc55dbe0e2a4bb7e..d12d6ef8127ee73a16e2ba4c837dcab0b3616ccc 100644 (file)
--- a/t/html.t
+++ b/t/html.t
@@ -5,7 +5,7 @@ use warnings;
 
 use Test::More;
 
-plan tests => 31;
+plan tests => 43;
 
 use_ok('HTML::Form::Simple');
 
@@ -176,29 +176,139 @@ is(
 
 # select
 
-is(
-       $form->select,
-       '<select></select>', # malformed html: at least 1 option required
+is_deeply(
+       [ $form->select ],
+       [ qw(<select> </select>) ], # malformed html: at least 1 option required
        'empty select'
 );
 
-is(
-       $form->select(undef, [], '', {name => ''}),
-       '<select></select>',
+is_deeply(
+       [ $form->select(undef, [], '', {name => '', class => ''}) ],
+       [ qw(<select> </select>) ],
        'explicit empty select'
 );
 
-is(
-       $form->select(undef, [undef]),
-       '<select><option></select>',
+is_deeply(
+       [ $form->select(undef, [undef]) ],
+       [ qw(<select> <option> </select>) ],
        'minimal select'
 );
 
-is(
-       $form->select(foo => [1..2]),
-       '<select name="foo"><option value="1"><option value="2"></select>',
+is_deeply(
+       [ $form->select(foo => [1, 2]) ],
+       [
+               '<select id="foo" name="foo">',
+               '<option value="1">', '<option value="2">',
+               '</select>'
+       ],
        'select contents'
 );
 
+is_deeply(
+       [ $form->select(foo => [1, 2], 3) ],
+       [
+               '<select id="foo" name="foo">',
+               '<option value="1">', '<option value="2">',
+               '</select>'
+       ],
+       'select invalid default'
+);
+
+is_deeply(
+       [ $form->select(undef, [1, 2], 2) ],
+       [
+               '<select>',
+               '<option value="1">', '<option selected value="2">',
+               '</select>'
+       ],
+       'select default'
+);
+
+is_deeply(
+       [
+               $form->select(foo => [
+                       '<">', {value => 2, disabled => 1, selected => 0, class => 1}, {selected => 1}
+               ], '2', {id => '', class => 'a <b', value => 1})
+       ],
+       [
+               '<select class="a &lt;b" name="foo">',
+               '<option value="&lt;&quot;>">',
+               '<option selected disabled class="1" value="2">',
+               '<option selected>',
+               '</select>'
+       ],
+       'complex select'
+);
+
+is(
+       scalar $form->select(foo => [1, 2]),
+       '<select id="foo" name="foo"><option value="1"><option value="2"></select>',
+       'select scalar'
+);
+
+# radio
+
+is_deeply(
+       [ $form->select(foo => [1], {type => 'radio'}) ],
+       [ '<input id="foo_1" name="foo" type="radio" value="1">' ],
+       '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 checked id="foo_1" name="foo" type="checkbox" value="1">',
+               '<input id="foo_2" name="" type="checkbox" value="2">',
+               '<label><input name="foo" value="3"> test</label>',
+       ],
+       'input selects'
+);
+
+is(
+       $form->radio(foo => 1),
+       '<input id="foo_1" name="foo" type="radio" value="1">',
+       'radio method'
+);
+
+is(
+       $form->radio(undef, {checked => 1}),
+       '<input checked type="radio">',
+       'simple radio button'
+);
+
+is(
+       $form->check('foo'),
+       '<input id="foo_1" name="foo" type="checkbox" value="1">',
+       'check method'
+);
+
+is(
+       $form->check(foo => 'test', {value => undef}),
+       '<label><input id="foo" name="foo" type="checkbox"> test</label>',
+       'check parameters'
+);
+
+is(
+       $form->check(undef, '', 1),
+       '<input checked type="checkbox" value="1">',
+       'simple 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>',
+       ],
+       'multiple checkboxes'
+);
+};
+
 #TODO