View | Details | Raw Unified | Return to bug 22569
Collapse All | Expand All

(-)a/t/db_dependent/Koha/Item/Transfers.t (-1 / +1 lines)
Lines 19-25 Link Here
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Test::More tests => 3;
22
use Test::More tests => 4;
23
23
24
use Koha::Item::Transfer;
24
use Koha::Item::Transfer;
25
use Koha::Item::Transfers;
25
use Koha::Item::Transfers;
(-)a/t/db_dependent/Koha/Libraries.t (+35 lines)
Lines 226-228 subtest 'get_hold_libraries and validate_hold_sibling' => sub { Link Here
226
    $schema->storage->txn_rollback;
226
    $schema->storage->txn_rollback;
227
227
228
};
228
};
229
230
subtest 'outgoing_transfers' => sub {
231
    plan tests => 3;
232
233
    $schema->storage->txn_begin;
234
235
    my $library = $builder->build_object( { class => 'Koha::Libraries' } );
236
    my $transfer1 = $builder->build_object(
237
        {
238
            class => 'Koha::Item::Transfers',
239
            value  => { frombranch => $library->branchcode },
240
        }
241
    );
242
    my $transfer2 = $builder->build_object(
243
        {
244
            class => 'Koha::Item::Transfers',
245
            value  => { frombranch => $library->branchcode },
246
        }
247
    );
248
249
    my $outgoing_transfers = $library->outgoing_transfers;
250
    is( ref($outgoing_transfers), 'Koha::Item::Transfers',
251
'Koha::Library->outgoing_transfers should return a set of Koha::Item::Transfers'
252
    );
253
    is( $outgoing_transfers->count, 2,
254
        'Koha::Library->outgoing_transfers should return the correct transfers'
255
    );
256
257
    $transfer1->delete;
258
    is( $library->outgoing_transfers->next->id, $transfer2->id,
259
        'Koha::Library->outgoing_transfers should return the correct cash registers'
260
    );
261
262
    $schema->storage->txn_rollback;
263
};
(-)a/t/db_dependent/StockRotationItems.t (-2 / +57 lines)
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 423-426 subtest "Tests for investigate (singular)." => sub { Link Here
423
    $schema->storage->txn_rollback;
423
    $schema->storage->txn_rollback;
424
};
424
};
425
425
426
subtest "Tests for toggle_indemand" => sub {
427
    plan tests => 15;
428
    $schema->storage->txn_begin;
429
430
    my $sritem = $builder->build({
431
        source => 'Stockrotationitem',
432
        value => { 'fresh' => 0, 'indemand' => 0 }
433
    });
434
    my $dbitem = Koha::StockRotationItems->find($sritem->{itemnumber_id});
435
    my $firstbranch = $dbitem->stage->branchcode_id;
436
    $dbitem->itemnumber->holdingbranch($firstbranch)->store;
437
    my $dbstage = $dbitem->stage;
438
    $dbstage->position(1)->duration(50)->store; # Configure stage.
439
    # Configure item
440
    $dbitem->itemnumber->holdingbranch($firstbranch)->store;
441
    $dbitem->itemnumber->homebranch($firstbranch)->store;
442
    # Sanity check
443
    is($dbitem->stage->stage_id, $dbstage->stage_id, "Stage sanity check.");
444
445
    # Test if an item is not in transfer, toggle always acts.
446
    is($dbitem->indemand, 0, "Item not in transfer starts with indemand disabled.");
447
    $dbitem->toggle_indemand;
448
    is($dbitem->indemand, 1, "Item not in transfer toggled correctly first time.");
449
    $dbitem->toggle_indemand;
450
    is($dbitem->indemand, 0, "Item not in transfer toggled correctly second time.");
451
452
    # Add stages
453
    my $srstage = $builder->build({
454
        source => 'Stockrotationstage',
455
        value => { duration => 50 }
456
    });
457
    my $dbstage2 = Koha::StockRotationStages->find($srstage->{stage_id});
458
    $dbstage2->move_to_group($dbitem->stage->rota_id);
459
    $dbstage2->position(2)->store;
460
    my $secondbranch = $dbstage2->branchcode_id;
461
462
    # Test an item in transfer, toggle cancels transfer and resets indemand.
463
    ok($dbitem->advance, "Advancement done.");
464
    $dbitem->get_from_storage;
465
    my $transfer = $dbitem->itemnumber->get_transfer;
466
    is(ref($transfer), 'Koha::Item::Transfer', 'Item set to in transfer as expected');
467
    is($transfer->frombranch, $firstbranch, 'Transfer from set correctly');
468
    is($transfer->tobranch, $secondbranch, 'Transfer to set correctly');
469
    is($transfer->datearrived, undef, 'Transfer datearrived not set');
470
    $dbitem->toggle_indemand;
471
    my $updated_transfer = $transfer->get_from_storage;
472
    is($updated_transfer->frombranch, $firstbranch, 'Transfer from retained correctly');
473
    is($updated_transfer->tobranch, $firstbranch, 'Transfer to updated correctly');
474
    isnt($updated_transfer->datearrived, undef, 'Transfer datearrived set as expected');
475
    is($dbitem->indemand, 0, "Item retains indemand as expected.");
476
    is($dbitem->stage_id, $dbstage->id, 'Item stage reset as expected.');
477
    is($dbitem->itemnumber->homebranch, $firstbranch, 'Item homebranch reset as expected.');
478
479
    $schema->storage->txn_rollback;
480
};
481
426
1;
482
1;
427
- 

Return to bug 22569