|
Lines 1-5
Link Here
|
| 1 |
#!/usr/bin/perl |
1 |
#!/usr/bin/perl |
| 2 |
|
2 |
|
|
|
3 |
# This file is part of Koha. |
| 4 |
# |
| 5 |
# Koha is free software; you can redistribute it and/or modify it |
| 6 |
# under the terms of the GNU General Public License as published by |
| 7 |
# the Free Software Foundation; either version 3 of the License, or |
| 8 |
# (at your option) any later version. |
| 9 |
# |
| 10 |
# Koha is distributed in the hope that it will be useful, but |
| 11 |
# WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 |
# GNU General Public License for more details. |
| 14 |
# |
| 15 |
# You should have received a copy of the GNU General Public License |
| 16 |
# along with Koha; if not, see <http://www.gnu.org/licenses>. |
| 17 |
|
| 3 |
use Modern::Perl; |
18 |
use Modern::Perl; |
| 4 |
use C4::Biblio; |
19 |
use C4::Biblio; |
| 5 |
use C4::Context; |
20 |
use C4::Context; |
|
Lines 40-76
$dbh->do(q|DELETE FROM branches|);
Link Here
|
| 40 |
$dbh->do(q|DELETE FROM branch_transfer_limits|); |
55 |
$dbh->do(q|DELETE FROM branch_transfer_limits|); |
| 41 |
$dbh->do(q|DELETE FROM branchtransfers|); |
56 |
$dbh->do(q|DELETE FROM branchtransfers|); |
| 42 |
|
57 |
|
| 43 |
#Add sample datas |
58 |
## Create sample datas |
| 44 |
#Add branches |
59 |
# Add branches |
| 45 |
my $samplebranch1 = $builder->build({ |
60 |
my $branchcode_1 = $builder->build( { source => 'Branch', } )->{branchcode}; |
| 46 |
source => 'Branch', |
61 |
my $branchcode_2 = $builder->build( { source => 'Branch', } )->{branchcode}; |
| 47 |
}); |
62 |
# Add itemtype |
| 48 |
my $samplebranch2 = $builder->build({ |
63 |
my $itemtype = $builder->build( { source => 'Itemtype' } )->{itemtype}; |
| 49 |
source => 'Branch', |
|
|
| 50 |
}); |
| 51 |
|
64 |
|
| 52 |
#Add biblio and items |
65 |
#Add biblio and items |
| 53 |
my $record = MARC::Record->new(); |
66 |
my $record = MARC::Record->new(); |
| 54 |
$record->append_fields( |
67 |
$record->append_fields( |
| 55 |
MARC::Field->new( '952', '0', '0', a => $samplebranch1->{branchcode} ) ); |
68 |
MARC::Field->new( '952', '0', '0', a => $branchcode_1 ) ); |
| 56 |
my ( $biblionumber, $biblioitemnumber ) = C4::Biblio::AddBiblio( $record, '', ); |
69 |
my ( $biblionumber, $biblioitemnumber ) = C4::Biblio::AddBiblio( $record, '', ); |
| 57 |
|
70 |
|
| 58 |
my @sampleitem1 = C4::Items::AddItem( |
71 |
my @sampleitem1 = C4::Items::AddItem( |
| 59 |
{ |
72 |
{ barcode => 1, |
| 60 |
barcode => 1, |
|
|
| 61 |
itemcallnumber => 'callnumber1', |
73 |
itemcallnumber => 'callnumber1', |
| 62 |
homebranch => $samplebranch1->{branchcode}, |
74 |
homebranch => $branchcode_1, |
| 63 |
holdingbranch => $samplebranch1->{branchcode} |
75 |
holdingbranch => $branchcode_1, |
|
|
76 |
itype => $itemtype |
| 64 |
}, |
77 |
}, |
| 65 |
$biblionumber |
78 |
$biblionumber |
| 66 |
); |
79 |
); |
| 67 |
my $item_id1 = $sampleitem1[2]; |
80 |
my $item_id1 = $sampleitem1[2]; |
| 68 |
my @sampleitem2 = C4::Items::AddItem( |
81 |
my @sampleitem2 = C4::Items::AddItem( |
| 69 |
{ |
82 |
{ barcode => 2, |
| 70 |
barcode => 2, |
|
|
| 71 |
itemcallnumber => 'callnumber2', |
83 |
itemcallnumber => 'callnumber2', |
| 72 |
homebranch => $samplebranch1->{branchcode}, |
84 |
homebranch => $branchcode_1, |
| 73 |
holdingbranch => $samplebranch1->{branchcode} |
85 |
holdingbranch => $branchcode_1, |
|
|
86 |
itype => $itemtype |
| 74 |
}, |
87 |
}, |
| 75 |
$biblionumber |
88 |
$biblionumber |
| 76 |
); |
89 |
); |
|
Lines 79-108
my $item_id2 = $sampleitem2[2];
Link Here
|
| 79 |
#Add transfers |
92 |
#Add transfers |
| 80 |
ModItemTransfer( |
93 |
ModItemTransfer( |
| 81 |
$item_id1, |
94 |
$item_id1, |
| 82 |
$samplebranch1->{branchcode}, |
95 |
$branchcode_1, |
| 83 |
$samplebranch2->{branchcode} |
96 |
$branchcode_2 |
| 84 |
); |
97 |
); |
| 85 |
ModItemTransfer( |
98 |
ModItemTransfer( |
| 86 |
$item_id2, |
99 |
$item_id2, |
| 87 |
$samplebranch1->{branchcode}, |
100 |
$branchcode_1, |
| 88 |
$samplebranch2->{branchcode} |
101 |
$branchcode_2 |
| 89 |
); |
102 |
); |
| 90 |
|
103 |
|
| 91 |
#Begin Tests |
104 |
#Begin Tests |
| 92 |
#Test CreateBranchTransferLimit |
105 |
#Test CreateBranchTransferLimit |
| 93 |
is( |
106 |
is( |
| 94 |
CreateBranchTransferLimit( |
107 |
CreateBranchTransferLimit( |
| 95 |
$samplebranch2->{branchcode}, |
108 |
$branchcode_2, |
| 96 |
$samplebranch1->{branchcode}, 'CODE' |
109 |
$branchcode_1, 'CODE' |
| 97 |
), |
110 |
), |
| 98 |
1, |
111 |
1, |
| 99 |
"A Branch TransferLimit has been added" |
112 |
"A Branch TransferLimit has been added" |
| 100 |
); |
113 |
); |
| 101 |
is(CreateBranchTransferLimit(),undef, |
114 |
is(CreateBranchTransferLimit(),undef, |
| 102 |
"Without parameters CreateBranchTransferLimit returns undef"); |
115 |
"Without parameters CreateBranchTransferLimit returns undef"); |
| 103 |
is(CreateBranchTransferLimit($samplebranch2->{branchcode}),undef, |
116 |
is(CreateBranchTransferLimit($branchcode_2),undef, |
| 104 |
"With only tobranch CreateBranchTransferLimit returns undef"); |
117 |
"With only tobranch CreateBranchTransferLimit returns undef"); |
| 105 |
is(CreateBranchTransferLimit(undef,$samplebranch2->{branchcode}),undef, |
118 |
is(CreateBranchTransferLimit(undef,$branchcode_2),undef, |
| 106 |
"With only frombranch CreateBranchTransferLimit returns undef"); |
119 |
"With only frombranch CreateBranchTransferLimit returns undef"); |
| 107 |
#FIXME: Currently, we can add a transferlimit even to nonexistent branches because in the database, |
120 |
#FIXME: Currently, we can add a transferlimit even to nonexistent branches because in the database, |
| 108 |
#branch_transfer_limits.toBranch and branch_transfer_limits.fromBranch aren't foreign keys |
121 |
#branch_transfer_limits.toBranch and branch_transfer_limits.fromBranch aren't foreign keys |
|
Lines 112-118
is(CreateBranchTransferLimit(undef,$samplebranch2->{branchcode}),undef,
Link Here
|
| 112 |
my @transfers = GetTransfers($item_id1); |
125 |
my @transfers = GetTransfers($item_id1); |
| 113 |
cmp_deeply( |
126 |
cmp_deeply( |
| 114 |
\@transfers, |
127 |
\@transfers, |
| 115 |
[ re('^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$'), $samplebranch1->{branchcode}, $samplebranch2->{branchcode} ], |
128 |
[ re('^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$'), $branchcode_1, $branchcode_2 ], |
| 116 |
"Transfers of the item1" |
129 |
"Transfers of the item1" |
| 117 |
); #NOTE: Only the first transfer is returned |
130 |
); #NOTE: Only the first transfer is returned |
| 118 |
@transfers = GetTransfers; |
131 |
@transfers = GetTransfers; |
|
Lines 123-150
is_deeply( \@transfers, [],
Link Here
|
| 123 |
"GetTransfers with a wrong item id returns an empty array" ); |
136 |
"GetTransfers with a wrong item id returns an empty array" ); |
| 124 |
|
137 |
|
| 125 |
#Test GetTransfersFromTo |
138 |
#Test GetTransfersFromTo |
| 126 |
my @transferfrom1to2 = GetTransfersFromTo( $samplebranch1->{branchcode}, |
139 |
my @transferfrom1to2 = GetTransfersFromTo( $branchcode_1, |
| 127 |
$samplebranch2->{branchcode} ); |
140 |
$branchcode_2 ); |
| 128 |
cmp_deeply( |
141 |
cmp_deeply( |
| 129 |
\@transferfrom1to2, |
142 |
\@transferfrom1to2, |
| 130 |
[ |
143 |
[ |
| 131 |
{ |
144 |
{ |
| 132 |
itemnumber => $item_id1, |
145 |
itemnumber => $item_id1, |
| 133 |
datesent => re('^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$'), |
146 |
datesent => re('^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$'), |
| 134 |
frombranch => $samplebranch1->{branchcode} |
147 |
frombranch => $branchcode_1 |
| 135 |
}, |
148 |
}, |
| 136 |
{ |
149 |
{ |
| 137 |
itemnumber => $item_id2, |
150 |
itemnumber => $item_id2, |
| 138 |
datesent => re('^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$'), |
151 |
datesent => re('^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$'), |
| 139 |
frombranch => $samplebranch1->{branchcode} |
152 |
frombranch => $branchcode_1 |
| 140 |
} |
153 |
} |
| 141 |
], |
154 |
], |
| 142 |
"Item1 and Item2 has been transferred from branch1 to branch2" |
155 |
"Item1 and Item2 has been transferred from branch1 to branch2" |
| 143 |
); |
156 |
); |
| 144 |
my @transferto = GetTransfersFromTo( undef, $samplebranch2->{branchcode} ); |
157 |
my @transferto = GetTransfersFromTo( undef, $branchcode_2 ); |
| 145 |
is_deeply( \@transferto, [], |
158 |
is_deeply( \@transferto, [], |
| 146 |
"GetTransfersfromTo without frombranch returns an empty array" ); |
159 |
"GetTransfersfromTo without frombranch returns an empty array" ); |
| 147 |
my @transferfrom = GetTransfersFromTo( $samplebranch1->{branchcode} ); |
160 |
my @transferfrom = GetTransfersFromTo( $branchcode_1 ); |
| 148 |
is_deeply( \@transferfrom, [], |
161 |
is_deeply( \@transferfrom, [], |
| 149 |
"GetTransfersfromTo without tobranch returns an empty array" ); |
162 |
"GetTransfersfromTo without tobranch returns an empty array" ); |
| 150 |
@transferfrom = GetTransfersFromTo(); |
163 |
@transferfrom = GetTransfersFromTo(); |
|
Lines 153-159
is_deeply( \@transferfrom, [],
Link Here
|
| 153 |
|
166 |
|
| 154 |
#Test DeleteBranchTransferLimits |
167 |
#Test DeleteBranchTransferLimits |
| 155 |
is( |
168 |
is( |
| 156 |
C4::Circulation::DeleteBranchTransferLimits( $samplebranch1->{branchcode} ), |
169 |
C4::Circulation::DeleteBranchTransferLimits( $branchcode_1 ), |
| 157 |
1, |
170 |
1, |
| 158 |
"A Branch TransferLimit has been deleted" |
171 |
"A Branch TransferLimit has been deleted" |
| 159 |
); |
172 |
); |
|
Lines 167-178
is(C4::Circulation::DeleteTransfer(),undef,"Without itemid DeleteTransfer return
Link Here
|
| 167 |
is(C4::Circulation::DeleteTransfer(-1),'0E0',"with a wrong itemid DeleteTranfer returns 0E0"); |
180 |
is(C4::Circulation::DeleteTransfer(-1),'0E0',"with a wrong itemid DeleteTranfer returns 0E0"); |
| 168 |
|
181 |
|
| 169 |
#Test TransferSlip |
182 |
#Test TransferSlip |
| 170 |
is( C4::Circulation::TransferSlip($samplebranch1->{branchcode}, undef, 5, $samplebranch2->{branchcode}), |
183 |
is( C4::Circulation::TransferSlip($branchcode_1, undef, 5, $branchcode_2), |
| 171 |
undef, "No tranferslip if invalid or undef itemnumber or barcode" ); |
184 |
undef, "No tranferslip if invalid or undef itemnumber or barcode" ); |
| 172 |
is( C4::Circulation::TransferSlip($samplebranch1->{branchcode}, $item_id1, 1, $samplebranch2->{branchcode})->{'code'}, |
185 |
is( C4::Circulation::TransferSlip($branchcode_1, $item_id1, 1, $branchcode_2)->{'code'}, |
| 173 |
'TRANSFERSLIP', "Get a transferslip on valid itemnumber and/or barcode" ); |
186 |
'TRANSFERSLIP', "Get a transferslip on valid itemnumber and/or barcode" ); |
| 174 |
cmp_deeply( |
187 |
cmp_deeply( |
| 175 |
C4::Circulation::TransferSlip($samplebranch1->{branchcode}, $item_id1, undef, $samplebranch2->{branchcode}), |
188 |
C4::Circulation::TransferSlip($branchcode_1, $item_id1, undef, $branchcode_2), |
| 176 |
C4::Circulation::TransferSlip($samplebranch1->{branchcode}, undef, 1, $samplebranch2->{branchcode}), |
189 |
C4::Circulation::TransferSlip($branchcode_1, undef, 1, $branchcode_2), |
| 177 |
"Barcode and itemnumber for same item both generate same TransferSlip" |
190 |
"Barcode and itemnumber for same item both generate same TransferSlip" |
| 178 |
); |
191 |
); |
| 179 |
- |
192 |
|
|
|
193 |
$schema->storage->txn_rollback; |
| 194 |
|
| 195 |
1; |