X-Git-Url: http://git.shiar.net/gitweb.cgi/perl/html-form-simple.git/blobdiff_plain/be81b5d559a8ed87ee6493f27b698343fada60c4..2ee16ffeffbdd0998c60f36a976169789e3c8e27:/t/html.t?ds=inline
diff --git a/t/html.t b/t/html.t
index d12d6ef..a9ee150 100644
--- a/t/html.t
+++ b/t/html.t
@@ -5,7 +5,7 @@ use warnings;
use Test::More;
-plan tests => 43;
+plan tests => 55;
use_ok('HTML::Form::Simple');
@@ -52,7 +52,42 @@ is(
'hidden'
);
-#TODO: hidden options
+is(
+ $form->hidden(undef, undef, {value => 'bar', name => 'foo', id => 'foo'}),
+ '',
+ 'hidden options'
+);
+
+is_deeply(
+ [ $form->hidden(foo => [1, 0], {class => 'test'}) ],
+ [
+ '',
+ '',
+ ],
+ 'hidden array'
+);
+
+is_deeply(
+ [ $form->hidden({2 => 0, 10 => 1}, {class => 'test'}) ],
+ [
+ '',
+ '',
+ ],
+ 'hidden hash'
+);
+
+{
+ local $, = "\n";
+ is(
+ scalar $form->hidden({2 => [1, 0], 10 => 2}, {class => 'test'}),
+ join("\n",
+ '',
+ '',
+ '',
+ ),
+ 'scalar hiddens'
+ );
+}
# submit
@@ -119,15 +154,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 +311,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 +365,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