3 # Copyright 2015 Koha Development team
5 # This file is part of Koha
7 # Koha is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
12 # Koha is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with Koha; if not, see <http://www.gnu.org/licenses>.
22 use Test::More tests => 1;
27 use Koha::Club::Hold::PatronHolds;
30 use Koha::DateUtils qw(dt_from_string);
31 use Scalar::Util qw(blessed);
33 use t::lib::TestBuilder;
35 my $builder = t::lib::TestBuilder->new;
36 my $schema = Koha::Database->new->schema;
38 subtest 'add' => sub {
42 $schema->storage->txn_begin;
44 my $club = $builder->build_object({ class => 'Koha::Clubs' });
45 my $library = $builder->build_object({ class => 'Koha::Libraries', value => { pickup_location => 1 } });
46 my $item1 = $builder->build_sample_item({ library => $library->branchcode });
47 my $item2 = $builder->build_sample_item({ library => $library->branchcode });
50 Koha::Club::Hold::add(
56 'Koha::Exceptions::MissingParameter',
57 'Exception thrown when biblio_id is passed';
59 like( "$@", qr/The biblio_id parameter is mandatory/ );
62 Koha::Club::Hold::add(
64 biblio_id => $item1->biblionumber
68 'Koha::Exceptions::MissingParameter',
69 'Exception thrown when club_id is passed';
71 like( "$@", qr/The club_id parameter is mandatory/ );
74 Koha::Club::Hold::add(
77 biblio_id => $item1->biblionumber,
78 pickup_library_id => $library->branchcode
82 'Koha::Exceptions::ClubHold::NoPatrons',
83 'Exception thrown when no patron is enrolled in club';
85 my $patron = $builder->build_object(
87 class => 'Koha::Patrons',
88 value => { branchcode => $library->branchcode }
91 my $e = $builder->build_object(
93 class => 'Koha::Club::Enrollments',
96 borrowernumber => $patron->borrowernumber,
97 date_canceled => undef
102 my $club_hold = Koha::Club::Hold::add(
104 club_id => $club->id,
105 biblio_id => $item1->biblionumber,
106 pickup_library_id => $library->branchcode
110 is(blessed($club_hold), 'Koha::Club::Hold', 'add returns a Koha::Club::Hold');
112 $e->date_canceled(dt_from_string)->store;
115 Koha::Club::Hold::add(
117 club_id => $club->id,
118 biblio_id => $item2->biblionumber,
119 pickup_library_id => $library->branchcode
123 'Koha::Exceptions::ClubHold::NoPatrons',
124 'Exception thrown when no patron is enrolled in club';
126 my $patron_holds = Koha::Club::Hold::PatronHolds->search({ club_hold_id => $club_hold->id });
128 ok($patron_holds->count, "There must be at least one patron_hold");
130 my $patron_hold = $patron_holds->next;
132 my $hold = Koha::Holds->find($patron_hold->hold_id);
134 is($patron_hold->patron_id, $hold->borrowernumber, 'Patron must be the same');
136 $schema->storage->txn_rollback;