Lines 1101-1107
subtest 'Tests for itemtype' => sub {
Link Here
|
1101 |
}; |
1101 |
}; |
1102 |
|
1102 |
|
1103 |
subtest 'get_transfers' => sub { |
1103 |
subtest 'get_transfers' => sub { |
1104 |
plan tests => 16; |
1104 |
plan tests => 17; |
1105 |
$schema->storage->txn_begin; |
1105 |
$schema->storage->txn_begin; |
1106 |
|
1106 |
|
1107 |
my $item = $builder->build_sample_item(); |
1107 |
my $item = $builder->build_sample_item(); |
Lines 1196-1201
subtest 'get_transfers' => sub {
Link Here
|
1196 |
$result_1 = $transfers->next; |
1196 |
$result_1 = $transfers->next; |
1197 |
is( $result_1->branchtransfer_id, $transfer_3->branchtransfer_id, 'Koha::Item->get_transfers returns the only transfer that remains'); |
1197 |
is( $result_1->branchtransfer_id, $transfer_3->branchtransfer_id, 'Koha::Item->get_transfers returns the only transfer that remains'); |
1198 |
|
1198 |
|
|
|
1199 |
subtest "Ensure prefetches don't affect the return order" => sub { |
1200 |
plan tests => 13; |
1201 |
|
1202 |
# Reset test data |
1203 |
$transfer_2->datesent(undef)->store; |
1204 |
$transfer_2->datearrived(undef)->store; |
1205 |
$transfer_1->datecancelled(undef)->store; |
1206 |
|
1207 |
my $prefetched_item = Koha::Items->search( |
1208 |
{ 'me.itemnumber' => $item->itemnumber }, |
1209 |
{ prefetch => ['current_branchtransfers'] } |
1210 |
)->next; |
1211 |
|
1212 |
$transfers = $prefetched_item->get_transfers(); |
1213 |
is( |
1214 |
$transfers->count, 3, |
1215 |
'When there are multiple open transfer requests, the Koha::Item::Transfers object contains them all' |
1216 |
); |
1217 |
$result_1 = $transfers->next; |
1218 |
$result_2 = $transfers->next; |
1219 |
$result_3 = $transfers->next; |
1220 |
is( |
1221 |
$result_1->branchtransfer_id, $transfer_1->branchtransfer_id, |
1222 |
'Koha::Item->get_transfers returns the oldest transfer request first' |
1223 |
); |
1224 |
is( |
1225 |
$result_2->branchtransfer_id, $transfer_2->branchtransfer_id, |
1226 |
'Koha::Item->get_transfers returns the newer transfer request second' |
1227 |
); |
1228 |
is( |
1229 |
$result_3->branchtransfer_id, $transfer_3->branchtransfer_id, |
1230 |
'Koha::Item->get_transfers returns the newest transfer request last' |
1231 |
); |
1232 |
|
1233 |
$transfer_2->datesent( \'NOW()' )->store; |
1234 |
$prefetched_item = Koha::Items->search( |
1235 |
{ 'me.itemnumber' => $item->itemnumber }, |
1236 |
{ prefetch => ['current_branchtransfers'] } |
1237 |
)->next; |
1238 |
$transfers = $prefetched_item->get_transfers(); |
1239 |
is( |
1240 |
$transfers->count, 3, |
1241 |
'When one transfer is set to in_transit, the Koha::Item::Transfers object still contains them all' |
1242 |
); |
1243 |
$result_1 = $transfers->next; |
1244 |
$result_2 = $transfers->next; |
1245 |
$result_3 = $transfers->next; |
1246 |
is( |
1247 |
$result_1->branchtransfer_id, $transfer_2->branchtransfer_id, |
1248 |
'Koha::Item->get_transfers returns the active transfer request first' |
1249 |
); |
1250 |
is( |
1251 |
$result_2->branchtransfer_id, $transfer_1->branchtransfer_id, |
1252 |
'Koha::Item->get_transfers returns the other transfers oldest to newest' |
1253 |
); |
1254 |
is( |
1255 |
$result_3->branchtransfer_id, $transfer_3->branchtransfer_id, |
1256 |
'Koha::Item->get_transfers returns the other transfers oldest to newest' |
1257 |
); |
1258 |
|
1259 |
$transfer_2->datearrived( \'NOW()' )->store; |
1260 |
$prefetched_item = Koha::Items->search( |
1261 |
{ 'me.itemnumber' => $item->itemnumber }, |
1262 |
{ prefetch => ['current_branchtransfers'] } |
1263 |
)->next; |
1264 |
$transfers = $prefetched_item->get_transfers(); |
1265 |
is( |
1266 |
$transfers->count, 2, |
1267 |
'Once a transfer is received, it no longer appears in the list from ->get_transfers()' |
1268 |
); |
1269 |
$result_1 = $transfers->next; |
1270 |
$result_2 = $transfers->next; |
1271 |
is( |
1272 |
$result_1->branchtransfer_id, $transfer_1->branchtransfer_id, |
1273 |
'Koha::Item->get_transfers returns the other transfers oldest to newest' |
1274 |
); |
1275 |
is( |
1276 |
$result_2->branchtransfer_id, $transfer_3->branchtransfer_id, |
1277 |
'Koha::Item->get_transfers returns the other transfers oldest to newest' |
1278 |
); |
1279 |
|
1280 |
$transfer_1->datecancelled( \'NOW()' )->store; |
1281 |
$prefetched_item = Koha::Items->search( |
1282 |
{ 'me.itemnumber' => $item->itemnumber }, |
1283 |
{ prefetch => ['current_branchtransfers'] } |
1284 |
)->next; |
1285 |
$transfers = $prefetched_item->get_transfers(); |
1286 |
is( |
1287 |
$transfers->count, 1, |
1288 |
'Once a transfer is cancelled, it no longer appears in the list from ->get_transfers()' |
1289 |
); |
1290 |
$result_1 = $transfers->next; |
1291 |
is( |
1292 |
$result_1->branchtransfer_id, $transfer_3->branchtransfer_id, |
1293 |
'Koha::Item->get_transfers returns the only transfer that remains' |
1294 |
); |
1295 |
}; |
1296 |
|
1199 |
$schema->storage->txn_rollback; |
1297 |
$schema->storage->txn_rollback; |
1200 |
}; |
1298 |
}; |
1201 |
|
1299 |
|
1202 |
- |
|
|