File: selectcsv.t

package info (click to toggle)
libhtml-formhandler-perl 0.40067-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 2,432 kB
  • ctags: 697
  • sloc: perl: 9,312; makefile: 2
file content (61 lines) | stat: -rw-r--r-- 1,451 bytes parent folder | download | duplicates (4)
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
use strict;
use warnings;
use Test::More;
use Test::Exception;

# tests the SelectCSV field
{
    package MyApp::Form::Test;
    use HTML::FormHandler::Moose;
    extends 'HTML::FormHandler';

    has_field 'foo' => ( type => 'SelectCSV' );
    sub options_foo {
       (
          1 => 'One',
          2 => 'Two',
       )
    }
    has_field 'bar' => ( type => 'SelectCSV' );
    sub options_bar {
       (
          1 => 'One',
          2 => 'Two',
       )
    }
    has_field 'box' => ( type => 'Select', multiple => 1 );
    sub options_box {
       (
          1 => 'One',
          2 => 'Two',
          3 => 'Three',
       )
    }

}

my $form = MyApp::Form::Test->new;
ok( $form );
my $init_obj = { foo => '1', bar => '1,2', box => [2] };

$form->process( init_object => $init_obj );
my $fif = $form->fif;
is_deeply( $fif, { foo => [1], bar => [1,2], box => [2] },
   'fif is correct' );

lives_ok( sub { $form->field('bar')->as_label }, 'as_label works with SelectCSV field' );

my $rendered = $form->render;
ok( $rendered, 'rendering worked' );

my $params = { bar => [2,1]  };
$form->process( $params );
lives_ok( sub { $form->field('bar')->as_label }, 'as_label works with SelectCSV field' );
$fif = $form->fif;
is_deeply( $fif, $params, 'fif ok' );
my $value = $form->value;
is_deeply( $value, { foo => undef, bar => '1,2', box => [] }, 'right value' );
$rendered = $form->render;
ok( $rendered, 'rendering worked' );

done_testing;