8 use Test
::More tests
=> 6;
16 use t
::lib
::TestBuilder
;
20 use lib
$FindBin::Bin
;
21 use_ok
('C4::Reserves');
24 my $schema = Koha
::Database
->schema;
25 $schema->storage->txn_begin;
27 my $builder = t
::lib
::TestBuilder
->new;
29 my $library1 = $builder->build({ source
=> 'Branch', });
30 my $library2 = $builder->build({ source
=> 'Branch', });
31 my $library3 = $builder->build({ source
=> 'Branch', });
32 my $library4 = $builder->build({ source
=> 'Branch', });
33 my $itemtype = $builder->build(
34 { source
=> 'Itemtype',
35 value
=> { notforloan
=> undef, rentalcharge
=> 0 }
41 my $borrowers_count = 5;
43 my $biblio = $builder->build_sample_biblio();
44 my $itemnumber = Koha
::Item
->new(
46 biblionumber
=> $biblio->biblionumber,
47 homebranch
=> $library4->{branchcode
},
48 holdingbranch
=> $library3->{branchcode
},
54 my @branchcodes = ( $library1->{branchcode
}, $library2->{branchcode
}, $library3->{branchcode
}, $library4->{branchcode
}, $library3->{branchcode
}, $library4->{branchcode
} );
56 my $patron_category = $builder->build({ source
=> 'Category' });
57 # Create some borrowers
59 foreach ( 1 .. $borrowers_count ) {
60 my $borrowernumber = Koha
::Patron
->new({
61 firstname
=> 'my firstname',
62 surname
=> 'my surname ' . $_,
63 categorycode
=> $patron_category->{categorycode
},
64 branchcode
=> $branchcodes[$_],
65 })->store->borrowernumber;
66 push @borrowernumbers, $borrowernumber;
69 # Create five item level holds
71 foreach my $borrowernumber (@borrowernumbers) {
74 branchcode
=> $branchcodes[$i],
75 borrowernumber
=> $borrowernumber,
76 biblionumber
=> $biblio->biblionumber,
84 my ($status, $reserve, $all_reserves);
86 t
::lib
::Mocks
::mock_preference
( 'LocalHoldsPriority', 0 );
87 ($status, $reserve, $all_reserves) = CheckReserves
($itemnumber);
88 ok
( $reserve->{borrowernumber
} eq $borrowernumbers[0], "Received expected results with LocalHoldsPriority disabled" );
90 t
::lib
::Mocks
::mock_preference
( 'LocalHoldsPriority', 1 );
92 t
::lib
::Mocks
::mock_preference
( 'LocalHoldsPriorityPatronControl', 'PickupLibrary' );
93 t
::lib
::Mocks
::mock_preference
( 'LocalHoldsPriorityItemControl', 'homebranch' );
94 ($status, $reserve, $all_reserves) = CheckReserves
($itemnumber);
95 ok
( $reserve->{borrowernumber
} eq $borrowernumbers[2], "Received expected results with PickupLibrary/homebranch" );
97 t
::lib
::Mocks
::mock_preference
( 'LocalHoldsPriorityPatronControl', 'PickupLibrary' );
98 t
::lib
::Mocks
::mock_preference
( 'LocalHoldsPriorityItemControl', 'holdingbranch' );
99 ($status, $reserve, $all_reserves) = CheckReserves
($itemnumber);
100 ok
( $reserve->{borrowernumber
} eq $borrowernumbers[1], "Received expected results with PickupLibrary/holdingbranch" );
102 t
::lib
::Mocks
::mock_preference
( 'LocalHoldsPriorityPatronControl', 'HomeLibrary' );
103 t
::lib
::Mocks
::mock_preference
( 'LocalHoldsPriorityItemControl', 'holdingbranch' );
104 ($status, $reserve, $all_reserves) = CheckReserves
($itemnumber);
105 ok
( $reserve->{borrowernumber
} eq $borrowernumbers[1], "Received expected results with HomeLibrary/holdingbranch" );
107 t
::lib
::Mocks
::mock_preference
( 'LocalHoldsPriorityPatronControl', 'HomeLibrary' );
108 t
::lib
::Mocks
::mock_preference
( 'LocalHoldsPriorityItemControl', 'homebranch' );
109 ($status, $reserve, $all_reserves) = CheckReserves
($itemnumber);
110 ok
( $reserve->{borrowernumber
} eq $borrowernumbers[2], "Received expected results with HomeLibrary/homebranch" );