File: 08-depends_on.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 (31 lines) | stat: -rw-r--r-- 590 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
use Test::More tests => 5;

package MyVal;
use Validation::Class;

package main;

my $r = MyVal->new(
    fields => {
        two => {
            label    => 'The Two',
            required => 1
        },
        one => {
            label      => 'The One',
            depends_on => 'two'
        }
    }
);

ok $r->validate('one'), 'one not required, pass';

$r->params->{one} = 1;    # flag

ok !$r->validate('one'), 'two is required';
ok $r->error_count == 1, 'error count ok';

$r->params->{two} = 2;

ok $r->validate('one'), 'validation ok';
ok !$r->error_count, 'error count ok';