Bug 15597: Typo in opac-auth-detail.tt
[koha.git] / t / SIP_Sip.t
blobf6702779d7a6e90a3e4a7f25c0db6ed382f931f2
1 #!/usr/bin/perl
3 # This file is part of Koha.
5 # Koha is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
10 # Koha is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with Koha; if not, see <http://www.gnu.org/licenses>.
18 use Modern::Perl;
20 use Test::More tests => 9;
21 use Test::Warn;
23 BEGIN {
24 use_ok('C4::SIP::Sip');
27 my $date_time = C4::SIP::Sip::timestamp();
28 like( $date_time, qr/^\d{8} \d{6}$/, 'Timestamp format no param');
30 my $t = time();
32 $date_time = C4::SIP::Sip::timestamp($t);
33 like( $date_time, qr/^\d{8} \d{6}$/, 'Timestamp format secs');
35 $date_time = C4::SIP::Sip::timestamp('2011-01-12');
36 ok( $date_time eq '20110112 235900', 'Timestamp iso date string');
38 my $myChecksum = C4::SIP::Sip::Checksum::checksum("12345");
39 my $checker = 65281;
40 my $stringChecksum = C4::SIP::Sip::Checksum::checksum("teststring");
41 my $stringChecker = 64425;
43 is( $myChecksum, $checker, "Checksum: $myChecksum matches expected output");
44 is( $stringChecksum, $stringChecker, "Checksum: $stringChecksum matches expected output");
46 my $testdata = "abcdAZ";
47 my $something = C4::SIP::Sip::Checksum::checksum($testdata);
49 $something = sprintf("%4X", $something);
50 ok( C4::SIP::Sip::Checksum::verify_cksum($testdata.$something), "Checksum: $something is valid.");
52 my $invalidTest;
53 warning_is { $invalidTest = C4::SIP::Sip::Checksum::verify_cksum("1234567") }
54 'verify_cksum: no sum detected',
55 'verify_cksum prints the expected warning for an invalid checksum';
56 is($invalidTest, 0, "Checksum: 1234567 is invalid as expected");