File: 21-filtering-behavior.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 (80 lines) | stat: -rw-r--r-- 2,359 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
76
77
78
79
80
use Test::More tests => 12;

# begin
package MyVal;
use Validation::Class;

package main;

my $dpre = MyVal->new(
    fields => {foobar => {filters => 'alphanumeric'}},
    params => {foobar => '1@%23abc45@%#@#%6d666ef..'}
);

ok $dpre->params->{foobar} =~ /^123abc456d666ef$/, 'default pre-filtering ok';

my $pre = MyVal->new(
    fields    => {foobar => {filters => 'alphanumeric'}},
    params    => {foobar => '1@%23abc45@%#@#%6d666ef..'},
    filtering => 'pre'
);

ok $pre->params->{foobar} =~ /^123abc456d666ef$/, 'explicit pre-filtering ok';

my $post = MyVal->new(
    fields    => {foobar => {filters => 'alphanumeric'}},
    params    => {foobar => '1@%23abc45@%#@#%6d666ef..'},
    filtering => 'post'
);

ok $post->params->{foobar} =~ /^1@%23abc45@%#@#%6d666ef\.\.$/,
  'explicit post-filtering ok';

$post->validate;
ok $post->params->{foobar} =~ /^123abc456d666ef$/,
  'explicit post-filtering after validate ok';

my $nope = MyVal->new(
    fields    => {foobar => {filters => 'alphanumeric'}},
    params    => {foobar => '1@%23abc45@%#@#%6d666ef..'},
    filtering => 'off'
);

ok $nope->params->{foobar} =~ /^1@%23abc45@%#@#%6d666ef\.\.$/,
  'explicit no-filtering ok';

$nope->validate;
ok $nope->params->{foobar} =~ /^1@%23abc45@%#@#%6d666ef\.\.$/,
  'explicit no-filtering after validate ok';

$nope = MyVal->new(
    fields    => {foobar => {filters => 'alphanumeric'}},
    params    => {foobar => '1@%23abc45@%#@#%6d666ef..'},
    filtering => 'manual'
);

ok $nope->params->{foobar} =~ /^1@%23abc45@%#@#%6d666ef\.\.$/,
  'explicit no pre/post filtering ok';

$nope->validate;

ok $nope->params->{foobar} =~ /^1@%23abc45@%#@#%6d666ef\.\.$/,
  'explicit no-filtering after validate ok';

# ok $nope->apply_filters('manual'), 'applying filters manually'; - DEPRECATED
ok $nope->proto->apply_filters('manual'), 'applying filters manually';
ok $nope->params->{foobar} =~ /^123abc456d666ef$/,
  'filtering applied manually';

$nope = MyVal->new(
    fields    => {foobar => {filters => 'alphanumeric'}},
    params    => {foobar => '1@%23abc45@%#@#%6d666ef..'},
    filtering => 'pre'
);

ok $nope->filtering('pre'), 'changing filtering behavior: pre';

$nope->fields->{foobar}->{pattern} = qr/^\d{3}\w{3}\d{3}\w\d{3}\w{2}$/;
$nope->params->{foobar} = '1@%23abc45@%#@#%6d666ef..';

ok $nope->validate, 'pre-filtering allowed validation';