10 use DateTime
::Duration
;
12 use Test
::More tests
=> 19;
16 use_ok
('C4::Circulation');
21 CreateBranchTransferLimit
22 DeleteBranchTransferLimits
30 my $dbh = C4
::Context
->dbh;
31 $dbh->{RaiseError
} = 1;
32 $dbh->{AutoCommit
} = 0;
34 $dbh->do(q
|DELETE FROM issues
|);
35 $dbh->do(q
|DELETE FROM borrowers
|);
36 $dbh->do(q
|DELETE FROM items
|);
37 $dbh->do(q
|DELETE FROM branches
|);
38 $dbh->do(q
|DELETE FROM branch_transfer_limits
|);
39 $dbh->do(q
|DELETE FROM branchtransfers
|);
46 branchname
=> 'Sample Branch',
47 branchaddress1
=> 'sample adr1',
48 branchaddress2
=> 'sample adr2',
49 branchaddress3
=> 'sample adr3',
50 branchzip
=> 'sample zip',
51 branchcity
=> 'sample city',
52 branchstate
=> 'sample state',
53 branchcountry
=> 'sample country',
54 branchphone
=> 'sample phone',
55 branchfax
=> 'sample fax',
56 branchemail
=> 'sample email',
57 branchurl
=> 'sample url',
58 branchip
=> 'sample ip',
59 branchprinter
=> undef,
60 opac_info
=> 'sample opac',
65 branchname
=> 'Sample Branch2',
66 branchaddress1
=> 'sample adr1_2',
67 branchaddress2
=> 'sample adr2_2',
68 branchaddress3
=> 'sample adr3_2',
69 branchzip
=> 'sample zip2',
70 branchcity
=> 'sample city2',
71 branchstate
=> 'sample state2',
72 branchcountry
=> 'sample country2',
73 branchphone
=> 'sample phone2',
74 branchfax
=> 'sample fax2',
75 branchemail
=> 'sample email2',
76 branchurl
=> 'sample url2',
77 branchip
=> 'sample ip2',
78 branchprinter
=> undef,
79 opac_info
=> 'sample opac2',
81 ModBranch
($samplebranch1);
82 ModBranch
($samplebranch2);
85 my $record = MARC
::Record
->new();
86 $record->append_fields(
87 MARC
::Field
->new( '952', '0', '0', a
=> $samplebranch1->{branchcode
} ) );
88 my ( $biblionumber, $biblioitemnumber ) = C4
::Biblio
::AddBiblio
( $record, '', );
90 my @sampleitem1 = C4
::Items
::AddItem
(
93 itemcallnumber
=> 'callnumber1',
94 homebranch
=> $samplebranch1->{branchcode
},
95 holdingbranch
=> $samplebranch1->{branchcode
}
99 my $item_id1 = $sampleitem1[2];
100 my @sampleitem2 = C4
::Items
::AddItem
(
103 itemcallnumber
=> 'callnumber2',
104 homebranch
=> $samplebranch1->{branchcode
},
105 holdingbranch
=> $samplebranch1->{branchcode
}
109 my $item_id2 = $sampleitem2[2];
114 $samplebranch1->{branchcode
},
115 $samplebranch2->{branchcode
}
119 $samplebranch1->{branchcode
},
120 $samplebranch2->{branchcode
}
124 #Test CreateBranchTransferLimit
126 CreateBranchTransferLimit
(
127 $samplebranch2->{branchcode
},
128 $samplebranch1->{branchcode
}, 'CODE'
131 "A Branch TransferLimit has been added"
133 is
(CreateBranchTransferLimit
(),undef,
134 "Without parameters CreateBranchTransferLimit returns undef");
135 is
(CreateBranchTransferLimit
($samplebranch2->{branchcode
}),undef,
136 "With only tobranch CreateBranchTransferLimit returns undef");
137 is
(CreateBranchTransferLimit
(undef,$samplebranch2->{branchcode
}),undef,
138 "With only frombranch CreateBranchTransferLimit returns undef");
139 #FIXME: Currently, we can add a transferlimit even to nonexistent branches because in the database,
140 #branch_transfer_limits.toBranch and branch_transfer_limits.fromBranch aren't foreign keys
141 #is(CreateBranchTransferLimit(-1,-1,'CODE'),0,"With wrong CreateBranchTransferLimit returns 0 - No transfertlimit added");
144 my @transfers = GetTransfers
($item_id1);
147 [ re
('^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$'), $samplebranch1->{branchcode
}, $samplebranch2->{branchcode
} ],
148 "Transfers of the item1"
149 ); #NOTE: Only the first transfer is returned
150 @transfers = GetTransfers
;
151 is_deeply
( \
@transfers, [],
152 "GetTransfers without params returns an empty array" );
153 @transfers = GetTransfers
(-1);
154 is_deeply
( \
@transfers, [],
155 "GetTransfers with a wrong item id returns an empty array" );
157 #Test GetTransfersFromTo
158 my @transferfrom1to2 = GetTransfersFromTo
( $samplebranch1->{branchcode
},
159 $samplebranch2->{branchcode
} );
164 itemnumber
=> $item_id1,
165 datesent
=> re
('^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$'),
166 frombranch
=> $samplebranch1->{branchcode
}
169 itemnumber
=> $item_id2,
170 datesent
=> re
('^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$'),
171 frombranch
=> $samplebranch1->{branchcode
}
174 "Item1 and Item2 has been transfered from branch1 to branch2"
176 my @transferto = GetTransfersFromTo
( undef, $samplebranch2->{branchcode
} );
177 is_deeply
( \
@transferto, [],
178 "GetTransfersfromTo without frombranch returns an empty array" );
179 my @transferfrom = GetTransfersFromTo
( $samplebranch1->{branchcode
} );
180 is_deeply
( \
@transferfrom, [],
181 "GetTransfersfromTo without tobranch returns an empty array" );
182 @transferfrom = GetTransfersFromTo
();
183 is_deeply
( \
@transferfrom, [],
184 "GetTransfersfromTo without params returns an empty array" );
186 #Test DeleteBranchTransferLimits
188 C4
::Circulation
::DeleteBranchTransferLimits
( $samplebranch1->{branchcode
} ),
190 "A Branch TransferLimit has been deleted"
192 is
(C4
::Circulation
::DeleteBranchTransferLimits
(),undef,"Without parameters DeleteBranchTransferLimit returns undef");
193 is
(C4
::Circulation
::DeleteBranchTransferLimits
('B'),'0E0',"With a wrong id DeleteBranchTransferLimit returns 0E0");
196 is
( C4
::Circulation
::DeleteTransfer
($item_id1),
197 1, "A the item1's transfer has been deleted" );
198 is
(C4
::Circulation
::DeleteTransfer
(),undef,"Without itemid DeleteTransfer returns undef");
199 is
(C4
::Circulation
::DeleteTransfer
(-1),'0E0',"with a wrong itemid DeleteTranfer returns 0E0");