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 {
41 $schema->storage->txn_begin;
43 my $club = $builder->build_object({ class => 'Koha::Clubs' });
44 my $library = $builder->build_object({ class => 'Koha::Libraries', value
=> { pickup_location
=> 1 } });
45 my $item1 = $builder->build_sample_item({ library
=> $library->branchcode });
46 my $item2 = $builder->build_sample_item({ library
=> $library->branchcode });
49 Koha
::Club
::Hold
::add
({ club_id
=> $club->id, biblio_id
=> $item1->biblionumber, pickup_library_id
=> $library->branchcode });
52 ok
($class eq 'Koha::Exceptions::ClubHold::NoPatrons', 'Exception thrown when no patron is enrolled in club');
55 my $patron = $builder->build_object({ class => 'Koha::Patrons', value
=> { branchcode
=> $library->branchcode } });
56 my $e = $builder->build_object({ class => 'Koha::Club::Enrollments' , value
=> { club_id
=> $club->id, borrowernumber
=> $patron->borrowernumber, date_canceled
=> undef }} );
58 my $club_hold = Koha
::Club
::Hold
::add
({
60 biblio_id
=> $item1->biblionumber,
61 pickup_library_id
=> $library->branchcode
64 is
(blessed
($club_hold), 'Koha::Club::Hold', 'add returns a Koha::Club::Hold');
66 $e->date_canceled(dt_from_string
)->store;
69 Koha
::Club
::Hold
::add
({ club_id
=> $club->id, biblio_id
=> $item2->biblionumber, pickup_library_id
=> $library->branchcode });
72 ok
($class eq 'Koha::Exceptions::ClubHold::NoPatrons', 'Exception thrown when no patron is enrolled in club');
75 my $patron_holds = Koha
::Club
::Hold
::PatronHolds
->search({ club_hold_id
=> $club_hold->id });
77 ok
($patron_holds->count, "There must be at least one patron_hold");
79 my $patron_hold = $patron_holds->next;
81 my $hold = Koha
::Holds
->find($patron_hold->hold_id);
83 is
($patron_hold->patron_id, $hold->borrowernumber, 'Patron must be the same');
85 $schema->storage->txn_rollback;