3 # This file is part of Koha.
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.
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.
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>.
20 use File::Basename qw/basename/;
24 use Koha::Illrequests;
27 use t::lib::TestBuilder;
31 use Test::More tests => 8;
33 my $schema = Koha::Database->new->schema;
34 my $builder = t::lib::TestBuilder->new;
35 use_ok('Koha::Illbatch');
36 use_ok('Koha::Illbatches');
38 $schema->storage->txn_begin;
40 Koha::Illrequests->search->delete;
43 my $patron = $builder->build({ source => 'Borrower' });
46 my $librarian = $builder->build({
54 my $branch = $builder->build({
59 my $illbatch = $builder->build({
62 name => "My test batch",
64 borrowernumber => $librarian->{borrowernumber},
65 branchcode => $branch->{branchcode}
68 my $batch_obj = Koha::Illbatches->find($illbatch->{id});
69 isa_ok( $batch_obj, 'Koha::Illbatch' );
71 # Create an ILL request in the batch
72 my $illrq = $builder->build({
73 source => 'Illrequest',
75 borrowernumber => $patron->{borrowernumber},
76 batch_id => $illbatch->{id}
79 my $illrq_obj = Koha::Illrequests->find($illrq->{illrequest_id});
81 # Check requests_count
82 my $requests_count = $batch_obj->requests_count;
83 is( $requests_count, 1, 'requests_count returns correctly' );
86 my $batch_patron = $batch_obj->patron;
87 isa_ok( $batch_patron, 'Koha::Patron' );
88 is( $batch_patron->firstname, "Grogu", "patron returns correctly" );
91 my $batch_branch = $batch_obj->branch;
92 isa_ok( $batch_branch, 'Koha::Library' );
93 is( $batch_branch->branchcode, $branch->{branchcode}, "branch returns correctly" );
96 $schema->storage->txn_rollback;