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>.
20 use Test::More tests => 10;
29 use_ok('C4::Circulation');
32 my $dbh = C4::Context->dbh;
33 $dbh->{AutoCommit} = 0;
34 $dbh->{RaiseError} = 1;
36 $dbh->do(q|DELETE FROM issues|);
37 $dbh->do(q|DELETE FROM items|);
38 $dbh->do(q|DELETE FROM borrowers|);
39 $dbh->do(q|DELETE FROM branches|);
40 $dbh->do(q|DELETE FROM biblio|);
41 $dbh->do(q|DELETE FROM categories|);
45 Koha::Library->new({ branchcode => $branchcode, branchname => 'Branch' })->store;
47 my $categorycode = 'C';
48 $dbh->do("INSERT INTO categories(categorycode) VALUES(?)", undef, $categorycode);
50 my %item_branch_infos = (
51 homebranch => $branchcode,
52 holdingbranch => $branchcode,
55 my $barcode1 = '0101';
56 my $barcode2 = '0102';
57 my $barcode3 = '0203';
59 my $check_valid_barcode = C4::Circulation::CheckValidBarcode();
60 is( $check_valid_barcode, 0, 'CheckValidBarcode without barcode returns false' );
61 $check_valid_barcode = C4::Circulation::CheckValidBarcode($barcode1);
62 is( $check_valid_barcode, 0, 'CheckValidBarcode with an invalid barcode returns true' );
63 $check_valid_barcode = C4::Circulation::CheckValidBarcode($barcode2);
64 is( $check_valid_barcode, 0, 'CheckValidBarcode with an invalid barcode returns true' );
65 $check_valid_barcode = C4::Circulation::CheckValidBarcode($barcode3);
66 is( $check_valid_barcode, 0, 'CheckValidBarcode with an invalid barcode returns true' );
68 my ($biblionumber1) = AddBiblio(MARC::Record->new, '');
69 AddItem({ barcode => $barcode1, %item_branch_infos }, $biblionumber1);
70 AddItem({ barcode => $barcode2, %item_branch_infos }, $biblionumber1);
71 my ($biblionumber2) = AddBiblio(MARC::Record->new, '');
72 AddItem({ barcode => $barcode3, %item_branch_infos }, $biblionumber2);
74 $check_valid_barcode = C4::Circulation::CheckValidBarcode();
75 is( $check_valid_barcode, 0, 'CheckValidBarcode without barcode returns false' );
76 $check_valid_barcode = C4::Circulation::CheckValidBarcode($barcode1);
77 is( $check_valid_barcode, 1, 'CheckValidBarcode returns true' );
78 $check_valid_barcode = C4::Circulation::CheckValidBarcode($barcode2);
79 is( $check_valid_barcode, 1, 'CheckValidBarcode returns true' );
80 $check_valid_barcode = C4::Circulation::CheckValidBarcode($barcode3);
81 is( $check_valid_barcode, 1, 'CheckValidBarcode returns true' );
82 $check_valid_barcode = C4::Circulation::CheckValidBarcode('wrong barcode');
83 is( $check_valid_barcode, 0, 'CheckValidBarcode with an invalid barcode returns false' );