Bug 25791: Remove win.print()
[koha.git] / t / db_dependent / Holds / LocalHoldsPriority.t
blob98ac219976df4bcb11aba2adc6ddcdc56a1b4120
1 #!/usr/bin/perl
3 use Modern::Perl;
5 use t::lib::Mocks;
6 use C4::Context;
8 use Test::More tests => 6;
9 use MARC::Record;
11 use Koha::Patrons;
12 use C4::Biblio;
13 use C4::Items;
14 use Koha::Database;
16 use t::lib::TestBuilder;
18 BEGIN {
19 use FindBin;
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 }
37 )->{itemtype};
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},
49 itype => $itemtype
51 )->store->itemnumber;
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
58 my @borrowernumbers;
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
70 my $i = 1;
71 foreach my $borrowernumber (@borrowernumbers) {
72 AddReserve(
74 branchcode => $branchcodes[$i],
75 borrowernumber => $borrowernumber,
76 biblionumber => $biblio->biblionumber,
77 priority => $i,
81 $i++;
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" );