3 # Copyright 2013 Equinox Software, Inc.
5 # This file is part of Koha.
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
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.
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>.
24 use Test::More tests => 21;
28 use Koha::LibraryCategories;
32 use lib $FindBin::Bin;
50 my $dbh = C4::Context->dbh;
51 $dbh->{AutoCommit} = 0;
52 $dbh->{RaiseError} = 1;
55 $dbh->do('DELETE FROM branchcategories');
59 my $count = Koha::Libraries->search->count;
60 like( $count, '/^\d+$/', "the count is a number" );
66 branchname => 'BranchA',
67 branchaddress1 => 'adr1A',
68 branchaddress2 => 'adr2A',
69 branchaddress3 => 'adr3A',
71 branchcity => 'cityA',
72 branchstate => 'stateA',
73 branchcountry => 'countryA',
74 branchphone => 'phoneA',
76 branchemail => 'emailA',
77 branchreplyto => 'emailreply',
78 branchreturnpath => 'branchreturn',
81 branchprinter => undef,
82 branchnotes => 'noteA',
87 branchname => 'BranchB',
88 branchaddress1 => 'adr1B',
89 branchaddress2 => 'adr2B',
90 branchaddress3 => 'adr3B',
92 branchcity => 'cityB',
93 branchstate => 'stateB',
94 branchcountry => 'countryB',
95 branchphone => 'phoneB',
97 branchemail => 'emailB',
98 branchreplyto => 'emailreply',
99 branchreturnpath => 'branchreturn',
102 branchprinter => undef,
103 branchnotes => 'noteB',
104 opac_info => 'opacB',
107 is( ModBranch($b2), undef, 'the field add is missing' );
111 is( Koha::Libraries->search->count, $count + 2, "two branches added" );
113 is( Koha::Libraries->find( $b2->{branchcode} )->delete, 1, "One row affected" );
114 is( Koha::Libraries->search->count, $count + 1, "branch BRB deleted" );
117 is( GetBranchName( $b1->{branchcode} ),
118 $b1->{branchname}, "GetBranchName returns the right name" );
120 #Test GetBranchDetail
121 my $branchdetail = GetBranchDetail( $b1->{branchcode} );
122 $branchdetail->{add} = 1;
123 $b1->{issuing} = undef; # Not used in DB
124 is_deeply( $branchdetail, $b1, 'branchdetail is right' );
127 my $branches = GetBranches();
128 is( scalar( keys %$branches ),
129 Koha::Libraries->search->count, "GetBranches returns the right number of branches" );
135 branchname => 'BranchA modified',
136 branchaddress1 => 'adr1A modified',
137 branchaddress2 => 'adr2A modified',
138 branchaddress3 => 'adr3A modified',
139 branchzip => 'zipA modified',
140 branchcity => 'cityA modified',
141 branchstate => 'stateA modified',
142 branchcountry => 'countryA modified',
143 branchphone => 'phoneA modified',
144 branchfax => 'faxA modified',
145 branchemail => 'emailA modified',
146 branchreplyto => 'emailreply modified',
147 branchreturnpath => 'branchreturn modified',
148 branchurl => 'urlA modified',
149 branchip => 'ipA modified',
150 branchprinter => undef,
151 branchnotes => 'notesA modified',
152 opac_info => 'opacA modified'
156 is( Koha::Libraries->search->count, $count + 1,
157 "A branch has been modified, no new branch added" );
158 $branchdetail = GetBranchDetail( $b1->{branchcode} );
159 $b1->{issuing} = undef;
160 is_deeply( $branchdetail, $b1 , "GetBranchDetail gives the details of BRA");
163 my $count_cat = Koha::LibraryCategories->search->count;
166 categorycode => 'CAT1',
167 categoryname => 'catname1',
168 codedescription => 'catdesc1',
169 categorytype => 'cattype1',
170 show_in_pulldown => 1
173 categorycode => 'CAT2',
174 categoryname => 'catname2',
175 categorytype => 'catype2',
176 codedescription => 'catdesc2',
177 show_in_pulldown => 1
181 categorycode => 'LIBCATCODE',
182 categoryname => 'library category name',
183 codedescription => 'library category code description',
184 categorytype => 'searchdomain',
185 show_in_pulldown => 1,
188 Koha::LibraryCategory->new(\%new_category)->store;
189 Koha::LibraryCategory->new($cat1)->store;
190 Koha::LibraryCategory->new($cat2)->store;
192 my $categories = Koha::LibraryCategories->search;
193 is( $categories->count, $count_cat + 3, "Two categories added" );
195 my $del = Koha::LibraryCategories->find( $cat2->{categorycode} )->delete;
196 is( $del, 1, 'One row affected' );
198 is( Koha::LibraryCategories->search->count, $count_cat + 2, "Category CAT 2 deleted" );
202 is( Koha::Libraries->search->count, $count + 2, 'BRB added' );
205 my $b1info = GetBranchInfo( $b1->{branchcode} );
206 $b1->{categories} = [];
207 is_deeply( @$b1info[0], $b1, 'BRA has no categories' );
209 my $b2info = GetBranchInfo( $b2->{branchcode} );
210 my @cat = ( $cat1->{categorycode} );
213 $b2->{issuing} = undef;
214 $b2->{categories} = \@cat;
215 is_deeply( @$b2info[0], $b2, 'BRB has the category CAT1' );
217 Koha::LibraryCategory->new($cat2)->store;
218 is( Koha::LibraryCategories->search->count, $count_cat + 3, "Two categories added" );
221 branchname => 'BranchB',
222 branchaddress1 => 'adr1B',
223 branchaddress2 => 'adr2B',
224 branchaddress3 => 'adr3B',
226 branchcity => 'cityB',
227 branchstate => 'stateB',
228 branchcountry => 'countryB',
229 branchphone => 'phoneB',
231 branchemail => 'emailB',
232 branchreplyto => 'emailreply',
233 branchreturnpath => 'branchreturn',
236 branchprinter => undef,
237 branchnotes => 'noteB',
238 opac_info => 'opacB',
243 $b2info = GetBranchInfo( $b2->{branchcode} );
244 push( @cat, $cat2->{categorycode} );
247 $b2->{issuing} = undef;
248 $b2->{categories} = \@cat;
249 is_deeply( @$b2info[0], $b2, 'BRB has the category CAT1 and CAT2' );
251 #TODO later: test mybranchine and onlymine
252 # Actually we cannot mock C4::Context->userenv in unit tests
254 #Test GetBranchesLoop
255 my $loop = GetBranchesLoop;
256 is( scalar(@$loop), Koha::Libraries->search->count, 'There is the right number of branches' );