1#!/usr/local/bin/perl
2
3use strict;
4use warnings;
5
6use Test::More;
7
8use HTML::FillInForm;
9use HTML::TokeParser;
10
11my $html = qq[<form><input type="text" name="one" value="all wrong"><input type="text" name="two" class="existing" value="worse"><input type="text" name="three" class="invalid" value="already bad"><select name="four"><option value="1">Foo</option><option value="2">Boo</option></select><textarea name="five"></textarea></form>];
12
13{
14    my $result =
15      HTML::FillInForm->new->fill(scalarref      => \$html,
16                                  fdat           => {two => "new val 2"},
17                                  invalid_fields => ['one']);
18    my $p = HTML::TokeParser->new(\$result);
19
20    my $one = $p->get_tag('input')->[1];
21
22    is($one->{name}, 'one');
23    is($one->{class}, 'invalid');
24
25    my $two       = $p->get_token->[2];
26    is($two->{name}, 'two');
27    isnt($two->{class},'invalid');
28}
29{
30    my $result = HTML::FillInForm->new->fill(scalarref      => \$html,
31                                          fdat           => {two => "new val 2"},
32                                          invalid_fields => ['one', 'two', 'three', 'four', 'five']);
33    my $p = HTML::TokeParser->new(\$result);
34
35    my $one       = $p->get_tag('input')->[1];
36    is($one->{name}, 'one');
37    is($one->{class}, 'invalid');
38
39    my $two       = $p->get_token->[2];
40    is($two->{name}, 'two');
41    is($two->{class},'existing invalid');
42
43    my $three     = $p->get_token->[2];
44    is($three->{name},'three');
45    is($three->{class},'invalid');
46
47    my $four      = $p->get_token->[2];
48    is($four->{name},  'four');
49    is($four->{class}, 'invalid');
50
51    my $five = $p->get_tag('textarea')->[1];
52
53    is($five->{name},'five');
54    is($five->{class},'invalid');
55}
56{
57    my $result = HTML::FillInForm->new->fill(scalarref      => \$html,
58                                          fdat           => {two => "new val 2"},
59                                          invalid_fields => ['one', 'three'],
60                                          invalid_class  => "funky");
61    my $p = HTML::TokeParser->new(\$result);
62
63    my $one       = $p->get_tag('input')->[1];
64    is($one->{name}, 'one');
65    is($one->{class}, 'funky');
66
67    my $two       = $p->get_token->[2];
68    is($two->{name}, 'two');
69    is($two->{class},'existing');
70
71    my $three     = $p->get_token->[2];
72    is($three->{name},'three');
73    is($three->{class},'invalid funky');
74}
75
76done_testing();
77