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