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
=> 36;
30 use lib
$FindBin::Bin
;
43 CheckBranchCategorycode
58 my $dbh = C4
::Context
->dbh;
59 $dbh->{AutoCommit
} = 0;
60 $dbh->{RaiseError
} = 1;
63 $dbh->do('DELETE FROM branchcategories');
67 my $count = GetBranchesCount
();
68 like
( $count, '/^\d+$/', "the count is a number" );
74 branchname
=> 'BranchA',
75 branchaddress1
=> 'adr1A',
76 branchaddress2
=> 'adr2A',
77 branchaddress3
=> 'adr3A',
79 branchcity
=> 'cityA',
80 branchstate
=> 'stateA',
81 branchcountry
=> 'countryA',
82 branchphone
=> 'phoneA',
84 branchemail
=> 'emailA',
85 branchreplyto
=> 'emailreply',
86 branchreturnpath
=> 'branchreturn',
89 branchprinter
=> undef,
90 branchnotes
=> 'noteA',
95 branchname
=> 'BranchB',
96 branchaddress1
=> 'adr1B',
97 branchaddress2
=> 'adr2B',
98 branchaddress3
=> 'adr3B',
100 branchcity
=> 'cityB',
101 branchstate
=> 'stateB',
102 branchcountry
=> 'countryB',
103 branchphone
=> 'phoneB',
105 branchemail
=> 'emailB',
106 branchreplyto
=> 'emailreply',
107 branchreturnpath
=> 'branchreturn',
110 branchprinter
=> undef,
111 branchnotes
=> 'noteB',
112 opac_info
=> 'opacB',
115 is
( ModBranch
($b2), undef, 'the field add is missing' );
119 is
( GetBranchesCount
(), $count + 2, "two branches added" );
123 is
( DelBranch
( $b2->{branchcode
} ), 1, "One row affected" );
124 is
( GetBranchesCount
(), $count + 1, "branch BRB deleted" );
127 is
( GetBranchName
( $b1->{branchcode
} ),
128 $b1->{branchname
}, "GetBranchName returns the right name" );
130 #Test GetBranchDetail
131 my $branchdetail = GetBranchDetail
( $b1->{branchcode
} );
132 $branchdetail->{add
} = 1;
133 $b1->{issuing
} = undef; # Not used in DB
134 is_deeply
( $branchdetail, $b1, 'branchdetail is right' );
137 my $branches = GetBranches
();
138 is
( scalar( keys %$branches ),
139 GetBranchesCount
(), "GetBranches returns the right number of branches" );
145 branchname
=> 'BranchA modified',
146 branchaddress1
=> 'adr1A modified',
147 branchaddress2
=> 'adr2A modified',
148 branchaddress3
=> 'adr3A modified',
149 branchzip
=> 'zipA modified',
150 branchcity
=> 'cityA modified',
151 branchstate
=> 'stateA modified',
152 branchcountry
=> 'countryA modified',
153 branchphone
=> 'phoneA modified',
154 branchfax
=> 'faxA modified',
155 branchemail
=> 'emailA modified',
156 branchreplyto
=> 'emailreply modified',
157 branchreturnpath
=> 'branchreturn modified',
158 branchurl
=> 'urlA modified',
159 branchip
=> 'ipA modified',
160 branchprinter
=> undef,
161 branchnotes
=> 'notesA modified',
162 opac_info
=> 'opacA modified'
166 is
( GetBranchesCount
(), $count + 1,
167 "A branch has been modified, no new branch added" );
168 $branchdetail = GetBranchDetail
( $b1->{branchcode
} );
169 $b1->{issuing
} = undef;
170 is_deeply
( $branchdetail, $b1 , "GetBranchDetail gives the details of BRA");
173 my $categories = GetBranchCategories
();
174 my $count_cat = scalar( @
$categories );
178 categorycode
=> 'CAT1',
179 categoryname
=> 'catname1',
180 codedescription
=> 'catdesc1',
181 categorytype
=> 'cattype1',
182 show_in_pulldown
=> 1
186 categorycode
=> 'CAT2',
187 categoryname
=> 'catname2',
188 categorytype
=> 'catype2',
189 codedescription
=> 'catdesc2',
190 show_in_pulldown
=> 1
194 categorycode
=> 'LIBCATCODE',
195 categoryname
=> 'library category name',
196 codedescription
=> 'library category code description',
197 categorytype
=> 'searchdomain',
198 show_in_pulldown
=> 1,
201 ModBranchCategoryInfo
({
206 ModBranchCategoryInfo
($cat1);
207 ModBranchCategoryInfo
($cat2);
209 $categories = GetBranchCategories
();
210 is
( scalar( @
$categories ), $count_cat + 3, "Two categories added" );
213 delete $new_category{add
};
214 is_deeply
($categories, [ $cat1,$cat2,\
%new_category ], 'retrieve all expected library categories (bug 10515)');
216 #test GetBranchCategory
217 my $cat1detail = GetBranchCategory
( $cat1->{categorycode
} );
219 is_deeply
( $cat1detail, $cat1, 'CAT1 details are right' );
220 my $category = GetBranchCategory
('LIBCATCODE');
221 is_deeply
($category, \
%new_category, 'fetched newly added library category');
223 #Test DelBranchCategory
224 my $del = DelBranchCategory
( $cat2->{categorycode
} );
225 is
( $del, 1, 'One row affected' );
227 $categories = GetBranchCategories
();
228 is
( scalar( @
$categories ), $count_cat + 2, "Category CAT2 deleted" );
230 my $cat2detail = GetBranchCategory
( $cat2->{categorycode
} );
231 is
( $cat2detail, undef, 'CAT2 doesnt exist' );
233 $category = GetBranchCategory
();
234 is
($category, undef, 'retrieve library category only if code is supplied (bug 10515)');
236 #Test CheckBranchCategoryCode
237 my $check1 = CheckBranchCategorycode
( $cat1->{categorycode
} );
238 my $check2 = CheckBranchCategorycode
( $cat2->{categorycode
} );
239 like
( $check1, '/^\d+$/', "CheckBranchCategorycode returns a number" );
243 is
( GetBranchesCount
(), $count + 2, 'BRB added' );
245 CheckBranchCategorycode
( $cat1->{categorycode
} ),
251 my $b1info = GetBranchInfo
( $b1->{branchcode
} );
252 $b1->{categories
} = [];
253 is_deeply
( @
$b1info[0], $b1, 'BRA has no categories' );
255 my $b2info = GetBranchInfo
( $b2->{branchcode
} );
256 my @cat = ( $cat1->{categorycode
} );
259 $b2->{issuing
} = undef;
260 $b2->{categories
} = \
@cat;
261 is_deeply
( @
$b2info[0], $b2, 'BRB has the category CAT1' );
263 ModBranchCategoryInfo
({add
=> 1,%$cat2});
264 $categories = GetBranchCategories
();
265 is
( scalar( @
$categories ), $count_cat + 3, "Two categories added" );
268 branchname
=> 'BranchB',
269 branchaddress1
=> 'adr1B',
270 branchaddress2
=> 'adr2B',
271 branchaddress3
=> 'adr3B',
273 branchcity
=> 'cityB',
274 branchstate
=> 'stateB',
275 branchcountry
=> 'countryB',
276 branchphone
=> 'phoneB',
278 branchemail
=> 'emailB',
279 branchreplyto
=> 'emailreply',
280 branchreturnpath
=> 'branchreturn',
283 branchprinter
=> undef,
284 branchnotes
=> 'noteB',
285 opac_info
=> 'opacB',
290 $b2info = GetBranchInfo
( $b2->{branchcode
} );
292 CheckBranchCategorycode
( $cat2->{categorycode
} ),
296 push( @cat, $cat2->{categorycode
} );
299 $b2->{issuing
} = undef;
300 $b2->{categories
} = \
@cat;
301 is_deeply
( @
$b2info[0], $b2, 'BRB has the category CAT1 and CAT2' );
303 #Test GetBranchesInCategory
304 my $brCat1 = GetBranchesInCategory
( $cat1->{categorycode
} );
305 my @b = ( $b2->{branchcode
} );
306 is_deeply
( $brCat1, \
@b, 'CAT1 has branch BRB' );
311 branchname
=> 'BranchC',
312 branchaddress1
=> 'adr1C',
313 branchaddress2
=> 'adr2C',
314 branchaddress3
=> 'adr3C',
316 branchcity
=> 'cityC',
317 branchstate
=> 'stateC',
318 branchcountry
=> 'countryC',
319 branchphone
=> 'phoneC',
321 branchemail
=> 'emailC',
324 branchprinter
=> undef,
325 branchnotes
=> 'noteC',
326 opac_info
=> 'opacC',
331 $brCat1 = GetBranchesInCategory
( $cat1->{categorycode
} );
332 push( @b, $b3->{branchcode
} );
333 is_deeply
( $brCat1, \
@b, 'CAT1 has branch BRB and BRC' );
335 CheckBranchCategorycode
( $cat1->{categorycode
} ),
337 'BRC has been added to CAT1'
340 #Test CheckCategoryUnique
341 is
( CheckCategoryUnique
('CAT2'), 0, 'CAT2 exists' );
342 is
( CheckCategoryUnique
('CAT_NO_EXISTS'), 1, 'CAT_NO_EXISTS doesnt exist' );
344 #Test GetCategoryTypes
345 my @category_types = GetCategoryTypes
();
346 is_deeply
(\
@category_types, [ 'searchdomain', 'properties' ], 'received expected library category types');
348 $categories = GetBranchCategories
(undef, undef, 'LIBCATCODE');
349 is_deeply
($categories, [ {%$cat1}, {%$cat2},{ %new_category, selected
=> 1 } ], 'retrieve expected, eselected library category (bug 10515)');
351 #TODO later: test mybranchine and onlymine
352 # Actually we cannot mock C4::Context->userenv in unit tests
354 #Test GetBranchesLoop
355 my $loop = GetBranchesLoop
;
356 is
( scalar(@
$loop), GetBranchesCount
(), 'There is the right number of branches' );