File: select_optgroup.t

package info (click to toggle)
libhtml-formfu-perl 0.09007-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 4,184 kB
  • sloc: perl: 13,186; makefile: 9; sql: 5
file content (62 lines) | stat: -rw-r--r-- 1,582 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
use strict;
use warnings;

use Test::More tests => 3;

use HTML::FormFu;

my $form = HTML::FormFu->new({ tt_args => { INCLUDE_PATH => 'share/templates/tt/xhtml' } });

$form->element('Select')->name('foo')->value(2)->options( [
        { group => [ [ 1 => 'one' ], [ 2 => 'two' ] ] },
        {   group => [ [ foo2_1 => 'One' ], [ foo2_2 => 'Two' ] ],
            label => 'foo2',
        },
        [ x => 'non-opt' ],
        {   group => [
                { label => 'wun', value => 'foo3_1' },
                {   label      => 'too',
                    value      => 'foo3_2',
                    attributes => { class => 'foo3b' } }
            ],
            label      => 'foo3',
            attributes => { class => 'opt4' },
        },
    ] );

my $form_xhtml = <<EOF;
<form action="" method="post">
<div class="select">
<select name="foo">
<optgroup>
<option value="1">one</option>
<option value="2" selected="selected">two</option>
</optgroup>
<optgroup label="foo2">
<option value="foo2_1">One</option>
<option value="foo2_2">Two</option>
</optgroup>
<option value="x">non-opt</option>
<optgroup label="foo3" class="opt4">
<option value="foo3_1">wun</option>
<option value="foo3_2" class="foo3b">too</option>
</optgroup>
</select>
</div>
</form>
EOF

is( "$form", $form_xhtml, 'stringified form' );

# With mocked basic query
{
    $form->process( { foo => 'foo2_1', } );

    my $foo = $form->get_field('foo');

    like( "$foo", qr/value="foo2_1" selected="selected"/ );

    my $count = $foo =~ s/selected="selected"/selected="selected"/g;

    is( $count, 1 );
}