10 use DateTime::Duration;
12 use Test::More tests => 12;
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 #FIXME :The following test should pass but doesn't because currently the routine CreateBranchTransferLimit returns nothing
133 #is(CreateBranchTransferLimit(),undef,"Without parameters CreateBranchTransferLimit returns undef");
136 my $dt_today = dt_from_string( undef, 'sql', undef );
137 my $today = $dt_today->strftime("%Y-%m-%d %H:%M:%S");
139 my @transfers = GetTransfers($item_id1);
142 [ $today, $samplebranch1->{branchcode}, $samplebranch2->{branchcode} ],
143 "Transfers of the item1"
144 ); #NOTE: Only the first transfer is returned
145 @transfers = GetTransfers;
146 is_deeply( \@transfers, [],
147 "GetTransfers without params returns an empty array" );
148 @transfers = GetTransfers(-1);
149 is_deeply( \@transfers, [],
150 "GetTransfers with a wrong item id returns an empty array" );
152 #Test GetTransfersFromTo
153 my @transferfrom1to2 = GetTransfersFromTo( $samplebranch1->{branchcode},
154 $samplebranch2->{branchcode} );
159 itemnumber => $item_id1,
161 frombranch => $samplebranch1->{branchcode}
164 itemnumber => $item_id2,
166 frombranch => $samplebranch1->{branchcode}
169 "Item1 and Item2 has been transfered from branch1 to branch2"
171 my @transferto = GetTransfersFromTo( undef, $samplebranch2->{branchcode} );
172 is_deeply( \@transferto, [],
173 "GetTransfersfromTo without frombranch returns an empty array" );
174 my @transferfrom = GetTransfersFromTo( $samplebranch1->{branchcode} );
175 is_deeply( \@transferfrom, [],
176 "GetTransfersfromTo without tobranch returns an empty array" );
177 @transferfrom = GetTransfersFromTo();
178 is_deeply( \@transferfrom, [],
179 "GetTransfersfromTo without params returns an empty array" );
181 #Test DeleteBranchTransferLimits
183 C4::Circulation::DeleteBranchTransferLimits( $samplebranch1->{branchcode} ),
185 "A Branch TransferLimit has been deleted"
187 #FIXME :The following test should pass but doesn't because currently the routine DeleteBranchTransferLimit returns nothin
188 #is(C4::Circulation::DeleteBranchTransferLimits(),undef,"Without parameters DeleteBranchTransferLimit returns undef");
191 is( C4::Circulation::DeleteTransfer($item_id1),
192 1, "A the item1's transfer has been deleted" );
193 #FIXME :The following tests should pass but don't because currently the routine DeleteTransfer returns nothing
194 #is(C4::Circulation::DeleteTransfer(),undef,"Without itemid DeleteTransfer returns undef");
195 #is(C4::Circulation::DeleteTransfer(-1),0,"with a wrong itemid DeleteTranfer returns 0");