|
Line 0
Link Here
|
| 0 |
- |
1 |
#!/usr/bin/perl |
|
|
2 |
|
| 3 |
# Copyright 2023 Rijksmuseum |
| 4 |
# |
| 5 |
# This file is part of Koha. |
| 6 |
# |
| 7 |
# Koha is free software; you can redistribute it and/or modify it |
| 8 |
# under the terms of the GNU General Public License as published by |
| 9 |
# the Free Software Foundation; either version 3 of the License, or |
| 10 |
# (at your option) any later version. |
| 11 |
# |
| 12 |
# Koha is distributed in the hope that it will be useful, but |
| 13 |
# WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 |
# GNU General Public License for more details. |
| 16 |
# |
| 17 |
# You should have received a copy of the GNU General Public License |
| 18 |
# along with Koha; if not, see <http://www.gnu.org/licenses>. |
| 19 |
|
| 20 |
use Modern::Perl; |
| 21 |
|
| 22 |
use Test::More tests => 1; |
| 23 |
use Test::Warn; |
| 24 |
use Try::Tiny; |
| 25 |
|
| 26 |
use Koha::Validator; |
| 27 |
|
| 28 |
subtest 'trivial tests' => sub { |
| 29 |
plan tests => 3; |
| 30 |
|
| 31 |
my $rules = { |
| 32 |
test01 => 'digits_only', |
| 33 |
test02 => [ 1, 2 ], |
| 34 |
test03 => sub { 0 }, |
| 35 |
test04 => 'email', |
| 36 |
test05 => qr/test/, |
| 37 |
}; |
| 38 |
my $validator = Koha::Validator->new( { rules => $rules } ); |
| 39 |
try { |
| 40 |
$validator->check_hash( |
| 41 |
{ test01 => 2, test02 => 1, test04 => 'marcel@test.nl', test05 => 'includes test word' } ); |
| 42 |
ok( 1, 'validator green' ); |
| 43 |
} catch { |
| 44 |
ok(0); |
| 45 |
}; |
| 46 |
try { |
| 47 |
$validator->check_hash( { test01 => 2, test02 => 1, test03 => 'nomatterwhat' } ); |
| 48 |
ok( 0, 'we should not be here' ); |
| 49 |
} catch { |
| 50 |
ok( 1, 'validator red' ); |
| 51 |
}; |
| 52 |
try { |
| 53 |
$validator->check_hash( { test04 => 'withbacktic`ls`@test.com' } ); |
| 54 |
ok( 0, 'we should not be here' ); |
| 55 |
} catch { |
| 56 |
ok( 1, 'validator red for email' ); |
| 57 |
}; |
| 58 |
}; |