File: 2_render_page_2.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 (48 lines) | stat: -rw-r--r-- 1,141 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
use strict;
use warnings;

use Test::More tests => 7;

use HTML::FormFu::MultiForm;
use Crypt::CBC ();
use Storable qw/ thaw /;
use YAML::XS qw/ LoadFile /;

my $yaml_file = 't/multiform/multiform.yml';

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

$multi->load_config_file($yaml_file);

$multi->process( {
        foo    => 'abc',
        submit => 'Submit',
    } );

ok( $multi->current_form->submitted_and_valid );

like( "$multi", qr|<input name="bar" type="text" />| );

# internals alert!
# decrypt the hidden value, and check it contains the expected data

my $form2 = $multi->next_form;

my $value = $form2->get_field( { name => $multi->default_multiform_hidden_name } )->default;

my $yaml = LoadFile($yaml_file);

my $cbc = Crypt::CBC->new( %{ $yaml->{crypt_args} } );

my $decrypted = $cbc->decrypt_hex($value);

my $data = thaw($decrypted);

is( $data->{current_form}, 2 );

ok( grep { $_ eq 'foo' } @{ $data->{valid_names} } );
ok( grep { $_ eq 'submit' } @{ $data->{valid_names} } );

is( $data->{params}{foo},    'abc' );
is( $data->{params}{submit}, 'Submit' );