File: form-multi-select.t

package info (click to toggle)
libhtml-form-perl 6.12-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 352 kB
  • sloc: perl: 2,052; makefile: 2
file content (109 lines) | stat: -rw-r--r-- 2,705 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#!/usr/bin/perl

# Test for case when multiple forms are on a page with same-named <select> fields.

use strict;
use Test::More tests => 2;
use HTML::Form;

{
    my $test
        = "the settings of a previous form should not interfere with a latter form (control test with one form)";
    my @forms    = HTML::Form->parse( FakeResponse::One->new );
    my $cat_form = $forms[0];
    my @vals     = $cat_form->param('age');
    is_deeply( \@vals, [''], $test );
}
{
    my $test
        = "the settings of a previous form should not interfere with a latter form (test with two forms)";
    my @forms    = HTML::Form->parse( FakeResponse::TwoForms->new );
    my $cat_form = $forms[1];

    my @vals = $cat_form->param('age');
    is_deeply( \@vals, [''], $test );
}

####
package FakeResponse::One;

sub new {
    bless {}, shift;
}

sub base {
    return "http://foo.com";
}

sub content_charset {
    return "iso-8859-1";
}

sub decoded_content {
    my $html = qq{
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <title></title>
    </head>
    <body>

    <form name="search_cats">
    <select name="age" onChange="jumpTo(this)" class="sap-form-item">
    <option value="" selected="selected">Any</option>
    <option value="young">Young</option>
    <option value="adult">Adult</option>
    <option value="senior">Senior</option>
    <option value="puppy">Puppy </option>
    </select>
    </form>
    </body></html>
    };
    return \$html;
}

#####
package FakeResponse::TwoForms;

sub new {
    bless {}, shift;
}

sub base {
    return "http://foo.com";
}

sub decoded_content {
    my $html = qq{
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <title></title>
    </head>
    <body>
    <form name="search_dogs" >
    <select name="age" onChange="jumpTo(this)" class="sap-form-item">
    <option value="" selected="selected">Any</option>
    <option value="young">Young</option>
    <option value="adult">Adult</option>
    <option value="senior">Senior</option>
    <option value="puppy">Puppy </option>
    </select>
    </form>


    <form name="search_cats">
    <select name="age" onChange="jumpTo(this)" class="sap-form-item">
    <option value="" selected="selected">Any</option>
    <option value="young">Young</option>
    <option value="adult">Adult</option>
    <option value="senior">Senior</option>
    <option value="puppy">Puppy </option>
    </select>
    </form>
    </body></html>
    };
    return \$html;
}