Bug 31503: (QA follow-up) Improve count of available_types
[koha.git] / t / db_dependent / Illbatches.t
1 #s!/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 Koha::Database;
21 use Koha::Illbatch;
22 use Koha::Illbatches;
23 use Koha::Illrequests;
24 use Koha::Patrons;
25 use t::lib::Mocks;
26 use t::lib::TestBuilder;
27 use Test::MockObject;
28 use Test::MockModule;
29
30 use Test::More tests => 6;
31
32 my $schema  = Koha::Database->new->schema;
33 my $builder = t::lib::TestBuilder->new;
34 use_ok('Koha::Illbatch');
35 use_ok('Koha::Illbatches');
36
37 $schema->storage->txn_begin;
38
39 # Create a patron
40 my $patron = $builder->build( { source => 'Borrower' } );
41
42 # Create a librarian
43 my $librarian = $builder->build(
44     {
45         source => 'Borrower',
46         value  => { firstname => "Grogu" }
47     }
48 );
49
50 # Create a branch
51 my $branch = $builder->build( { source => 'Branch' } );
52
53 # Create a batch
54 my $illbatch = $builder->build_object(
55     {
56         class => 'Koha::Illbatches',
57         value  => {
58             name       => "My test batch",
59             backend    => "Mock",
60             patron_id  => $librarian->{borrowernumber},
61             library_id => $branch->{branchcode}
62         }
63     }
64 );
65
66 # Create an ILL request in the batch
67 my $illrq = $builder->build(
68     {
69         source => 'Illrequest',
70         value  => {
71             borrowernumber => $patron->{borrowernumber},
72             batch_id       => $illbatch->id
73         }
74     }
75 );
76 my $illrq_obj = Koha::Illrequests->find( $illrq->{illrequest_id} );
77
78 # Check patron
79 my $batch_patron = $illbatch->patron;
80 isa_ok( $batch_patron, 'Koha::Patron' );
81 is( $batch_patron->firstname, "Grogu", "patron returns correctly" );
82
83 # Check branch
84 my $batch_branch = $illbatch->library;
85 isa_ok( $batch_branch, 'Koha::Library' );
86 is( $batch_branch->branchcode, $branch->{branchcode}, "branch returns correctly" );
87
88 $illrq_obj->delete;
89 $schema->storage->txn_rollback;