3 # Copyright 2019 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::Patron::Relationships;
29 use t::lib::TestBuilder;
32 my $schema = Koha::Database->new->schema;
33 my $builder = t::lib::TestBuilder->new;
35 subtest 'add_guarantor() tests' => sub {
39 $schema->storage->txn_begin;
41 t::lib::Mocks::mock_preference( 'borrowerRelationship', 'father1|father2' );
43 my $patron_1 = $builder->build_object({ class => 'Koha::Patrons' });
44 my $patron_2 = $builder->build_object({ class => 'Koha::Patrons' });
47 { $patron_1->add_guarantor({ guarantor_id => $patron_2->borrowernumber }); }
48 'Koha::Exceptions::Patron::Relationship::InvalidRelationship',
49 'Exception is thrown as no relationship passed';
51 is( $patron_1->guarantee_relationships->count, 0, 'No guarantors added' );
54 { $patron_1->add_guarantor({ guarantor_id => $patron_2->borrowernumber, relationship => 'father' }); }
55 'Koha::Exceptions::Patron::Relationship::InvalidRelationship',
56 'Exception is thrown as a wrong relationship was passed';
58 is( $patron_1->guarantee_relationships->count, 0, 'No guarantors added' );
60 $patron_1->add_guarantor({ guarantor_id => $patron_2->borrowernumber, relationship => 'father1' });
62 my $guarantors = $patron_1->guarantor_relationships;
64 is( $guarantors->count, 1, 'No guarantors added' );
66 $SIG{__WARN__} = sub {}; # FIXME: PrintError = 0 not working!
69 { $patron_1->add_guarantor({ guarantor_id => $patron_2->borrowernumber, relationship => 'father2' }); }
70 'Koha::Exceptions::Patron::Relationship::DuplicateRelationship',
71 'Exception is thrown for duplicated relationship';
73 $schema->storage->txn_rollback;