forked from Koha-Community/Koha
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBorrower.t
executable file
·350 lines (334 loc) · 23.2 KB
/
Borrower.t
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
#!/usr/bin/perl
# This file is part of Koha.
#
# Koha is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# Koha is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Koha; if not, see <http://www.gnu.org/licenses>.
use Modern::Perl;
use Test::More tests => 18;
use Test::Warn;
use Koha::Database;
BEGIN {
use_ok('Koha::Object');
use_ok('Koha::Borrower');
}
my $object = Koha::Borrower->new( { surname => 'Test Borrower' } );
is( $object->surname(), 'Test Borrower', "Accessor returns correct value" );
$object->surname('Test Borrower Surname');
is( $object->surname(), 'Test Borrower Surname', "Accessor returns correct value after set" );
my $object2 = Koha::Borrower->new( { surname => 'Test Borrower 2' } );
is( $object2->surname(), 'Test Borrower 2', "Accessor returns correct value" );
$object2->surname('Test Borrower Surname 2');
is( $object2->surname(), 'Test Borrower Surname 2', "Accessor returns correct value after set" );
my $ret;
$ret = $object2->set( { surname => "Test Borrower Surname 3", firstname => "Test Firstname" } );
ok( ref($ret) eq 'Koha::Borrower', "Set returns object on success" );
is( $object2->surname(), "Test Borrower Surname 3", "Set sets first field correctly" );
is( $object2->firstname(), "Test Firstname", "Set sets second field correctly" );
warning_is { $ret = $object->set({ surname => "Test Borrower Surname 4", bork => "bork" }) }
"No property bork!",
"Expected 'No property bork!' caught";
is( $object2->surname(), "Test Borrower Surname 3", "Bad Set does not set field" );
is( $ret, 0, "Set returns 0 when passed a bad property" );
warning_is { $ret = $object->bork() }
"No method bork!",
"Expected 'No method bork!' caught for getter.";
ok( ! defined $ret, 'Bad getter returns undef' );
warning_is { $ret = $object->bork('bork') }
"No method bork!",
"Expected 'No method bork!' caught for setter.";
ok( ! defined $ret, 'Bad setter returns undef' );
my $borrower = Koha::Borrower->new(
{
borrowernumber => '12345',
cardnumber => '1234567890',
surname => 'mySurname',
firstname => 'myFirstname',
title => 'Mr.',
othernames => 'myOthernames',
initials => 'MM',
streetnumber => '100',
streettype => 'Blvd',
address => 'my personnal address',
address2 => 'my adress2',
city => 'Marseille',
state => 'mystate',
zipcode => '13006',
country => 'France',
email => '[email protected]',
phone => '0402872934',
mobile => '0627884632',
fax => '0402872935',
emailpro => '[email protected]',
phonepro => '0402873334',
B_streetnumber => '101',
B_streettype => 'myB_streettype',
B_address => 'myB_address',
B_address2 => 'myB_address2',
B_city => 'myB_city',
B_state => 'myB_state',
B_zipcode => '23456',
B_country => 'myB_country',
B_email => 'myB_email',
B_phone => '0678353935',
dateofbirth => '1990-07-16',
branchcode => 'myBranCode',
categorycode => 'myCatCode',
dateenrolled => '2015-03-19',
dateexpiry => '2016-03-19',
gonenoaddress => '0',
lost => '0',
debarred => '2015-04-19',
debarredcomment => 'You are debarred',
contactname => 'myContactname',
contactfirstname => 'myContactfirstname',
contacttitle => 'myContacttitle',
guarantorid => '123454321',
borrowernotes => 'borrowernotes',
relationship => 'myRelationship',
ethnicity => undef,
ethnotes => undef,
sex => 'M',
password => 'hfkurhfe976634èj!',
flags => '55555',
userid => '87987',
opacnote => 'myOpacnote',
contactnote => 'myContactnote',
sort1 => 'mySort1',
sort2 => 'mySort2',
altcontactfirstname => 'myAltcontactfirstname',
altcontactsurname => 'myAltcontactsurname',
altcontactaddress1 => 'myAltcontactaddress1',
altcontactaddress2 => 'myAltcontactaddress2',
altcontactaddress3 => 'myAltcontactaddress3',
altcontactstate => 'myAltcontactstate',
altcontactzipcode => '465843',
altcontactcountry => 'myOtherCountry',
altcontactphone => 'myOtherphone',
smsalertnumber => '0683027346',
privacy => '667788',
}
);
#borrower Accessor tests
subtest 'Accessor tests' => sub {
plan tests => 67;
is( $borrower->borrowernumber, '12345', 'borrowernumber accessor returns correct value' );
is( $borrower->cardnumber, '1234567890', 'cardnumber accessor returns correct value' );
is( $borrower->surname, 'mySurname', 'surname accessor returns correct value' );
is( $borrower->firstname, 'myFirstname', 'firstname accessor returns correct value' );
is( $borrower->title, 'Mr.', 'title accessor returns correct value' );
is( $borrower->othernames, 'myOthernames', 'othernames accessor returns correct value' );
is( $borrower->initials, 'MM', 'initials accessor returns correct value' );
is( $borrower->streetnumber, '100', 'streetnumber accessor returns correct value' );
is( $borrower->streettype, 'Blvd', 'streettype accessor returns correct value' );
is( $borrower->address, 'my personnal address', 'address accessor returns correct value' );
is( $borrower->address2, 'my adress2', 'address2 accessor returns correct value' );
is( $borrower->city, 'Marseille', 'city accessor returns correct value' );
is( $borrower->state, 'mystate', 'state accessor returns correct value' );
is( $borrower->zipcode, '13006', 'zipcode accessor returns correct value' );
is( $borrower->country, 'France', 'country accessor returns correct value' );
is( $borrower->email, '[email protected]', 'email accessor returns correct value' );
is( $borrower->phone, '0402872934', 'phone accessor returns correct value' );
is( $borrower->mobile, '0627884632', 'mobile accessor returns correct value' );
is( $borrower->fax, '0402872935', 'fax accessor returns correct value' );
is( $borrower->emailpro, '[email protected]', 'emailpro accessor returns correct value' );
is( $borrower->phonepro, '0402873334', 'phonepro accessor returns correct value' );
is( $borrower->B_streetnumber, '101', 'B_streetnumber accessor returns correct value' );
is( $borrower->B_streettype, 'myB_streettype', 'B_streettype accessor returns correct value' );
is( $borrower->B_address, 'myB_address', 'B_address accessor returns correct value' );
is( $borrower->B_address2, 'myB_address2', 'B_address2 accessor returns correct value' );
is( $borrower->B_city, 'myB_city', 'B_city accessor returns correct value' );
is( $borrower->B_state, 'myB_state', 'B_state accessor returns correct value' );
is( $borrower->B_zipcode, '23456', 'B_zipcode accessor returns correct value' );
is( $borrower->B_country, 'myB_country', 'B_country accessor returns correct value' );
is( $borrower->B_email, 'myB_email', 'B_email accessor returns correct value' );
is( $borrower->B_phone, '0678353935', 'B_phone accessor returns correct value' );
is( $borrower->dateofbirth, '1990-07-16', 'dateofbirth accessor returns correct value' );
is( $borrower->branchcode, 'myBranCode', 'branchcode accessor returns correct value' );
is( $borrower->categorycode, 'myCatCode', 'categorycode accessor returns correct value' );
is( $borrower->dateenrolled, '2015-03-19', 'dateenrolled accessor returns correct value' );
is( $borrower->dateexpiry, '2016-03-19', 'dateexpiry accessor returns correct value' );
is( $borrower->gonenoaddress, '0', 'gonenoaddress accessor returns correct value' );
is( $borrower->lost, '0', 'lost accessor returns correct value' );
is( $borrower->debarred, '2015-04-19', 'debarred accessor returns correct value' );
is( $borrower->debarredcomment, 'You are debarred', 'debarredcomment accessor returns correct value' );
is( $borrower->contactname, 'myContactname', 'contactname accessor returns correct value' );
is( $borrower->contactfirstname, 'myContactfirstname', 'contactfirstname accessor returns correct value' );
is( $borrower->contacttitle, 'myContacttitle', 'contacttitle accessor returns correct value' );
is( $borrower->guarantorid, '123454321', 'guarantorid accessor returns correct value' );
is( $borrower->borrowernotes, 'borrowernotes', 'borrowernotes accessor returns correct value' );
is( $borrower->relationship, 'myRelationship', 'relationship accessor returns correct value' );
is( $borrower->ethnicity, undef, 'ethnicity accessor returns correct value' );
is( $borrower->ethnotes, undef, 'ethnotes accessor returns correct value' );
is( $borrower->sex, 'M', 'sex accessor returns correct value' );
is( $borrower->password, 'hfkurhfe976634èj!', 'password accessor returns correct value' );
is( $borrower->flags, '55555', 'flags accessor returns correct value' );
is( $borrower->userid, '87987', 'userid accessor returns correct value' );
is( $borrower->opacnote, 'myOpacnote', 'opacnote accessor returns correct value' );
is( $borrower->contactnote, 'myContactnote', 'contactnote accessor returns correct value' );
is( $borrower->sort1, 'mySort1', 'sort1 accessor returns correct value' );
is( $borrower->sort2, 'mySort2', 'sort2 accessor returns correct value' );
is( $borrower->altcontactfirstname, 'myAltcontactfirstname', 'altcontactfirstname accessor returns correct value' );
is( $borrower->altcontactsurname, 'myAltcontactsurname', 'altcontactsurname accessor returns correct value' );
is( $borrower->altcontactaddress1, 'myAltcontactaddress1', 'altcontactaddress1 accessor returns correct value' );
is( $borrower->altcontactaddress2, 'myAltcontactaddress2', 'altcontactaddress2 accessor returns correct value' );
is( $borrower->altcontactaddress3, 'myAltcontactaddress3', 'altcontactaddress3 accessor returns correct value' );
is( $borrower->altcontactstate, 'myAltcontactstate', 'altcontactstate accessor returns correct value' );
is( $borrower->altcontactzipcode, '465843', 'altcontactzipcode accessor returns correct value' );
is( $borrower->altcontactcountry, 'myOtherCountry', 'altcontactcountry accessor returns correct value' );
is( $borrower->altcontactphone, 'myOtherphone', 'altcontactphone accessor returns correct value' );
is( $borrower->smsalertnumber, '0683027346', 'smsalertnumber accessor returns correct value' );
is( $borrower->privacy, '667788', 'privacy accessor returns correct value' );
};
#borrower Set tests
subtest 'Set tests' => sub {
plan tests => 67;
$borrower->set(
{
borrowernumber => '12346',
cardnumber => '1234567891',
surname => 'SmySurname',
firstname => 'SmyFirstname',
title => 'Mme.',
othernames => 'SmyOthernames',
initials => 'SS',
streetnumber => '200',
streettype => 'Rue',
address => 'Smy personnal address',
address2 => 'Smy adress2',
city => 'Lyon',
state => 'Smystate',
zipcode => '69000',
country => 'France',
email => '[email protected]',
phone => '0402872935',
mobile => '0627884633',
fax => '0402872936',
emailpro => '[email protected]',
phonepro => '0402873335',
B_streetnumber => '102',
B_streettype => 'SmyB_streettype',
B_address => 'SmyB_address',
B_address2 => 'SmyB_address2',
B_city => 'SmyB_city',
B_state => 'SmyB_state',
B_zipcode => '12333',
B_country => 'SmyB_country',
B_email => 'SmyB_email',
B_phone => '0678353936',
dateofbirth => '1991-07-16',
branchcode => 'SmyBranCode',
categorycode => 'SmyCatCode',
dateenrolled => '2014-03-19',
dateexpiry => '2017-03-19',
gonenoaddress => '1',
lost => '1',
debarred => '2016-04-19',
debarredcomment => 'You are still debarred',
contactname => 'SmyContactname',
contactfirstname => 'SmyContactfirstname',
contacttitle => 'SmyContacttitle',
guarantorid => '223454321',
borrowernotes => 'Sborrowernotes',
relationship => 'SmyRelationship',
ethnicity => undef,
ethnotes => undef,
sex => 'F',
password => 'zerzerzer#',
flags => '666666',
userid => '98233',
opacnote => 'SmyOpacnote',
contactnote => 'SmyContactnote',
sort1 => 'SmySort1',
sort2 => 'SmySort2',
altcontactfirstname => 'SmyAltcontactfirstname',
altcontactsurname => 'SmyAltcontactsurname',
altcontactaddress1 => 'SmyAltcontactaddress1',
altcontactaddress2 => 'SmyAltcontactaddress2',
altcontactaddress3 => 'SmyAltcontactaddress3',
altcontactstate => 'SmyAltcontactstate',
altcontactzipcode => '565843',
altcontactcountry => 'SmyOtherCountry',
altcontactphone => 'SmyOtherphone',
smsalertnumber => '0683027347',
privacy => '667789'
}
);
is( $borrower->borrowernumber, '12346', 'borrowernumber field set ok' );
is( $borrower->cardnumber, '1234567891', 'cardnumber field set ok' );
is( $borrower->surname, 'SmySurname', 'surname field set ok' );
is( $borrower->firstname, 'SmyFirstname', 'firstname field set ok' );
is( $borrower->title, 'Mme.', 'title field set ok' );
is( $borrower->othernames, 'SmyOthernames', 'othernames field set ok' );
is( $borrower->initials, 'SS', 'initials field set ok' );
is( $borrower->streetnumber, '200', 'streetnumber field set ok' );
is( $borrower->streettype, 'Rue', 'streettype field set ok' );
is( $borrower->address, 'Smy personnal address', 'address field set ok' );
is( $borrower->address2, 'Smy adress2', 'address2 field set ok' );
is( $borrower->city, 'Lyon', 'city field set ok' );
is( $borrower->state, 'Smystate', 'state field set ok' );
is( $borrower->zipcode, '69000', 'zipcode field set ok' );
is( $borrower->country, 'France', 'country field set ok' );
is( $borrower->email, '[email protected]', 'email field set ok' );
is( $borrower->phone, '0402872935', 'phone field set ok' );
is( $borrower->mobile, '0627884633', 'mobile field set ok' );
is( $borrower->fax, '0402872936', 'fax field set ok' );
is( $borrower->emailpro, '[email protected]', 'emailpro field set ok' );
is( $borrower->phonepro, '0402873335', 'phonepro field set ok' );
is( $borrower->B_streetnumber, '102', 'B_streetnumber field set ok' );
is( $borrower->B_streettype, 'SmyB_streettype', 'B_streettype field set ok' );
is( $borrower->B_address, 'SmyB_address', 'B_address field set ok' );
is( $borrower->B_address2, 'SmyB_address2', 'B_address2 field set ok' );
is( $borrower->B_city, 'SmyB_city', 'B_city field set ok' );
is( $borrower->B_state, 'SmyB_state', 'B_state field set ok' );
is( $borrower->B_zipcode, '12333', 'B_zipcode field set ok' );
is( $borrower->B_country, 'SmyB_country', 'B_country field set ok' );
is( $borrower->B_email, 'SmyB_email', 'B_email field set ok' );
is( $borrower->B_phone, '0678353936', 'B_phone field set ok' );
is( $borrower->dateofbirth, '1991-07-16', 'dateofbirth field set ok' );
is( $borrower->branchcode, 'SmyBranCode', 'branchcode field set ok' );
is( $borrower->categorycode, 'SmyCatCode', 'categorycode field set ok' );
is( $borrower->dateenrolled, '2014-03-19', 'dateenrolled field set ok' );
is( $borrower->dateexpiry, '2017-03-19', 'dateexpiry field set ok' );
is( $borrower->gonenoaddress, '1', 'gonenoaddress field set ok' );
is( $borrower->lost, '1', 'lost field set ok' );
is( $borrower->debarred, '2016-04-19', 'debarred field set ok' );
is( $borrower->debarredcomment, 'You are still debarred', 'debarredcomment field set ok' );
is( $borrower->contactname, 'SmyContactname', 'contactname field set ok' );
is( $borrower->contactfirstname, 'SmyContactfirstname', 'contactfirstname field set ok' );
is( $borrower->contacttitle, 'SmyContacttitle', 'contacttitle field set ok' );
is( $borrower->guarantorid, '223454321', 'guarantorid field set ok' );
is( $borrower->borrowernotes, 'Sborrowernotes', 'borrowernotes field set ok' );
is( $borrower->relationship, 'SmyRelationship', 'relationship field set ok' );
is( $borrower->ethnicity, undef, 'ethnicity field set ok' );
is( $borrower->ethnotes, undef, 'ethnotes field set ok' );
is( $borrower->sex, 'F', 'sex field set ok' );
is( $borrower->password, 'zerzerzer#', 'password field set ok' );
is( $borrower->flags, '666666', 'flags field set ok' );
is( $borrower->userid, '98233', 'userid field set ok' );
is( $borrower->opacnote, 'SmyOpacnote', 'opacnote field set ok' );
is( $borrower->contactnote, 'SmyContactnote', 'contactnote field set ok' );
is( $borrower->sort1, 'SmySort1', 'sort1 field set ok' );
is( $borrower->sort2, 'SmySort2', 'sort2 field set ok' );
is( $borrower->altcontactfirstname, 'SmyAltcontactfirstname', 'altcontactfirstname field set ok' );
is( $borrower->altcontactsurname, 'SmyAltcontactsurname', 'altcontactsurname field set ok' );
is( $borrower->altcontactaddress1, 'SmyAltcontactaddress1', 'altcontactaddress1 field set ok' );
is( $borrower->altcontactaddress2, 'SmyAltcontactaddress2', 'altcontactaddress2 field set ok' );
is( $borrower->altcontactaddress3, 'SmyAltcontactaddress3', 'altcontactaddress3 field set ok' );
is( $borrower->altcontactstate, 'SmyAltcontactstate', 'altcontactstate field set ok' );
is( $borrower->altcontactzipcode, '565843', 'altcontactzipcode field set ok' );
is( $borrower->altcontactcountry, 'SmyOtherCountry', 'altcontactcountry field set ok' );
is( $borrower->altcontactphone, 'SmyOtherphone', 'altcontactphone field set ok' );
is( $borrower->smsalertnumber, '0683027347', 'smsalertnumber field set ok' );
is( $borrower->privacy, '667789', 'privacy field set ok' );
};
1;