Bug 13089 - Tab key triggers JavaScript error in the checkEnter function
[koha.git] / t / SIP_Sip.t
1 #!/usr/bin/perl
2
3 # This file is part of Koha.
4 #
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.
9 #
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.
14 #
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>.
17
18 use Modern::Perl;
19
20 use Test::More tests => 9;
21 use Test::Warn;
22
23 BEGIN {
24         use FindBin;
25         use lib "$FindBin::Bin/../C4/SIP";
26         use_ok('C4::SIP::Sip');
27 }
28
29 my $date_time = Sip::timestamp();
30 like( $date_time, qr/^\d{8}    \d{6}$/, 'Timestamp format no param');
31
32 my $t = time();
33
34 $date_time = Sip::timestamp($t);
35 like( $date_time, qr/^\d{8}    \d{6}$/, 'Timestamp format secs');
36
37 $date_time = Sip::timestamp('2011-01-12');
38 ok( $date_time eq '20110112    235900', 'Timestamp iso date string');
39
40 my $myChecksum = Sip::Checksum::checksum("12345");
41 my $checker = 65281;
42 my $stringChecksum = Sip::Checksum::checksum("teststring");
43 my $stringChecker = 64425;
44
45 is( $myChecksum, $checker, "Checksum: $myChecksum matches expected output");
46 is( $stringChecksum, $stringChecker, "Checksum: $stringChecksum matches expected output");
47
48 my $testdata = "abcdAZ";
49 my $something = Sip::Checksum::checksum($testdata);
50
51 $something =  sprintf("%4X", $something);
52 ok( Sip::Checksum::verify_cksum($testdata.$something), "Checksum: $something is valid.");
53
54 my $invalidTest;
55 warning_is { $invalidTest = Sip::Checksum::verify_cksum("1234567") }
56             'verify_cksum: no sum detected',
57             'verify_cksum prints the expected warning for an invalid checksum';
58 is($invalidTest, 0, "Checksum: 1234567 is invalid as expected");
59
60 1;