Bug 12744 - Set language in staff client should have 'Cancel' link
[koha.git] / t / db_dependent / Circulation_Branch.t
blobee2645837d4fff6276f70372b6e0d4adc30ef9b3
1 #!/usr/bin/perl
3 use Modern::Perl;
4 use C4::Biblio;
5 use C4::Members;
6 use C4::Branch;
7 use C4::Circulation;
8 use C4::Items;
9 use C4::Context;
11 use Test::More tests => 10;
13 BEGIN {
14 use_ok('C4::Circulation');
17 can_ok( 'C4::Circulation', qw(
18 GetBranchBorrowerCircRule
19 GetBranchItemRule
23 #Start transaction
24 my $dbh = C4::Context->dbh;
25 $dbh->{RaiseError} = 1;
26 $dbh->{AutoCommit} = 0;
28 $dbh->do(q|DELETE FROM issues|);
29 $dbh->do(q|DELETE FROM items|);
30 $dbh->do(q|DELETE FROM borrowers|);
31 $dbh->do(q|DELETE FROM branches|);
32 $dbh->do(q|DELETE FROM categories|);
33 $dbh->do(q|DELETE FROM accountlines|);
34 $dbh->do(q|DELETE FROM itemtypes|);
35 $dbh->do(q|DELETE FROM branch_item_rules|);
36 $dbh->do(q|DELETE FROM branch_borrower_circ_rules|);
37 $dbh->do(q|DELETE FROM default_branch_circ_rules|);
38 $dbh->do(q|DELETE FROM default_circ_rules|);
39 $dbh->do(q|DELETE FROM default_branch_item_rules|);
41 #Add branch and category
42 my $samplebranch1 = {
43 add => 1,
44 branchcode => 'SAB1',
45 branchname => 'Sample Branch',
46 branchaddress1 => 'sample adr1',
47 branchaddress2 => 'sample adr2',
48 branchaddress3 => 'sample adr3',
49 branchzip => 'sample zip',
50 branchcity => 'sample city',
51 branchstate => 'sample state',
52 branchcountry => 'sample country',
53 branchphone => 'sample phone',
54 branchfax => 'sample fax',
55 branchemail => 'sample email',
56 branchurl => 'sample url',
57 branchip => 'sample ip',
58 branchprinter => undef,
59 opac_info => 'sample opac',
61 my $samplebranch2 = {
62 add => 1,
63 branchcode => 'SAB2',
64 branchname => 'Sample Branch2',
65 branchaddress1 => 'sample adr1_2',
66 branchaddress2 => 'sample adr2_2',
67 branchaddress3 => 'sample adr3_2',
68 branchzip => 'sample zip2',
69 branchcity => 'sample city2',
70 branchstate => 'sample state2',
71 branchcountry => 'sample country2',
72 branchphone => 'sample phone2',
73 branchfax => 'sample fax2',
74 branchemail => 'sample email2',
75 branchurl => 'sample url2',
76 branchip => 'sample ip2',
77 branchprinter => undef,
78 opac_info => 'sample opac2',
80 ModBranch($samplebranch1);
81 ModBranch($samplebranch2);
83 my $samplecat = {
84 categorycode => 'CAT1',
85 description => 'Description1',
86 enrolmentperiod => 'Null',
87 enrolmentperioddate => 'Null',
88 dateofbirthrequired => 'Null',
89 finetype => 'Null',
90 bulk => 'Null',
91 enrolmentfee => 'Null',
92 overduenoticerequired => 'Null',
93 issuelimit => 'Null',
94 reservefee => 'Null',
95 hidelostitems => 0,
96 category_type => 'Null'
98 my $query =
99 "INSERT INTO categories (categorycode,
100 description,
101 enrolmentperiod,
102 enrolmentperioddate,
103 dateofbirthrequired ,
104 finetype,
105 bulk,
106 enrolmentfee,
107 overduenoticerequired,
108 issuelimit,
109 reservefee,
110 hidelostitems,
111 category_type
113 VALUES( ?,?,?,?,?,?,?,?,?,?,?,?,?)";
114 $dbh->do(
115 $query, {},
116 $samplecat->{categorycode}, $samplecat->{description},
117 $samplecat->{enrolmentperiod}, $samplecat->{enrolmentperioddate},
118 $samplecat->{dateofbirthrequired}, $samplecat->{finetype},
119 $samplecat->{bulk}, $samplecat->{enrolmentfee},
120 $samplecat->{overduenoticerequired}, $samplecat->{issuelimit},
121 $samplecat->{reservefee}, $samplecat->{hidelostitems},
122 $samplecat->{category_type}
125 #Add itemtypes
126 my $sampleitemtype1 = {
127 itemtype => 'BOOK',
128 description => 'BookDescription',
129 rentalcharge => '10.0',
130 notforloan => 1,
131 imageurl => 'Null',
132 summary => 'BookSummary'
134 my $sampleitemtype2 = {
135 itemtype => 'DVD',
136 description => 'DvdDescription',
137 rentalcharge => '5.0',
138 notforloan => 0,
139 imageurl => 'Null',
140 summary => 'DvdSummary'
142 $query =
143 "INSERT INTO itemtypes (itemtype,
144 description,
145 rentalcharge,
146 notforloan,
147 imageurl,
148 summary
150 VALUES( ?,?,?,?,?,?)";
151 my $sth = $dbh->prepare($query);
152 $sth->execute(
153 $sampleitemtype1->{itemtype}, $sampleitemtype1->{description},
154 $sampleitemtype1->{rentalcharge}, $sampleitemtype1->{notforloan},
155 $sampleitemtype1->{imageurl}, $sampleitemtype1->{summary}
157 $sth->execute(
158 $sampleitemtype2->{itemtype}, $sampleitemtype2->{description},
159 $sampleitemtype2->{rentalcharge}, $sampleitemtype2->{notforloan},
160 $sampleitemtype2->{imageurl}, $sampleitemtype2->{summary}
163 $query =
164 "INSERT INTO branch_borrower_circ_rules (branchcode,categorycode,maxissueqty) VALUES( ?,?,?)";
165 $dbh->do(
166 $query, {},
167 $samplebranch1->{branchcode},
168 $samplecat->{categorycode}, 5
170 $query =
171 "INSERT INTO default_branch_circ_rules (branchcode,maxissueqty,holdallowed,returnbranch) VALUES( ?,?,?,?)";
172 $dbh->do( $query, {}, $samplebranch2->{branchcode},
173 3, 1, $samplebranch2->{branchcode} );
174 $query =
175 "INSERT INTO default_circ_rules (singleton,maxissueqty,holdallowed,returnbranch) VALUES( ?,?,?,?)";
176 $dbh->do( $query, {}, 'singleton', 4, 3, $samplebranch1->{branchcode} );
178 $query =
179 "INSERT INTO branch_item_rules (branchcode,itemtype,holdallowed,returnbranch) VALUES( ?,?,?,?)";
180 $sth = $dbh->prepare($query);
181 $sth->execute(
182 $samplebranch1->{branchcode},
183 $sampleitemtype1->{itemtype},
184 5, $samplebranch1->{branchcode}
186 $sth->execute(
187 $samplebranch2->{branchcode},
188 $sampleitemtype2->{itemtype},
189 5, $samplebranch1->{branchcode}
192 #Test GetBranchBorrowerCircRule
193 is_deeply(
194 GetBranchBorrowerCircRule(),
195 { maxissueqty => 4 },
196 "Without parameter, GetBranchBorrower returns the maxissueqty of default_circ_rules"
198 is_deeply(
199 GetBranchBorrowerCircRule( $samplebranch2->{branchcode} ),
200 { maxissueqty => 3 },
201 "Without only the branchcode specified, GetBranchBorrower returns the maxissueqty corresponding"
203 is_deeply(
204 GetBranchBorrowerCircRule(
205 $samplebranch1->{branchcode},
206 $samplecat->{categorycode}
208 { maxissueqty => 5 },
209 "GetBranchBorrower returns the maxissueqty of the branch1 and the category1"
211 is_deeply(
212 GetBranchBorrowerCircRule( -1, -1 ),
213 { maxissueqty => 4 },
214 "GetBranchBorrower with wrong parameters returns tthe maxissueqty of default_circ_rules"
217 #Test GetBranchItemRule
218 is_deeply(
219 GetBranchItemRule(
220 $samplebranch1->{branchcode},
221 $sampleitemtype1->{itemtype}
223 { returnbranch => $samplebranch1->{branchcode}, holdallowed => 5 },
224 "GetBranchitem returns holdallowed and return branch"
226 is_deeply(
227 GetBranchItemRule(),
228 { returnbranch => $samplebranch1->{branchcode}, holdallowed => 3 },
229 "Without parameters GetBranchItemRule returns the values in default_circ_rules"
231 is_deeply(
232 GetBranchItemRule( $samplebranch1->{branchcode} ),
233 { returnbranch => $samplebranch1->{branchcode}, holdallowed => 3 },
234 "With only a branchcode GetBranchItemRule returns values in default_branch_circ_rules"
236 is_deeply(
237 GetBranchItemRule( -1, -1 ),
238 { returnbranch => $samplebranch1->{branchcode}, holdallowed => 3 },
239 "With only one parametern GetBranchItemRule returns default values"
242 $dbh->rollback;