|
Lines 25-31
use Koha::Database;
Link Here
|
| 25 |
use Koha::Item::Transfer; |
25 |
use Koha::Item::Transfer; |
| 26 |
use t::lib::TestBuilder; |
26 |
use t::lib::TestBuilder; |
| 27 |
|
27 |
|
| 28 |
use Test::More tests => 8; |
28 |
use Test::More tests => 9; |
| 29 |
|
29 |
|
| 30 |
my $schema = Koha::Database->new->schema; |
30 |
my $schema = Koha::Database->new->schema; |
| 31 |
|
31 |
|
|
Lines 390-393
subtest "Tests for investigate (singular)." => sub {
Link Here
|
| 390 |
$schema->storage->txn_rollback; |
390 |
$schema->storage->txn_rollback; |
| 391 |
}; |
391 |
}; |
| 392 |
|
392 |
|
|
|
393 |
subtest "Tests for toggle_indemand" => sub { |
| 394 |
plan tests => 15; |
| 395 |
$schema->storage->txn_begin; |
| 396 |
|
| 397 |
my $sritem = $builder->build({ |
| 398 |
source => 'Stockrotationitem', |
| 399 |
value => { 'fresh' => 0, 'indemand' => 0 } |
| 400 |
}); |
| 401 |
my $dbitem = Koha::StockRotationItems->find($sritem->{itemnumber_id}); |
| 402 |
my $firstbranch = $dbitem->stage->branchcode_id; |
| 403 |
$dbitem->itemnumber->holdingbranch($firstbranch)->store; |
| 404 |
my $dbstage = $dbitem->stage; |
| 405 |
$dbstage->position(1)->duration(50)->store; # Configure stage. |
| 406 |
# Configure item |
| 407 |
$dbitem->itemnumber->holdingbranch($firstbranch)->store; |
| 408 |
$dbitem->itemnumber->homebranch($firstbranch)->store; |
| 409 |
# Sanity check |
| 410 |
is($dbitem->stage->stage_id, $dbstage->stage_id, "Stage sanity check."); |
| 411 |
|
| 412 |
# Test if an item is not in transfer, toggle always acts. |
| 413 |
is($dbitem->indemand, 0, "Item not in transfer starts with indemand disabled."); |
| 414 |
$dbitem->toggle_indemand; |
| 415 |
is($dbitem->indemand, 1, "Item not in transfer toggled correctly first time."); |
| 416 |
$dbitem->toggle_indemand; |
| 417 |
is($dbitem->indemand, 0, "Item not in transfer toggled correctly second time."); |
| 418 |
|
| 419 |
# Add stages |
| 420 |
my $srstage = $builder->build({ |
| 421 |
source => 'Stockrotationstage', |
| 422 |
value => { duration => 50 } |
| 423 |
}); |
| 424 |
my $dbstage2 = Koha::StockRotationStages->find($srstage->{stage_id}); |
| 425 |
$dbstage2->move_to_group($dbitem->stage->rota_id); |
| 426 |
$dbstage2->position(2)->store; |
| 427 |
my $secondbranch = $dbstage2->branchcode_id; |
| 428 |
|
| 429 |
# Test an item in transfer, toggle cancels transfer and resets indemand. |
| 430 |
ok($dbitem->advance, "Advancement done."); |
| 431 |
$dbitem->get_from_storage; |
| 432 |
my $transfer = $dbitem->itemnumber->get_transfer; |
| 433 |
is(ref($transfer), 'Koha::Item::Transfer', 'Item set to in transfer as expected'); |
| 434 |
is($transfer->frombranch, $firstbranch, 'Transfer from set correctly'); |
| 435 |
is($transfer->tobranch, $secondbranch, 'Transfer to set correctly'); |
| 436 |
is($transfer->datearrived, undef, 'Transfer datearrived not set'); |
| 437 |
$dbitem->toggle_indemand; |
| 438 |
my $updated_transfer = $transfer->get_from_storage; |
| 439 |
is($updated_transfer->frombranch, $firstbranch, 'Transfer from retained correctly'); |
| 440 |
is($updated_transfer->tobranch, $firstbranch, 'Transfer to updated correctly'); |
| 441 |
isnt($updated_transfer->datearrived, undef, 'Transfer datearrived set as expected'); |
| 442 |
is($dbitem->indemand, 0, "Item retains indemand as expected."); |
| 443 |
is($dbitem->stage_id, $dbstage->id, 'Item stage reset as expected.'); |
| 444 |
is($dbitem->itemnumber->homebranch, $firstbranch, 'Item homebranch reset as expected.'); |
| 445 |
|
| 446 |
$schema->storage->txn_rollback; |
| 447 |
}; |
| 448 |
|
| 393 |
1; |
449 |
1; |
| 394 |
- |
|
|