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