Bug 12461 - Add patron clubs feature
[koha.git] / t / db_dependent / Circulation / GetPendingOnSiteCheckouts.t
1 #!/usr/bin/perl
2
3 # This file is part of Koha.
4 #
5 # Koha is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
9 #
10 # Koha is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with Koha; if not, see <http://www.gnu.org/licenses>.
17
18 use Modern::Perl;
19
20 use Test::More tests => 2;
21 use Test::MockModule;
22 use t::lib::TestBuilder;
23
24 use C4::Biblio;
25 use C4::Circulation;
26 use C4::Items;
27 use C4::Members;
28
29 use Koha::Library;
30 use Koha::Libraries;
31 use Koha::Patron::Categories;
32
33 use MARC::Record;
34
35 my $schema = Koha::Database->schema;
36 $schema->storage->txn_begin;
37
38 my $builder = t::lib::TestBuilder->new;
39 my $dbh = C4::Context->dbh;
40
41 $dbh->do(q|DELETE FROM issues|);
42
43 my $branchcode = $builder->build({ source => 'Branch' })->{ branchcode };
44 my $itemtype   = $builder->build({ source => 'Itemtype' })->{ itemtype };
45
46 my %item_infos = (
47     homebranch    => $branchcode,
48     holdingbranch => $branchcode,
49     itype         => $itemtype
50 );
51
52 my ($biblionumber1) = AddBiblio(MARC::Record->new, '');
53 my $itemnumber1 = AddItem({ barcode => '0101', %item_infos }, $biblionumber1);
54 my $itemnumber2 = AddItem({ barcode => '0102', %item_infos }, $biblionumber1);
55
56 my ($biblionumber2) = AddBiblio(MARC::Record->new, '');
57 my $itemnumber3 = AddItem({ barcode => '0203', %item_infos }, $biblionumber2);
58
59 my $categorycode = $builder->build({ source => 'Category' })->{ categorycode };
60 my $borrowernumber = $builder->build(
61     {   source => 'Borrower',
62         value  => { categorycode => $categorycode, branchcode => $branchcode }
63     }
64 )->{borrowernumber};
65
66 my $borrower = GetMember(borrowernumber => $borrowernumber);
67
68 # Need to mock userenv for AddIssue
69 my $module = new Test::MockModule('C4::Context');
70 $module->mock('userenv', sub { { branch => $branchcode } });
71 AddIssue($borrower, '0101');
72 AddIssue($borrower, '0203');
73
74 # Begin tests...
75 my $onsite_checkouts = GetPendingOnSiteCheckouts;
76 is( scalar @$onsite_checkouts, 0, "No pending on-site checkouts" );
77
78 my $itemnumber4 = AddItem({ barcode => '0104', %item_infos }, $biblionumber1);
79 AddIssue( $borrower, '0104', undef, undef, undef, undef, { onsite_checkout => 1 } );
80 $onsite_checkouts = GetPendingOnSiteCheckouts;
81 is( scalar @$onsite_checkouts, 1, "There is 1 pending on-site checkout" );
82
83 $schema->storage->txn_rollback;
84
85 1;