recursive testing, fixup prereqs
[catagits/HTML-Zoom.git] / t / forms.t
1 use HTML::Zoom;
2 use Test::More;
3
4 my $zoom = HTML::Zoom->from_html(<<HTML);
5 <form class="myform" action="/somewhere">
6 <label />
7 <input />
8 </form>
9 HTML
10
11 my @fields = (
12     { id => "foo", label => "foo", name => "foo", type => "text", value => 0 },
13     { id => "bar", label => "bar", name => "bar", type => "radio", value => 1 },
14 );
15
16 my $h = $zoom->select('.myform')->repeat_content([
17     map { my $field = $_; sub {
18               $_->select('label')
19                ->add_to_attribute( for => $field->{id} )
20                ->then
21                ->replace_content( $field->{label} )
22                ->select('input')
23                ->add_to_attribute( name => $field->{name} )
24                ->then
25                ->add_to_attribute( type => $field->{type} )
26                ->then
27                ->add_to_attribute( value => $field->{value} )
28            } } @fields
29        ])->to_html;
30
31 is($h, q{<form class="myform" action="/somewhere">
32 <label for="foo">foo</label>
33 <input name="foo" type="text" value="0" />
34
35 <label for="bar">bar</label>
36 <input name="bar" type="radio" value="1" />
37 </form>
38 }, 'render all ok');
39
40 done_testing;