Lines 28-34
use Koha::Item::Transfer;
Link Here
|
28 |
use t::lib::TestBuilder; |
28 |
use t::lib::TestBuilder; |
29 |
use t::lib::Mocks; |
29 |
use t::lib::Mocks; |
30 |
|
30 |
|
31 |
use Test::More tests => 8; |
31 |
use Test::More tests => 9; |
32 |
|
32 |
|
33 |
my $schema = Koha::Database->new->schema; |
33 |
my $schema = Koha::Database->new->schema; |
34 |
|
34 |
|
Lines 649-652
subtest "Tests for investigate (singular)." => sub {
Link Here
|
649 |
$schema->storage->txn_rollback; |
649 |
$schema->storage->txn_rollback; |
650 |
}; |
650 |
}; |
651 |
|
651 |
|
|
|
652 |
subtest "Tests for toggle_indemand" => sub { |
653 |
plan tests => 15; |
654 |
$schema->storage->txn_begin; |
655 |
|
656 |
my $sritem = $builder->build({ |
657 |
source => 'Stockrotationitem', |
658 |
value => { 'fresh' => 0, 'indemand' => 0 } |
659 |
}); |
660 |
my $dbitem = Koha::StockRotationItems->find($sritem->{itemnumber_id}); |
661 |
my $firstbranch = $dbitem->stage->branchcode_id; |
662 |
$dbitem->itemnumber->holdingbranch($firstbranch)->store; |
663 |
my $dbstage = $dbitem->stage; |
664 |
$dbstage->position(1)->duration(50)->store; # Configure stage. |
665 |
# Configure item |
666 |
$dbitem->itemnumber->holdingbranch($firstbranch)->store; |
667 |
$dbitem->itemnumber->homebranch($firstbranch)->store; |
668 |
# Sanity check |
669 |
is($dbitem->stage->stage_id, $dbstage->stage_id, "Stage sanity check."); |
670 |
|
671 |
# Test if an item is not in transfer, toggle always acts. |
672 |
is($dbitem->indemand, 0, "Item not in transfer starts with indemand disabled."); |
673 |
$dbitem->toggle_indemand; |
674 |
is($dbitem->indemand, 1, "Item not in transfer toggled correctly first time."); |
675 |
$dbitem->toggle_indemand; |
676 |
is($dbitem->indemand, 0, "Item not in transfer toggled correctly second time."); |
677 |
|
678 |
# Add stages |
679 |
my $srstage = $builder->build({ |
680 |
source => 'Stockrotationstage', |
681 |
value => { duration => 50 } |
682 |
}); |
683 |
my $dbstage2 = Koha::StockRotationStages->find($srstage->{stage_id}); |
684 |
$dbstage2->move_to_group($dbitem->stage->rota_id); |
685 |
$dbstage2->position(2)->store; |
686 |
my $secondbranch = $dbstage2->branchcode_id; |
687 |
|
688 |
# Test an item in transfer, toggle cancels transfer and resets indemand. |
689 |
ok($dbitem->advance, "Advancement done."); |
690 |
$dbitem->get_from_storage; |
691 |
my $transfer = $dbitem->itemnumber->get_transfer; |
692 |
is(ref($transfer), 'Koha::Item::Transfer', 'Item set to in transfer as expected'); |
693 |
is($transfer->frombranch, $firstbranch, 'Transfer from set correctly'); |
694 |
is($transfer->tobranch, $secondbranch, 'Transfer to set correctly'); |
695 |
is($transfer->datearrived, undef, 'Transfer datearrived not set'); |
696 |
$dbitem->toggle_indemand; |
697 |
my $updated_transfer = $transfer->get_from_storage; |
698 |
is($updated_transfer->frombranch, $firstbranch, 'Transfer from retained correctly'); |
699 |
is($updated_transfer->tobranch, $firstbranch, 'Transfer to updated correctly'); |
700 |
isnt($updated_transfer->datearrived, undef, 'Transfer datearrived set as expected'); |
701 |
is($dbitem->indemand, 0, "Item retains indemand as expected."); |
702 |
is($dbitem->stage_id, $dbstage->id, 'Item stage reset as expected.'); |
703 |
is($dbitem->itemnumber->homebranch, $firstbranch, 'Item homebranch reset as expected.'); |
704 |
|
705 |
$schema->storage->txn_rollback; |
706 |
}; |
707 |
|
652 |
1; |
708 |
1; |
653 |
- |
|
|