|
Lines 26-32
use Koha::DateUtils;
Link Here
|
| 26 |
use Koha::Item::Transfer; |
26 |
use Koha::Item::Transfer; |
| 27 |
use t::lib::TestBuilder; |
27 |
use t::lib::TestBuilder; |
| 28 |
|
28 |
|
| 29 |
use Test::More tests => 8; |
29 |
use Test::More tests => 9; |
| 30 |
|
30 |
|
| 31 |
my $schema = Koha::Database->new->schema; |
31 |
my $schema = Koha::Database->new->schema; |
| 32 |
|
32 |
|
|
Lines 500-503
subtest "Tests for investigate (singular)." => sub {
Link Here
|
| 500 |
$schema->storage->txn_rollback; |
500 |
$schema->storage->txn_rollback; |
| 501 |
}; |
501 |
}; |
| 502 |
|
502 |
|
|
|
503 |
subtest "Tests for toggle_indemand" => sub { |
| 504 |
plan tests => 15; |
| 505 |
$schema->storage->txn_begin; |
| 506 |
|
| 507 |
my $sritem = $builder->build({ |
| 508 |
source => 'Stockrotationitem', |
| 509 |
value => { 'fresh' => 0, 'indemand' => 0 } |
| 510 |
}); |
| 511 |
my $dbitem = Koha::StockRotationItems->find($sritem->{itemnumber_id}); |
| 512 |
my $firstbranch = $dbitem->stage->branchcode_id; |
| 513 |
$dbitem->itemnumber->holdingbranch($firstbranch)->store; |
| 514 |
my $dbstage = $dbitem->stage; |
| 515 |
$dbstage->position(1)->duration(50)->store; # Configure stage. |
| 516 |
# Configure item |
| 517 |
$dbitem->itemnumber->holdingbranch($firstbranch)->store; |
| 518 |
$dbitem->itemnumber->homebranch($firstbranch)->store; |
| 519 |
# Sanity check |
| 520 |
is($dbitem->stage->stage_id, $dbstage->stage_id, "Stage sanity check."); |
| 521 |
|
| 522 |
# Test if an item is not in transfer, toggle always acts. |
| 523 |
is($dbitem->indemand, 0, "Item not in transfer starts with indemand disabled."); |
| 524 |
$dbitem->toggle_indemand; |
| 525 |
is($dbitem->indemand, 1, "Item not in transfer toggled correctly first time."); |
| 526 |
$dbitem->toggle_indemand; |
| 527 |
is($dbitem->indemand, 0, "Item not in transfer toggled correctly second time."); |
| 528 |
|
| 529 |
# Add stages |
| 530 |
my $srstage = $builder->build({ |
| 531 |
source => 'Stockrotationstage', |
| 532 |
value => { duration => 50 } |
| 533 |
}); |
| 534 |
my $dbstage2 = Koha::StockRotationStages->find($srstage->{stage_id}); |
| 535 |
$dbstage2->move_to_group($dbitem->stage->rota_id); |
| 536 |
$dbstage2->position(2)->store; |
| 537 |
my $secondbranch = $dbstage2->branchcode_id; |
| 538 |
|
| 539 |
# Test an item in transfer, toggle cancels transfer and resets indemand. |
| 540 |
ok($dbitem->advance, "Advancement done."); |
| 541 |
$dbitem->get_from_storage; |
| 542 |
my $transfer = $dbitem->itemnumber->get_transfer; |
| 543 |
is(ref($transfer), 'Koha::Item::Transfer', 'Item set to in transfer as expected'); |
| 544 |
is($transfer->frombranch, $firstbranch, 'Transfer from set correctly'); |
| 545 |
is($transfer->tobranch, $secondbranch, 'Transfer to set correctly'); |
| 546 |
is($transfer->datearrived, undef, 'Transfer datearrived not set'); |
| 547 |
$dbitem->toggle_indemand; |
| 548 |
my $updated_transfer = $transfer->get_from_storage; |
| 549 |
is($updated_transfer->frombranch, $firstbranch, 'Transfer from retained correctly'); |
| 550 |
is($updated_transfer->tobranch, $firstbranch, 'Transfer to updated correctly'); |
| 551 |
isnt($updated_transfer->datearrived, undef, 'Transfer datearrived set as expected'); |
| 552 |
is($dbitem->indemand, 0, "Item retains indemand as expected."); |
| 553 |
is($dbitem->stage_id, $dbstage->id, 'Item stage reset as expected.'); |
| 554 |
is($dbitem->itemnumber->homebranch, $firstbranch, 'Item homebranch reset as expected.'); |
| 555 |
|
| 556 |
$schema->storage->txn_rollback; |
| 557 |
}; |
| 558 |
|
| 503 |
1; |
559 |
1; |
| 504 |
- |
|
|