File: condition_from_stash.t

package info (click to toggle)
libhtml-formfu-model-dbic-perl 0.09002-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 1,064 kB
  • sloc: perl: 2,270; makefile: 2
file content (67 lines) | stat: -rw-r--r-- 1,570 bytes parent folder | download | duplicates (6)
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
use strict;
use warnings;
use Test::More tests => 9;

use HTML::FormFu;
use lib 't/lib';
use DBICTestLib 'new_schema';
use MySchema;
my $form = HTML::FormFu->new;

$form->load_config_file('t/options_from_model/condition_from_stash.yml');

my $schema = new_schema();

$form->stash->{schema} = $schema;

my $master_rs = $schema->resultset('Master');
my $user_rs   = $schema->resultset('User');

{
    my $m1 = $master_rs->create({ text_col => 'foo' });

    $m1->create_related( 'user', { name => 'a' } );
    $m1->create_related( 'user', { name => 'b' } );
    $m1->create_related( 'user', { name => 'c' } );
}

{
    my $m2 = $master_rs->create({ text_col => 'bar' });

    $m2->create_related( 'user', { name => 'd' } );
    $m2->create_related( 'user', { name => 'e' } );
    $m2->create_related( 'user', { name => 'f' } );
    $m2->create_related( 'user', { name => 'g' } );

    $form->stash->{master_id} = $m2->id;
}

$form->process;

{
    my $option = $form->get_field('user')->options;

    ok( @$option == 4 );

    is( $option->[0]->{label}, 'd' );
    is( $option->[1]->{label}, 'e' );
    is( $option->[2]->{label}, 'f' );
    is( $option->[3]->{label}, 'g' );
}

$form = HTML::FormFu->new;
$form->load_config_file('t/options_from_model/condition_from_stash.yml');
$form->stash->{schema} = $schema;
$form->stash->{master_id} = {'!=' => '2' };
$form->process;

{
    my $option = $form->get_field('user')->options;

    ok( @$option == 3 );

    is( $option->[0]->{label}, 'a' );
    is( $option->[1]->{label}, 'b' );
    is( $option->[2]->{label}, 'c' );
}