X-Git-Url: https://git.dogcows.com/gitweb?p=chaz%2Fp5-CGI-Ex;a=blobdiff_plain;f=t%2F1_validate_05_types.t;h=d45041f4ff891b3b465def7f109d7ca6869b3366;hp=224710759c4246bdfb3dfe11562ee9884b98f76c;hb=0b04f67c06c1db11969096f07dfc7dbb23bf99ba;hpb=490b94ab4051adf93abf16a4ed34efb923d6e8fc diff --git a/t/1_validate_05_types.t b/t/1_validate_05_types.t index 2247107..d45041f 100644 --- a/t/1_validate_05_types.t +++ b/t/1_validate_05_types.t @@ -7,7 +7,7 @@ =cut use strict; -use Test::More tests => 104; +use Test::More tests => 112; use_ok('CGI::Ex::Validate'); @@ -32,6 +32,27 @@ ok(! $e); $e = validate({bar => 1}, $v); ok($e); +$v = {text1 => {required => 1, validate_if => 'text2 was_valid'}, text2 => {validate_if => 'text3'}}; +$e = validate({}, $v); +ok(! $e, "Got no error on validate_if with was_valid"); +$e = validate({text2 => 1}, $v); +ok(! $e, "Got no error on validate_if with was_valid with non-validated data"); +$e = validate({text3 => 1}, $v); +ok(! $e, "Got no error on validate_if with was_valid with validated - bad data"); +$e = validate({text2 => 1, text3 => 1}, $v); +ok(! $e, "Got error on validate_if with was_valid with validated - good data"); +$e = validate({text1 => 1, text2 => 1, text3 => 1}, $v); +ok(! $e, "No error on validate_if with was_valid with validated - good data"); + +$v = {text1 => {required => 1, validate_if => 'text2 had_error'}, text2 => {required => 1}}; +$e = validate({}, $v); +ok($e, "Got error on validate_if with had_error"); +$e = validate({text2 => 1}, $v); +ok(! $e, "No error on validate_if with had_error and bad_data"); +$e = validate({text1 => 1}, $v); +ok($e && ! $e->as_hash->{text1_error}, "No error on validate_if with had_error and good data"); + + ### required_if $v = {foo => {required_if => 'bar'}}; $e = validate({}, $v);