]> git.koha-community.org Git - koha.git/blob - t/db_dependent/Circulation/GetIssues.t
Bug 17636: Remove itemtype-related GetIssues.t warnings
[koha.git] / t / db_dependent / Circulation / GetIssues.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 => 10;
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 $issues;
76 $issues = C4::Circulation::GetIssues({biblionumber => $biblionumber1});
77 is(scalar @$issues, 1, "Biblio $biblionumber1 has 1 item issued");
78 is($issues->[0]->{itemnumber}, $itemnumber1, "First item of biblio $biblionumber1 is issued");
79
80 $issues = C4::Circulation::GetIssues({biblionumber => $biblionumber2});
81 is(scalar @$issues, 1, "Biblio $biblionumber2 has 1 item issued");
82 is($issues->[0]->{itemnumber}, $itemnumber3, "First item of biblio $biblionumber2 is issued");
83
84 $issues = C4::Circulation::GetIssues({borrowernumber => $borrowernumber});
85 is(scalar @$issues, 2, "Borrower $borrowernumber checked out 2 items");
86
87 $issues = C4::Circulation::GetIssues({borrowernumber => $borrowernumber, biblionumber => $biblionumber1});
88 is(scalar @$issues, 1, "One of those is an item from biblio $biblionumber1");
89
90 $issues = C4::Circulation::GetIssues({borrowernumber => $borrowernumber, biblionumber => $biblionumber2});
91 is(scalar @$issues, 1, "The other is an item from biblio $biblionumber2");
92
93 $issues = C4::Circulation::GetIssues({itemnumber => $itemnumber2});
94 is(scalar @$issues, 0, "No one has issued the second item of biblio $biblionumber2");
95
96 my $onsite_checkouts = GetPendingOnSiteCheckouts;
97 is( scalar @$onsite_checkouts, 0, "No pending on-site checkouts" );
98
99 my $itemnumber4 = AddItem({ barcode => '0104', %item_infos }, $biblionumber1);
100 AddIssue( $borrower, '0104', undef, undef, undef, undef, { onsite_checkout => 1 } );
101 $onsite_checkouts = GetPendingOnSiteCheckouts;
102 is( scalar @$onsite_checkouts, 1, "There is 1 pending on-site checkout" );
103
104 $schema->storage->txn_rollback;
105
106 1;