Commit | Line | Data |
abe0a338 |
1 | use strictures 1; |
2 | use Test::More; |
366d3dd1 |
3 | use Test::More; |
abe0a338 |
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 | |
366d3dd1 |
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 | |
ff52d017 |
49 | $z = HTML::Zoom->from_html($tmpl); |
50 | ($expect = $tmpl) =~ s/value="0" type="checkbox" name="input_check" /value="1" type="checkbox" name="input_check" selected="selected" /; |
366d3dd1 |
51 | |
52 | is( |
53 | $z->select('input[name="input_check"]')->val(1)->to_html, |
54 | $expect, |
55 | 'set value on input=checkbox' |
56 | ); |
abe0a338 |
57 | |
ff52d017 |
58 | ($expect = $tmpl) =~ s/value="1" type="checkbox" name="input_check" selected="selected" \>/value="0" type="checkbox" name="input_check" \>/; |
59 | |
60 | is( |
61 | $z->select('input[name="input_check"]')->val(0)->to_html, |
62 | $expect, |
63 | 'remove value on input=checkbox' |
64 | ); |
65 | |
66 | $z = HTML::Zoom->from_html($tmpl); |
67 | ($expect = $tmpl) =~ s/name="input_field" /name="input_field" value="testval" /; |
68 | |
69 | is( |
70 | $z->select('input')->val({input_field => "testval"})->to_html, |
71 | $expect, |
72 | 'alternate fill' |
73 | ); |
74 | |
75 | |
76 | SKIP: { |
77 | skip "not implemented",1; |
78 | $z = HTML::Zoom->from_html($tmpl); |
79 | ($expect = $tmpl) =~ s/option value="2" /option value="2" selected="selected" /; |
80 | |
81 | is( |
82 | $z->select('select[name="select_field"]')->val(2)->to_html, |
83 | $expect, |
84 | 'Set value on select' |
85 | ); |
86 | |
87 | } |
88 | |
89 | my %rules; |
90 | $z->select('form')->validate_form(\%rules)->to_html; |
91 | is(scalar keys %rules, 5, "Correctly extracted validation info"); |
abe0a338 |
92 | |
ff52d017 |
93 | done_testing(); |