Bug 10515: add regression tests
[koha.git] / t / db_dependent / Branch.t
1 #!/usr/bin/perl
2
3 # Copyright 2013 Equinox Software, Inc.
4 #
5 # This file is part of Koha.
6 #
7 # Koha is free software; you can redistribute it and/or modify it under the
8 # terms of the GNU General Public License as published by the Free Software
9 # Foundation; either version 3 of the License, or (at your option) any later
10 # version.
11 #
12 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License along
17 # with Koha; if not, see <http://www.gnu.org/licenses>.
18
19 use Modern::Perl;
20
21 use C4::Context;
22 use Data::Dumper;
23
24 use Test::More tests => 6;
25
26 use C4::Branch;
27
28 BEGIN {
29     use FindBin;
30     use lib $FindBin::Bin;
31     use_ok('C4::Branch');
32 }
33
34 # Start transaction
35 my $dbh = C4::Context->dbh;
36 $dbh->{AutoCommit} = 0;
37 $dbh->{RaiseError} = 1;
38
39 # clear the slate
40 $dbh->do('DELETE FROM branchcategories');
41
42 my @category_types = GetCategoryTypes();
43 is_deeply(\@category_types, [ 'searchdomain', 'properties' ], 'received expected library category types');
44
45 my %new_category = (
46     categorycode     => 'LIBCATCODE',
47     categoryname     => 'library category name',
48     codedescription  => 'library category code description',
49     categorytype     => 'searchdomain',
50     show_in_pulldown => 1,
51 );
52 ModBranchCategoryInfo({
53     add => 1,
54     %new_category,
55 });
56
57 my $category = GetBranchCategory('LIBCATCODE');
58 is_deeply($category, \%new_category, 'fetched newly added library category');
59
60 $category = GetBranchCategory();
61 is($category, undef, 'retrieve library category only if code is supplied (bug 10515)');
62
63 my $categories = GetBranchCategories();
64 is_deeply($categories, [ \%new_category ], 'retrieve all expected library categories (bug 10515)');
65
66 $categories = GetBranchCategories(undef, undef, 'LIBCATCODE');
67 is_deeply($categories, [ { %new_category, selected => 1 } ], 'retrieve expected, eselected library category (bug 10515)');
68
69 $dbh->rollback();