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