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 Test::More tests => 54;
24 use t::lib::TestBuilder;
27 use_ok('Koha::Objects');
28 use_ok('Koha::Patrons');
29 use_ok('Koha::Patron::Relationship');
30 use_ok('Koha::Patron::Relationships');
33 my $builder = t::lib::TestBuilder->new();
36 my $kyle = Koha::Patrons->find(
49 my $chelsea = Koha::Patrons->find(
54 firstname => 'Chelsea',
62 my $daria = Koha::Patrons->find(
74 my $kylie = Koha::Patrons->find(
86 Koha::Patron::Relationship->new({ guarantor_id => $kyle->id, guarantee_id => $daria->id, relationship => 'father' })->store();
87 Koha::Patron::Relationship->new({ guarantor_id => $kyle->id, guarantee_id => $kylie->id, relationship => 'father' })->store();
88 Koha::Patron::Relationship->new({ guarantor_id => $chelsea->id, guarantee_id => $daria->id, relationship => 'mother' })->store();
89 Koha::Patron::Relationship->new({ guarantor_id => $chelsea->id, guarantee_id => $kylie->id, relationship => 'mother' })->store();
93 @gr = $kyle->guarantee_relationships()->as_list;
94 is( @gr, 2, 'Found 2 guarantee relationships for father' );
95 is( $gr[0]->guarantor_id, $kyle->id, 'Guarantor matches for first relationship' );
96 is( $gr[0]->guarantee_id, $daria->id, 'Guarantee matches for first relationship' );
97 is( $gr[0]->relationship, 'father', 'Relationship is father' );
98 is( ref($gr[0]->guarantee), 'Koha::Patron', 'Method guarantee returns a Koha::Patron' );
99 is( $gr[0]->guarantee->id, $daria->id, 'Koha::Patron returned is the correct guarantee' );
100 is( ref($gr[0]->guarantor), 'Koha::Patron', 'Method guarantor returns a Koha::Patron' );
101 is( $gr[0]->guarantor->id, $kyle->id, 'Koha::Patron returned is the correct guarantor' );
103 is( $gr[1]->guarantor_id, $kyle->id, 'Guarantor matches for first relationship' );
104 is( $gr[1]->guarantee_id, $kylie->id, 'Guarantee matches for first relationship' );
105 is( $gr[1]->relationship, 'father', 'Relationship is father' );
106 is( ref($gr[1]->guarantee), 'Koha::Patron', 'Method guarantee returns a Koha::Patron' );
107 is( $gr[1]->guarantee->id, $kylie->id, 'Koha::Patron returned is the correct guarantee' );
108 is( ref($gr[1]->guarantor), 'Koha::Patron', 'Method guarantor returns a Koha::Patron' );
109 is( $gr[1]->guarantor->id, $kyle->id, 'Koha::Patron returned is the correct guarantor' );
111 @gr = $chelsea->guarantee_relationships()->as_list;
112 is( @gr, 2, 'Found 2 guarantee relationships for mother' );
113 is( $gr[0]->guarantor_id, $chelsea->id, 'Guarantor matches for first relationship' );
114 is( $gr[0]->guarantee_id, $daria->id, 'Guarantee matches for first relationship' );
115 is( $gr[0]->relationship, 'mother', 'Relationship is mother' );
116 is( ref($gr[0]->guarantee), 'Koha::Patron', 'Method guarantee returns a Koha::Patron' );
117 is( $gr[0]->guarantee->id, $daria->id, 'Koha::Patron returned is the correct guarantee' );
118 is( ref($gr[0]->guarantor), 'Koha::Patron', 'Method guarantor returns a Koha::Patron' );
119 is( $gr[0]->guarantor->id, $chelsea->id, 'Koha::Patron returned is the correct guarantor' );
121 is( $gr[1]->guarantor_id, $chelsea->id, 'Guarantor matches for first relationship' );
122 is( $gr[1]->guarantee_id, $kylie->id, 'Guarantee matches for first relationship' );
123 is( $gr[1]->relationship, 'mother', 'Relationship is mother' );
124 is( ref($gr[1]->guarantee), 'Koha::Patron', 'Method guarantee returns a Koha::Patron' );
125 is( $gr[1]->guarantee->id, $kylie->id, 'Koha::Patron returned is the correct guarantee' );
126 is( ref($gr[1]->guarantor), 'Koha::Patron', 'Method guarantor returns a Koha::Patron' );
127 is( $gr[1]->guarantor->id, $chelsea->id, 'Koha::Patron returned is the correct guarantor' );
129 @gr = $daria->guarantor_relationships()->as_list;
130 is( @gr, 2, 'Found 4 guarantor relationships for child' );
131 is( $gr[0]->guarantor_id, $kyle->id, 'Guarantor matches for first relationship' );
132 is( $gr[0]->guarantee_id, $daria->id, 'Guarantee matches for first relationship' );
133 is( $gr[0]->relationship, 'father', 'Relationship is father' );
134 is( ref($gr[0]->guarantee), 'Koha::Patron', 'Method guarantee returns a Koha::Patron' );
135 is( $gr[0]->guarantee->id, $daria->id, 'Koha::Patron returned is the correct guarantee' );
136 is( ref($gr[0]->guarantor), 'Koha::Patron', 'Method guarantor returns a Koha::Patron' );
137 is( $gr[0]->guarantor->id, $kyle->id, 'Koha::Patron returned is the correct guarantor' );
139 is( $gr[1]->guarantor_id, $chelsea->id, 'Guarantor matches for first relationship' );
140 is( $gr[1]->guarantee_id, $daria->id, 'Guarantee matches for first relationship' );
141 is( $gr[1]->relationship, 'mother', 'Relationship is mother' );
142 is( ref($gr[1]->guarantee), 'Koha::Patron', 'Method guarantee returns a Koha::Patron' );
143 is( $gr[1]->guarantee->id, $daria->id, 'Koha::Patron returned is the correct guarantee' );
144 is( ref($gr[1]->guarantor), 'Koha::Patron', 'Method guarantor returns a Koha::Patron' );
145 is( $gr[1]->guarantor->id, $chelsea->id, 'Koha::Patron returned is the correct guarantor' );
147 my $siblings = $daria->siblings;
148 my $sibling = $siblings->next();
149 is( ref($siblings), 'Koha::Patrons', 'Calling siblings in scalar context results in a Koha::Patrons object' );
150 is( ref($sibling), 'Koha::Patron', 'Method next returns a Koha::Patron' );
151 is( $sibling->firstname, 'Kylie', 'Sibling from scalar first name matches correctly' );
152 is( $sibling->surname, 'Hall', 'Sibling from scalar surname matches correctly' );
153 is( $sibling->id, $kylie->id, 'Sibling from scalar patron id matches correctly' );