Koha/t/Circulation_barcodedecode.t
Dobrica Pavlinusic 089b1151f5 Bug 6448 [1/3] EAN-13/UPC-A itemBarcodeInputFilter
This filter which check validity of EAN-13 barcode and padd it with zeros
up to full 13 digit number. This will also expand 12 digit UPC-A barcodes
to EAN-13 automatically which is useful for older barcode readers which tend
to ignore first zero in EAN-13 if they have just UPC-A support.

It should be noted that EAN-13 or UPC-A product codes printed on books are not
good choice for barcodes in Koha since each item has to have unique barcode.

Test scenario:

1. prove t/Circulation_barcodedecode.t
   this checks expansion of 12 digit UPC-A to 13 digit EAN-13 and zero padding

2. in systempreferences search for itemBarcodeInputFilter and select EAN-13

3. edit one item and assign it valid EAN-13 barcode, eg. 0000000695152, check it out

4. test checkin with just 695152 to test leading zero expansion

Signed-off-by: Chris Cormack <chris@bigballofwax.co.nz>
2012-08-02 18:41:40 +02:00

57 lines
2.2 KiB
Perl

#!/usr/bin/perl
#
use strict;
use warnings;
use Test::More tests => 26;
C4::Context->_new_userenv(123456);
C4::Context->set_userenv(1,'kmkale' , 1, 'kk1' , 'IMS', 0, 'kmkale@anantcorp.com');
BEGIN {
use_ok('C4::Circulation');
}
our %inputs = (
cuecat => ["26002315", '.C3nZC3nZC3nYD3b6ENnZCNnY.fHmc.C3D1Dxr2C3nZE3n7.', ".C3nZC3nZC3nYD3b6ENnZCNnY.fHmc.C3D1Dxr2C3nZE3n7.\r\n",
'q.C3nZC3nZC3nWDNzYDxf2CNnY.fHmc.C3DWC3nZCNjXD3nW.', '.C3nZC3nZC3nWCxjWE3D1C3nX.cGf2.ENr7C3v7D3T3ENj3C3zYDNnZ.' ],
whitespace => [" 26002315", "26002315 ", "\n\t26002315\n"],
'T-prefix' => [qw(T0031472 T32)],
'libsuite8' => ['b000126', 'b12', 'B0126', 'IMS-B-126', 'ims-b-126','CD0000024','00123','11998'],
EAN13 => [qw(892685001928 695152)],
other => [qw(26002315 T0031472 T32 Alphanum123), "Alpha Num 345"],
);
our %outputs = (
cuecat => ["26002315", "046675000808", "046675000808", "043000112403", "978068484914051500"],
whitespace => [qw(26002315 26002315 26002315)],
'T-prefix' => [qw(T0031472 T0000002 )],
'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'],
EAN13 => [qw(0892685001928 0000000695152)],
other => [qw(26002315 T0031472 T32 Alphanum123), "Alpha Num 345"],
);
my @filters = sort keys %inputs;
foreach my $filter (@filters) {
foreach my $datum (@{$inputs{$filter}}) {
my $expect = shift @{$outputs{$filter}} or die "Internal Test Error: missing expected output for filter '$filter' on input '$datum'";
my $output = C4::Circulation::barcodedecode($datum, $filter);
ok($output eq $expect, sprintf("%12s: %20s => %15s", $filter, "'$datum'", "'$expect'"));
($output eq $expect) or diag "Bad output: '$output'";
}
}
__END__
=head2 C4::Circulation::barcodedecode()
This tests avoids being dependent on the database by using the optional
second argument to barcodedecode.
T-prefix style is derived from zero-padded "Follett Classic Code 3 of 9". From:
www.fsc.follett.com/_file/File/pdf/Barcode%20Symbology%20Q%20%20A%203_05.pdf
~ 1 to 7 characters
~ T, P or X followed by numeric characters
~ No checkdigit
=cut