Commit | Line | Data |
3bb32b1a |
1 | use strictures 1; |
2 | use Test::More; |
3 | |
4 | use HTML::Zoom; |
5 | |
6 | my $tmpl =<<END; |
7 | <body> |
8 | <form name="main"> |
9 | <label for="input_field">Input</label> |
10 | <input data-validate="required" type="text" name="input_field" /> |
11 | <label for="input_field2">Input 2</label> |
12 | <input data-validate="required" value="gorch" type="text" name="input_field2" /> |
13 | |
14 | <label for="input_check">Checkbox</label> |
15 | <input data-validate="required" value="0" type="checkbox" name="input_check" /> |
16 | |
17 | <label for="select_field">Select</label> |
18 | <select data-validate="required" name="select_field"> |
19 | <option value="1">foo</option> |
20 | <option value="2">bar</option> |
21 | <option value="3" selected="selected">oof</option> |
22 | <option value="4">rab</option> |
23 | </select> |
24 | </form> |
25 | </body> |
26 | END |
27 | |
28 | my $z = HTML::Zoom->from_html($tmpl); |
29 | |
30 | my @fields; |
31 | $z->select('input')->collect({ |
32 | into => \@fields, |
33 | passthrough => 1, |
34 | })->memoize; |
35 | is(scalar @fields,2,"correctly extracted all inputs"); |
36 | |
37 | my $expect; |
38 | |
39 | ($expect = $tmpl) =~ s#name="input_field" />#name="input_field" /><div>cluck</div>#; |
40 | |
41 | is( |
42 | $z->select('input[name="input_field"]') |
43 | ->add_after(\"<div>cluck</div>") |
44 | ->to_html, $expect, |
45 | "added after void"); |
46 | |
47 | ($expect = $tmpl) =~ s#Input</label>#Input</label><div>cluck</div>#; |
48 | |
49 | is( |
50 | $z->select('input[name="input_field"]') |
51 | ->add_before(\"<div>cluck</div>") |
52 | ->to_html, $expect, |
53 | "added before void"); |