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

(-)a/t/db_dependent/Koha/Item/Transfers.t (-1 / +40 lines)
Lines 19-25 Link Here
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Test::More tests => 2;
22
use Test::More tests => 3;
23
23
24
use Koha::Item::Transfer;
24
use Koha::Item::Transfer;
25
use Koha::Item::Transfers;
25
use Koha::Item::Transfers;
Lines 66-68 is( $retrieved_transfer_1->itemnumber, $new_transfer_1->itemnumber, 'Find a tran Link Here
66
66
67
$schema->storage->txn_rollback;
67
$schema->storage->txn_rollback;
68
68
69
subtest 'item() tests' => sub {
70
71
    plan tests => 2;
72
73
    $schema->storage->txn_begin;
74
75
    my $library_from = $builder->build( { source => 'Branch' } );
76
    my $library_to   = $builder->build( { source => 'Branch' } );
77
    my $item         = $builder->build(
78
        {
79
            source => 'Item',
80
            value  => {
81
                holding_branch => $library_from->{branchcode},
82
                homebranch     => $library_to->{branchcode}
83
            }
84
        }
85
    );
86
87
    my $transfer = Koha::Item::Transfer->new(
88
        {
89
            itemnumber  => $item->{itemnumber},
90
            frombranch  => $library_from->{branchcode},
91
            tobranch    => $library_to->{branchcode},
92
            datearrived => dt_from_string,
93
            datesent    => dt_from_string,
94
        }
95
    )->store;
96
97
    my $transfer_item = $transfer->item;
98
    is( ref($transfer_item), 'Koha::Item',
99
        'Koha::Item::Transfer->item should return a Koha::Item' );
100
    is(
101
        $transfer->itemnumber,
102
        $transfer_item->itemnumber,
103
        'Koha::Item::Transfer->item should return the correct item'
104
    );
105
106
    $schema->storage->txn_rollback;
107
};
(-)a/t/db_dependent/Koha/Libraries.t (-1 / +36 lines)
Lines 19-25 Link Here
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Test::More tests => 8;
22
use Test::More tests => 9;
23
23
24
use C4::Biblio;
24
use C4::Biblio;
25
use C4::Context;
25
use C4::Context;
Lines 468-470 subtest 'cash_registers' => sub { Link Here
468
468
469
    $schema->storage->txn_rollback;
469
    $schema->storage->txn_rollback;
470
};
470
};
471
472
subtest 'outgoing_transfers' => sub {
473
    plan tests => 3;
474
475
    $schema->storage->txn_begin;
476
477
    my $library = $builder->build_object( { class => 'Koha::Libraries' } );
478
    my $transfer1 = $builder->build_object(
479
        {
480
            class => 'Koha::Item::Transfers',
481
            value  => { frombranch => $library->branchcode },
482
        }
483
    );
484
    my $transfer2 = $builder->build_object(
485
        {
486
            class => 'Koha::Item::Transfers',
487
            value  => { frombranch => $library->branchcode },
488
        }
489
    );
490
491
    my $outgoing_transfers = $library->outgoing_transfers;
492
    is( ref($outgoing_transfers), 'Koha::Item::Transfers',
493
'Koha::Library->outgoing_transfers should return a set of Koha::Item::Transfers'
494
    );
495
    is( $outgoing_transfers->count, 2,
496
        'Koha::Library->outgoing_transfers should return the correct transfers'
497
    );
498
499
    $transfer1->delete;
500
    is( $library->outgoing_transfers->next->id, $transfer2->id,
501
        'Koha::Library->outgoing_transfers should return the correct cash registers'
502
    );
503
504
    $schema->storage->txn_rollback;
505
};
(-)a/t/db_dependent/StockRotationItems.t (-2 / +57 lines)
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
- 

Return to bug 22569