d19f7288a49efeeeac759aad2790f8f45c3660a3
[catagits/HTML-Zoom.git] / t / form_helpers.t
1 use strictures 1;
2 use Test::More;
3 use Test::More;
4
5 use HTML::Zoom;
6
7 my $tmpl =<<END;
8 <body>
9   <form name="main">
10     <label for="input_field">Input</label>
11     <input data-validate="required" type="text" name="input_field" />
12     <label for="input_field2">Input 2</label>
13     <input data-validate="required" value="gorch" type="text" name="input_field2" />
14
15     <label for="input_check">Checkbox</label>
16     <input data-validate="required" value="0" type="checkbox" name="input_check" />
17
18     <label for="select_field">Select</label>
19     <select data-validate="required" name="select_field">
20       <option value="1">foo</option>
21       <option value="2">bar</option>
22       <option value="3" selected="selected">oof</option>
23       <option value="4">rab</option>
24     </select>
25     <label for="select_field">Select 2</label>
26     <select data-validate="required" name="select_field2">
27       <option value="1">foo</option>
28       <option value="2">bar</option>
29       <option value="3">oof</option>
30       <option value="4">rab</option>
31     </select>
32
33   </form>
34 </body>
35 END
36
37 my $z = HTML::Zoom->from_html($tmpl);
38
39 my ($expect);
40
41 ($expect = $tmpl) =~ s/name="input_field" /name="input_field" value="testval" /;
42
43 is(
44   $z->select('input[name="input_field"]')->val('testval')->to_html,
45   $expect,
46   'set value on input=text'
47 );
48
49 ($expect = $tmpl) =~ s/name="input_field" /name="input_field" value="testval" /;
50
51 is(
52   $z->select('input[name="input_check"]')->val(1)->to_html,
53   $expect,
54   'set value on input=checkbox'
55 );
56
57 # my %rules;
58 # my $validate_and_fill = sub {
59 #  $_ = $_->set_attribute("test" => "test");
60 #  #use Devel::Dwarn;Dwarn \@_;
61 #  $_;
62 # };
63
64 # print $z->select('form')->validate_form(\%rules, {input_field => "Test", input_field2 => "Moo"})->to_html;
65 # use Devel::Dwarn;Dwarn \%rules;
66