Bug 12863 [LESS follow-up] News in OPAC: HTML broken with nested p tags and multiple...
[koha.git] / t / db_dependent / Circulation_transfers.t
blob25e720ada3060d5eb17ee0da52dc74f792c80686
1 #!/usr/bin/perl
3 use Modern::Perl;
4 use C4::Biblio;
5 use C4::Context;
6 use C4::Items;
7 use C4::Branch;
8 use C4::Circulation;
9 use Koha::DateUtils;
10 use DateTime::Duration;
12 use Test::More tests => 19;
13 use Test::Deep;
15 BEGIN {
16 use_ok('C4::Circulation');
18 can_ok(
19 'C4::Circulation',
20 qw(
21 CreateBranchTransferLimit
22 DeleteBranchTransferLimits
23 DeleteTransfer
24 GetTransfers
25 GetTransfersFromTo
29 #Start transaction
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|);
41 #Add sample datas
42 #Add branches
43 my $samplebranch1 = {
44 add => 1,
45 branchcode => 'SAB1',
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',
62 my $samplebranch2 = {
63 add => 1,
64 branchcode => 'SAB2',
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);
84 #Add biblio and items
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(
92 barcode => 1,
93 itemcallnumber => 'callnumber1',
94 homebranch => $samplebranch1->{branchcode},
95 holdingbranch => $samplebranch1->{branchcode}
97 $biblionumber
99 my $item_id1 = $sampleitem1[2];
100 my @sampleitem2 = C4::Items::AddItem(
102 barcode => 2,
103 itemcallnumber => 'callnumber2',
104 homebranch => $samplebranch1->{branchcode},
105 holdingbranch => $samplebranch1->{branchcode}
107 $biblionumber
109 my $item_id2 = $sampleitem2[2];
111 #Add transfers
112 ModItemTransfer(
113 $item_id1,
114 $samplebranch1->{branchcode},
115 $samplebranch2->{branchcode}
117 ModItemTransfer(
118 $item_id2,
119 $samplebranch1->{branchcode},
120 $samplebranch2->{branchcode}
123 #Begin Tests
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");
143 #Test GetTransfers
144 my @transfers = GetTransfers($item_id1);
145 cmp_deeply(
146 \@transfers,
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} );
160 cmp_deeply(
161 \@transferfrom1to2,
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");
195 #Test DeleteTransfer
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");
201 #End transaction
202 $dbh->rollback;