File: checkbox.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 (53 lines) | stat: -rw-r--r-- 1,330 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
use strict;
use warnings;

use Test::More tests => 6;

use HTML::FormFu;

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

my $foo = $form->element('Checkbox')->name('foo')->value('foox');

# add more elements to test accessor output
my $bar = $form->element('Checkbox')->name('bar')->value('barx');
my $moo
    = $form->element('Checkbox')->name('moo')->value('moox')->default('moox');
my $fad
    = $form->element('Checkbox')->name('fad')->value('fadx')->default('fadx');

my $field_xhtml = qq{<div class="checkbox">
<input name="foo" type="checkbox" value="foox" />
</div>};

is( "$foo", $field_xhtml, 'field xhtml' );

my $form_xhtml = <<EOF;
<form action="" method="post">
$field_xhtml
<div class="checkbox">
<input name="bar" type="checkbox" value="barx" />
</div>
<div class="checkbox">
<input name="moo" type="checkbox" value="moox" checked="checked" />
</div>
<div class="checkbox">
<input name="fad" type="checkbox" value="fadx" checked="checked" />
</div>
</form>
EOF

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

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

    like( "$foo", qr/checked/ );
    unlike( "$bar", qr/checked/ );
    like( "$moo", qr/checked/ );
    unlike( "$fad", qr/checked/ );
}