File: 97-persistent-values.t

package info (click to toggle)
libvalidation-class-perl 7.900057-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 1,572 kB
  • ctags: 355
  • sloc: perl: 21,493; makefile: 2
file content (75 lines) | stat: -rw-r--r-- 1,506 bytes parent folder | download | duplicates (5)
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
use Test::More tests => 6;

package MyVal;
use Validation::Class;

field this => {
    required => 1,
    error    => 'This aint that.',
    filters  => ['trim', 'strip']
};

field that => {
    required => 1,
    error    => 'That aint this.',
    filters  => ['trim', 'strip']
};

sub my_fields {
    my $fields = {

        this => {
            required => 1,
            error    => 'This aint that.',
            filters  => ['trim', 'strip']
        },

        that => {
            required => 1,
            error    => 'That aint this.',
            filters  => ['trim', 'strip']
        }
    };
    return $fields;
}

my $first_params = {
    this => '0123456789',
    that => ''
};

my $second_params = {
    this => '',
    that => ''
};

package main;

my $v1 = MyVal->new(

    #fields => my_fields,
    params         => $first_params,
    ignore_unknown => 1
);

# validation objects
ok $v1, '1st validation object ok';
$v1->validate(qw/this that/);
ok $v1->fields->{this}->{value} eq '0123456789',
  '1st validation object -this- field value correct';

my $v2 = MyVal->new(

    #fields => my_fields,
    params         => $second_params,
    ignore_unknown => 1
);

ok $v2, '2nd validation object ok';
$v2->validate(qw/this that/);
ok $v2->fields->{this}->{value} eq '',
  '2nd validation object -this- field value correct';

ok !$v2->params->{this}, '2nd validation object -this- param correct';
ok !$v2->fields->{this}->{value},
  '2nd validation object -this- field value correct';