File: radiogroup_subgroup.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 (85 lines) | stat: -rw-r--r-- 2,039 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
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('Radiogroup')->name('foo')->default(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' },
                    container_attributes => { class => 'item foo3_2' },
                },
            ],
            label      => 'foo3',
            attributes => { class => 'opt4' },
        },
    ] );

my $expected_form_xhtml = <<EOF;
<form action="" method="post">
<fieldset class="radiogroup">
<span>
<span class="subgroup">
<span>
<input name="foo" type="radio" value="1" />
<label>one</label>
</span>
<span>
<input name="foo" type="radio" value="2" checked="checked" />
<label>two</label>
</span>
</span>
<span class="subgroup">
<span>
<input name="foo" type="radio" value="foo2_1" />
<label>One</label>
</span>
<span>
<input name="foo" type="radio" value="foo2_2" />
<label>Two</label>
</span>
</span>
<span>
<input name="foo" type="radio" value="x" />
<label>non-opt</label>
</span>
<span class="opt4 subgroup">
<span>
<input name="foo" type="radio" value="foo3_1" />
<label>wun</label>
</span>
<span class="item foo3_2">
<input name="foo" type="radio" value="foo3_2" class="foo3b" />
<label>too</label>
</span>
</span>
</span>
</fieldset>
</form>
EOF

is( "$form", $expected_form_xhtml );

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

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

    like( "$xml", qr/value="foo3_1" checked="checked"/ );

    my $count = $xml =~ s/checked="checked"/checked="checked"/g;

    is( $count, 1 );
}