Debian Codegraph @

t/render/checkbox.t

raw
1 use strict;
2 use warnings;
3 use Test::More;
4 use HTML::FormHandler::Test;
5
6 {
7 {
8 package Test::Form;
9 use HTML::FormHandler::Moose;
10 extends 'HTML::FormHandler';
11
12 has_field 'option1' => ( type => 'Checkbox', do_label => 0 );
13 has_field 'option2' => ( type => 'Checkbox', do_label => 0, tags => { label_left => 1 } );
14 has_field 'option3' => ( type => 'Checkbox', option_label => 'Try this one' );
15 has_field 'option4' => ( type => 'Checkbox', tags => { no_wrapped_label => 1 } );
16 has_field 'option5' => ( type => 'Checkbox', widget_wrapper => 'None' );
17 has_field 'option6' => ( type => 'Checkbox', do_label => 0,
18 do_wrapper => 0, label => 'Simple Checkbox' );
19 }
20 my $form = Test::Form->new;
21 $form->process;
22
23 # single_label: label wraps input, label to right
24 my $expected =
25 '<div>
26 <label class="checkbox" for="option1"><input id="option1" name="option1" type="checkbox" value="1" /> Option1 </label>
27 </div>';
28 my $rendered = $form->field('option1')->render;
29 is_html( $rendered, $expected, 'standard Checkbox render ok' );
30
31 # single_label: label wraps input, label to left
32 $expected =
33 '<div>
34 <label class="checkbox" for="option2"> Option2 <input id="option2" name="option2" type="checkbox" value="1" /></label>
35 </div>';
36 $rendered = $form->field('option2')->render;
37 is_html( $rendered, $expected, 'Checkbox with label to left' );
38
39 # standard: checkbox with additional label (like Bootstrap)
40 $expected =
41 '<div>
42 <label for="option3">Option3</label>
43 <label class="checkbox" for="option3">
44 <input id="option3" name="option3" type="checkbox" value="1" />
45 Try this one
46 </label>
47 </div>';
48 $rendered = $form->field('option3')->render;
49 is_html( $rendered, $expected, 'Checkbox with two labels' );
50
51 # no wrapped label
52 $expected =
53 '<div>
54 <label for="option4">Option4</label>
55 <input id="option4" name="option4" type="checkbox" value="1" />
56 </div>';
57 $rendered = $form->field('option4')->render;
58 is_html( $rendered, $expected, 'Checkbox with no wrapped label');
59
60 # wrapper = 'None', input element only
61 $expected =
62 '<input id="option5" name="option5" type="checkbox" value="1" />';
63 $rendered = $form->field('option5')->render;
64 is_html( $rendered, $expected, 'Checkbox with no wrapper and no label' );
65
66 # no wrapper
67 $expected =
68 '<label class="checkbox" for="option6">
69 <input id="option6" name="option6" type="checkbox" value="1" />
70 Simple Checkbox
71 </label>';
72 $rendered = $form->field('option6')->render;
73 is_html( $rendered, $expected, 'checkbox with no wrapper, wrapped label' );
74
75 }
76
77 done_testing;