|
Lines 24-30
use Koha::DateUtils qw( dt_from_string );
Link Here
|
| 24 |
|
24 |
|
| 25 |
use t::lib::TestBuilder; |
25 |
use t::lib::TestBuilder; |
| 26 |
|
26 |
|
| 27 |
use Test::More tests => 7; |
27 |
use Test::More tests => 8; |
| 28 |
use Test::Exception; |
28 |
use Test::Exception; |
| 29 |
|
29 |
|
| 30 |
my $schema = Koha::Database->new->schema; |
30 |
my $schema = Koha::Database->new->schema; |
|
Lines 311-313
subtest 'cancel tests' => sub {
Link Here
|
| 311 |
|
311 |
|
| 312 |
$schema->storage->txn_rollback; |
312 |
$schema->storage->txn_rollback; |
| 313 |
}; |
313 |
}; |
| 314 |
- |
314 |
|
|
|
315 |
subtest 'remedy tests' => sub { |
| 316 |
plan tests => 10; |
| 317 |
|
| 318 |
$schema->storage->txn_begin; |
| 319 |
|
| 320 |
my $library1 = $builder->build_object( { class => 'Koha::Libraries' } ); |
| 321 |
my $library2 = $builder->build_object( { class => 'Koha::Libraries' } ); |
| 322 |
my $library3 = $builder->build_object( { class => 'Koha::Libraries' } ); |
| 323 |
my $item = $builder->build_sample_item( |
| 324 |
{ |
| 325 |
homebranch => $library1->branchcode, |
| 326 |
holdingbranch => $library2->branchcode, |
| 327 |
datelastseen => undef |
| 328 |
} |
| 329 |
); |
| 330 |
|
| 331 |
my $reason = 'WrongTransfer'; |
| 332 |
my $transfer = $builder->build_object( |
| 333 |
{ |
| 334 |
class => 'Koha::Item::Transfers', |
| 335 |
value => { |
| 336 |
itemnumber => $item->itemnumber, |
| 337 |
frombranch => $library2->branchcode, |
| 338 |
tobranch => $library1->branchcode, |
| 339 |
daterequested => \'NOW()', |
| 340 |
datesent => \'NOW()', |
| 341 |
datearrived => undef, |
| 342 |
datecancelled => undef, |
| 343 |
reason => 'Manual', |
| 344 |
cancellation_reason => undef |
| 345 |
} |
| 346 |
} |
| 347 |
); |
| 348 |
is( ref($transfer), 'Koha::Item::Transfer', 'Mock transfer added' ); |
| 349 |
|
| 350 |
# Item return updates holding branch |
| 351 |
$item->holdingbranch($library3->branchcode)->store(); |
| 352 |
|
| 353 |
# Successful remedy |
| 354 |
my $remedy_transfer = $transfer->remedy(); |
| 355 |
is( ref($remedy_transfer), 'Koha::Item::Transfer', |
| 356 |
'Koha::Item::Transfer->remedy should return a new Koha::Item::Transfer object' |
| 357 |
); |
| 358 |
ok( !$remedy_transfer->in_transit, "Remedy transfer is NOT created as in transit (or cancelled)"); |
| 359 |
is( $remedy_transfer->itemnumber, $transfer->itemnumber, "Remedy transfer is for the same item"); |
| 360 |
is( $remedy_transfer->frombranch, $library3->branchcode, "Remedy transfer is from the items updated holdingbranch"); |
| 361 |
is( $remedy_transfer->tobranch, $transfer->tobranch, "Remedy transer is to the same to branch"); |
| 362 |
is( $remedy_transfer->reason, $transfer->reason, "Remedy transfer has the same reason"); |
| 363 |
is( $remedy_transfer->comments, $transfer->comments, "Remedy transfer has the same comments"); |
| 364 |
|
| 365 |
my $original_transfer = $transfer->get_from_storage; |
| 366 |
ok( defined($original_transfer->datecancelled), "Original transfer was cancelled"); |
| 367 |
is( $original_transfer->cancellation_reason, 'WrongTransfer', "Original transfer cancellation reason is 'WrongTransfer'"); |
| 368 |
|
| 369 |
$schema->storage->txn_rollback; |
| 370 |
}; |