Bug 14364: Allow automatically canceled expired waiting holds to fill the next hold
[koha.git] / t / Circulation_barcodedecode.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 => 29;
21 use Test::Warn;
22
23 use C4::Context;
24 use t::lib::Mocks;
25
26 use_ok('C4::Circulation', qw( barcodedecode ));
27
28 t::lib::Mocks::mock_userenv({ branchcode => 'IMS' });
29
30 our %inputs = (
31     cuecat     => ["26002315", '.C3nZC3nZC3nYD3b6ENnZCNnY.fHmc.C3D1Dxr2C3nZE3n7.', ".C3nZC3nZC3nYD3b6ENnZCNnY.fHmc.C3D1Dxr2C3nZE3n7.\r\n",
32                     'q.C3nZC3nZC3nWDNzYDxf2CNnY.fHmc.C3DWC3nZCNjXD3nW.', '.C3nZC3nZC3nWCxjWE3D1C3nX.cGf2.ENr7C3v7D3T3ENj3C3zYDNnZ.' ],
33     whitespace => [" 26002315", "26002315 ", "\n\t26002315\n", "whitespace removed"],
34     'T-prefix' => [qw(T0031472 T32)],
35     'libsuite8' => ['b000126', 'b12', 'B0126', 'IMS-B-126', 'ims-b-126','CD0000024','00123','11998'],
36     EAN13      => [qw(892685001928 695152)],
37     other      => [qw(26002315 T0031472 T32 Alphanum123), "Alpha Num 345", " side spaces removed \n"],
38 );
39 our %outputs = (
40     cuecat     => ["26002315", "046675000808", "046675000808", "043000112403", "978068484914051500"],
41     whitespace => [qw(26002315 26002315 26002315 whitespaceremoved)],
42     'T-prefix' => [qw(T0031472 T0000002         )],
43     'libsuite8' => ['IMS-b-126', 'IMS-b-12', 'IMS-B-126', 'IMS-B-126', 'ims-b-126','IMS-CD-24','IMS-b-123','IMS-b-11998'],
44     EAN13      => [qw(0892685001928 0000000695152)],
45     other      => [qw(26002315 T0031472 T32 Alphanum123), "Alpha Num 345", "side spaces removed"],
46 );
47
48 my @filters = sort keys %inputs;
49 foreach my $filter (@filters) {
50     foreach my $datum (@{$inputs{$filter}}) {
51         my $expect = shift @{$outputs{$filter}}
52             or die "Internal Test Error: missing expected output for filter '$filter' on input '$datum'";
53         my $output = C4::Circulation::barcodedecode($datum, $filter);
54         ok($output eq $expect, sprintf("%12s: %20s => %15s", $filter, "'$datum'", "'$expect'")); 
55         ($output eq $expect) or diag  "Bad output: '$output'";
56     }
57 }
58
59 warnings_are
60     { C4::Circulation::barcodedecode(undef); }
61     [],
62     'No warnings with undef barcode';
63
64 # T-prefix style is derived from zero-padded "Follett Classic Code 3 of 9".  From:
65 #     www.fsc.follett.com/_file/File/pdf/Barcode%20Symbology%20Q%20%20A%203_05.pdf
66 #  ~ 1 to 7 characters
67 #  ~ T, P or X followed by numeric characters
68 #  ~ No checkdigit
69