10 use DateTime::Duration;
12 use Test::More tests => 19;
15 use_ok('C4::Circulation');
20 CreateBranchTransferLimit
21 DeleteBranchTransferLimits
29 my $dbh = C4::Context->dbh;
30 $dbh->{RaiseError} = 1;
31 $dbh->{AutoCommit} = 0;
33 $dbh->do(q|DELETE FROM issues|);
34 $dbh->do(q|DELETE FROM borrowers|);
35 $dbh->do(q|DELETE FROM items|);
36 $dbh->do(q|DELETE FROM branches|);
37 $dbh->do(q|DELETE FROM branch_transfer_limits|);
38 $dbh->do(q|DELETE FROM branchtransfers|);
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',
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);
84 my $record = MARC::Record->new();
85 $record->append_fields(
86 MARC::Field->new( '952', '0', '0', a => $samplebranch1->{branchcode} ) );
87 my ( $biblionumber, $biblioitemnumber ) = C4::Biblio::AddBiblio( $record, '', );
89 my @sampleitem1 = C4::Items::AddItem(
92 itemcallnumber => 'callnumber1',
93 homebranch => $samplebranch1->{branchcode},
94 holdingbranch => $samplebranch1->{branchcode}
98 my $item_id1 = $sampleitem1[2];
99 my @sampleitem2 = C4::Items::AddItem(
102 itemcallnumber => 'callnumber2',
103 homebranch => $samplebranch1->{branchcode},
104 holdingbranch => $samplebranch1->{branchcode}
108 my $item_id2 = $sampleitem2[2];
113 $samplebranch1->{branchcode},
114 $samplebranch2->{branchcode}
118 $samplebranch1->{branchcode},
119 $samplebranch2->{branchcode}
123 #Test CreateBranchTransferLimit
125 CreateBranchTransferLimit(
126 $samplebranch2->{branchcode},
127 $samplebranch1->{branchcode}, 'CODE'
130 "A Branch TransferLimit has been added"
132 is(CreateBranchTransferLimit(),undef,
133 "Without parameters CreateBranchTransferLimit returns undef");
134 is(CreateBranchTransferLimit($samplebranch2->{branchcode}),undef,
135 "With only tobranch CreateBranchTransferLimit returns undef");
136 is(CreateBranchTransferLimit(undef,$samplebranch2->{branchcode}),undef,
137 "With only frombranch CreateBranchTransferLimit returns undef");
138 #FIXME: Currently, we can add a transferlimit even to nonexistent branches because in the database,
139 #branch_transfer_limits.toBranch and branch_transfer_limits.fromBranch aren't foreign keys
140 #is(CreateBranchTransferLimit(-1,-1,'CODE'),0,"With wrong CreateBranchTransferLimit returns 0 - No transfertlimit added");
143 my $dt_today = dt_from_string( undef, 'sql', undef );
144 my $today = $dt_today->strftime("%Y-%m-%d %H:%M:%S");
146 my @transfers = GetTransfers($item_id1);
149 [ $today, $samplebranch1->{branchcode}, $samplebranch2->{branchcode} ],
150 "Transfers of the item1"
151 ); #NOTE: Only the first transfer is returned
152 @transfers = GetTransfers;
153 is_deeply( \@transfers, [],
154 "GetTransfers without params returns an empty array" );
155 @transfers = GetTransfers(-1);
156 is_deeply( \@transfers, [],
157 "GetTransfers with a wrong item id returns an empty array" );
159 #Test GetTransfersFromTo
160 my @transferfrom1to2 = GetTransfersFromTo( $samplebranch1->{branchcode},
161 $samplebranch2->{branchcode} );
166 itemnumber => $item_id1,
168 frombranch => $samplebranch1->{branchcode}
171 itemnumber => $item_id2,
173 frombranch => $samplebranch1->{branchcode}
176 "Item1 and Item2 has been transfered from branch1 to branch2"
178 my @transferto = GetTransfersFromTo( undef, $samplebranch2->{branchcode} );
179 is_deeply( \@transferto, [],
180 "GetTransfersfromTo without frombranch returns an empty array" );
181 my @transferfrom = GetTransfersFromTo( $samplebranch1->{branchcode} );
182 is_deeply( \@transferfrom, [],
183 "GetTransfersfromTo without tobranch returns an empty array" );
184 @transferfrom = GetTransfersFromTo();
185 is_deeply( \@transferfrom, [],
186 "GetTransfersfromTo without params returns an empty array" );
188 #Test DeleteBranchTransferLimits
190 C4::Circulation::DeleteBranchTransferLimits( $samplebranch1->{branchcode} ),
192 "A Branch TransferLimit has been deleted"
194 is(C4::Circulation::DeleteBranchTransferLimits(),undef,"Without parameters DeleteBranchTransferLimit returns undef");
195 is(C4::Circulation::DeleteBranchTransferLimits('B'),'0E0',"With a wrong id DeleteBranchTransferLimit returns 0E0");
198 is( C4::Circulation::DeleteTransfer($item_id1),
199 1, "A the item1's transfer has been deleted" );
200 is(C4::Circulation::DeleteTransfer(),undef,"Without itemid DeleteTransfer returns undef");
201 is(C4::Circulation::DeleteTransfer(-1),'0E0',"with a wrong itemid DeleteTranfer returns 0E0");