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(
49 value => { firstname => "Grogu" }
54 my $branch = $builder->build( { source => 'Branch' } );
57 my $illbatch = $builder->build(
61 name => "My test batch",
63 borrowernumber => $librarian->{borrowernumber},
64 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(
74 source => 'Illrequest',
76 borrowernumber => $patron->{borrowernumber},
77 batch_id => $illbatch->{id}
81 my $illrq_obj = Koha::Illrequests->find( $illrq->{illrequest_id} );
83 # Check requests_count
84 my $requests_count = $batch_obj->requests_count;
85 is( $requests_count, 1, 'requests_count returns correctly' );
88 my $batch_patron = $batch_obj->patron;
89 isa_ok( $batch_patron, 'Koha::Patron' );
90 is( $batch_patron->firstname, "Grogu", "patron returns correctly" );
93 my $batch_branch = $batch_obj->branch;
94 isa_ok( $batch_branch, 'Koha::Library' );
95 is( $batch_branch->branchcode, $branch->{branchcode}, "branch returns correctly" );
98 $schema->storage->txn_rollback;