Bug 9259: Use is instead of is_deeply
[koha.git] / t / db_dependent / Circulation / CheckValidBarcode.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 => 10;
21
22 use C4::Circulation;
23 use C4::Biblio;
24 use C4::Items;
25 use Koha::Library;
26
27
28 BEGIN {
29     use_ok('C4::Circulation');
30 }
31
32 my $dbh = C4::Context->dbh;
33 $dbh->{AutoCommit} = 0;
34 $dbh->{RaiseError} = 1;
35
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|);
42
43
44 my $branchcode = 'B';
45 Koha::Library->new({ branchcode => $branchcode, branchname => 'Branch' })->store;
46
47 my $categorycode = 'C';
48 $dbh->do("INSERT INTO categories(categorycode) VALUES(?)", undef, $categorycode);
49
50 my %item_branch_infos = (
51     homebranch => $branchcode,
52     holdingbranch => $branchcode,
53 );
54
55 my $barcode1 = '0101';
56 my $barcode2 = '0102';
57 my $barcode3 = '0203';
58
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' );
67
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);
73
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' );
84
85 $dbh->rollback();
86
87 1;