Bug 19116: Unit tests

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
(cherry picked from commit 021d1d3714)
Signed-off-by: Fridolin Somers <fridolin.somers@biblibre.com>
This commit is contained in:
Jonathan Druart 2017-09-04 14:14:31 -03:00 committed by Fridolin Somers
parent 2b4d0cb0b4
commit bc3bfeab37
1 changed files with 48 additions and 1 deletions

View File

@ -17,7 +17,7 @@
use Modern::Perl;
use Test::More tests => 97;
use Test::More tests => 98;
use DateTime;
@ -1635,6 +1635,53 @@ subtest 'AddReturn + CumulativeRestrictionPeriods' => sub {
is( $debarments->[0]->{expiration}, $expected_expiration );
};
subtest 'Set waiting flag' => sub {
plan tests => 2;
my $library_1 = $builder->build( { source => 'Branch' } );
my $patron_1 = $builder->build( { source => 'Borrower', value => { branchcode => $library_1->{branchcode} } } );
my $library_2 = $builder->build( { source => 'Branch' } );
my $patron_2 = $builder->build( { source => 'Borrower', value => { branchcode => $library_2->{branchcode} } } );
my $biblio = $builder->build( { source => 'Biblio' } );
my $biblioitem = $builder->build( { source => 'Biblioitem', value => { biblionumber => $biblio->{biblionumber} } } );
my $item = $builder->build(
{
source => 'Item',
value => {
homebranch => $library_1->{branchcode},
holdingbranch => $library_1->{branchcode},
notforloan => 0,
itemlost => 0,
withdrawn => 0,
biblionumber => $biblioitem->{biblionumber},
}
}
);
set_userenv( $library_2 );
my $reserve_id = AddReserve(
$library_2->{branchcode}, $patron_2->{borrowernumber}, $biblioitem->{biblionumber},
'', 1, undef, undef, '', undef, $item->{itemnumber},
);
set_userenv( $library_1 );
my $do_transfer = 1;
my ( $res, $rr ) = AddReturn( $item->{barcode}, $library_1->{branchcode} );
ModReserveAffect( $item->{itemnumber}, undef, $do_transfer, $reserve_id );
my $hold = Koha::Holds->find( $reserve_id );
is( $hold->found, 'T', 'Hold is in transit' );
set_userenv( $library_2 );
$do_transfer = 0;
AddReturn( $item->{barcode}, $library_2->{branchcode} );
ModReserveAffect( $item->{itemnumber}, undef, $do_transfer, $reserve_id );
$hold = Koha::Holds->find( $reserve_id );
is( $hold->found, 'W', 'Hold is waiting' );
};
sub set_userenv {
my ( $library ) = @_;
C4::Context->set_userenv(0,0,0,'firstname','surname', $library->{branchcode}, $library->{branchname}, '', '', '');