Bug 17740: Add the Koha::Patron->holds method
[koha.git] / t / db_dependent / Members.t
blob3d24e44049646061c1ab2d5dfdee39dfea54df70
1 #!/usr/bin/perl
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>.
18 use Modern::Perl;
20 use Test::More tests => 64;
21 use Test::MockModule;
22 use Data::Dumper;
23 use C4::Context;
24 use Koha::Database;
25 use Koha::Holds;
26 use Koha::List::Patron;
27 use Koha::Patrons;
29 use t::lib::Mocks;
30 use t::lib::TestBuilder;
32 BEGIN {
33 use_ok('C4::Members');
36 my $schema = Koha::Database->schema;
37 $schema->storage->txn_begin;
38 my $builder = t::lib::TestBuilder->new;
39 my $dbh = C4::Context->dbh;
40 $dbh->{RaiseError} = 1;
42 # Remove invalid guarantorid's as long as we have no FK
43 $dbh->do("UPDATE borrowers b1 LEFT JOIN borrowers b2 ON b2.borrowernumber=b1.guarantorid SET b1.guarantorid=NULL where b1.guarantorid IS NOT NULL AND b2.borrowernumber IS NULL");
45 my $library1 = $builder->build({
46 source => 'Branch',
47 });
48 my $library2 = $builder->build({
49 source => 'Branch',
50 });
51 my $CARDNUMBER = 'TESTCARD01';
52 my $FIRSTNAME = 'Marie';
53 my $SURNAME = 'Mcknight';
54 my $CATEGORYCODE = 'S';
55 my $BRANCHCODE = $library1->{branchcode};
57 my $CHANGED_FIRSTNAME = "Marry Ann";
58 my $EMAIL = "Marie\@email.com";
59 my $EMAILPRO = "Marie\@work.com";
60 my $PHONE = "555-12123";
62 # XXX should be randomised and checked against the database
63 my $IMPOSSIBLE_CARDNUMBER = "XYZZZ999";
65 #my ($usernum, $userid, $usercnum, $userfirstname, $usersurname, $userbranch, $branchname, $userflags, $emailaddress, $branchprinter)= @_;
66 my @USERENV = (
68 'test',
69 'MASTERTEST',
70 'Test',
71 'Test',
72 't',
73 'Test',
76 my $BRANCH_IDX = 5;
78 C4::Context->_new_userenv ('DUMMY_SESSION_ID');
79 C4::Context->set_userenv ( @USERENV );
81 my $userenv = C4::Context->userenv
82 or BAIL_OUT("No userenv");
84 # Make a borrower for testing
85 my %data = (
86 cardnumber => $CARDNUMBER,
87 firstname => $FIRSTNAME,
88 surname => $SURNAME,
89 categorycode => $CATEGORYCODE,
90 branchcode => $BRANCHCODE,
91 dateofbirth => '',
92 dateexpiry => '9999-12-31',
93 userid => 'tomasito'
96 my $addmem=AddMember(%data);
97 ok($addmem, "AddMember()");
99 my $member = GetMember( cardnumber => $CARDNUMBER )
100 or BAIL_OUT("Cannot read member with card $CARDNUMBER");
102 ok ( $member->{firstname} eq $FIRSTNAME &&
103 $member->{surname} eq $SURNAME &&
104 $member->{categorycode} eq $CATEGORYCODE &&
105 $member->{branchcode} eq $BRANCHCODE
106 , "Got member")
107 or diag("Mismatching member details: ".Dumper(\%data, $member));
109 is($member->{dateofbirth}, undef, "Empty dates handled correctly");
111 $member->{firstname} = $CHANGED_FIRSTNAME;
112 $member->{email} = $EMAIL;
113 $member->{phone} = $PHONE;
114 $member->{emailpro} = $EMAILPRO;
115 ModMember(%$member);
116 my $changedmember = GetMember( cardnumber => $CARDNUMBER );
117 ok ( $changedmember->{firstname} eq $CHANGED_FIRSTNAME &&
118 $changedmember->{email} eq $EMAIL &&
119 $changedmember->{phone} eq $PHONE &&
120 $changedmember->{emailpro} eq $EMAILPRO
121 , "Member Changed")
122 or diag("Mismatching member details: ".Dumper($member, $changedmember));
124 t::lib::Mocks::mock_preference( 'CardnumberLength', '' );
125 C4::Context->clear_syspref_cache();
127 my $checkcardnum=C4::Members::checkcardnumber($CARDNUMBER, "");
128 is ($checkcardnum, "1", "Card No. in use");
130 $checkcardnum=C4::Members::checkcardnumber($IMPOSSIBLE_CARDNUMBER, "");
131 is ($checkcardnum, "0", "Card No. not used");
133 t::lib::Mocks::mock_preference( 'CardnumberLength', '4' );
134 C4::Context->clear_syspref_cache();
136 $checkcardnum=C4::Members::checkcardnumber($IMPOSSIBLE_CARDNUMBER, "");
137 is ($checkcardnum, "2", "Card number is too long");
141 t::lib::Mocks::mock_preference( 'AutoEmailPrimaryAddress', 'OFF' );
142 C4::Context->clear_syspref_cache();
144 my $notice_email = GetNoticeEmailAddress($member->{'borrowernumber'});
145 is ($notice_email, $EMAIL, "GetNoticeEmailAddress returns correct value when AutoEmailPrimaryAddress is off");
147 t::lib::Mocks::mock_preference( 'AutoEmailPrimaryAddress', 'emailpro' );
148 C4::Context->clear_syspref_cache();
150 $notice_email = GetNoticeEmailAddress($member->{'borrowernumber'});
151 is ($notice_email, $EMAILPRO, "GetNoticeEmailAddress returns correct value when AutoEmailPrimaryAddress is emailpro");
153 # Check_Userid tests
154 %data = (
155 cardnumber => "123456789",
156 firstname => "Tomasito",
157 surname => "None",
158 categorycode => "S",
159 branchcode => $library2->{branchcode},
160 dateofbirth => '',
161 debarred => '',
162 dateexpiry => '',
163 dateenrolled => '',
165 # Add a new borrower
166 my $borrowernumber = AddMember( %data );
167 is( Check_Userid( 'tomasito.non', $borrowernumber ), 1,
168 'recently created userid -> unique (borrowernumber passed)' );
169 is( Check_Userid( 'tomasitoxxx', $borrowernumber ), 1,
170 'non-existent userid -> unique (borrowernumber passed)' );
171 is( Check_Userid( 'tomasito.none', '' ), 0,
172 'userid exists (blank borrowernumber)' );
173 is( Check_Userid( 'tomasitoxxx', '' ), 1,
174 'non-existent userid -> unique (blank borrowernumber)' );
176 my $borrower = GetMember( borrowernumber => $borrowernumber );
177 is( $borrower->{dateofbirth}, undef, 'AddMember should undef dateofbirth if empty string is given');
178 is( $borrower->{debarred}, undef, 'AddMember should undef debarred if empty string is given');
179 isnt( $borrower->{dateexpiry}, '0000-00-00', 'AddMember should not set dateexpiry to 0000-00-00 if empty string is given');
180 isnt( $borrower->{dateenrolled}, '0000-00-00', 'AddMember should not set dateenrolled to 0000-00-00 if empty string is given');
182 ModMember( borrowernumber => $borrowernumber, dateofbirth => '', debarred => '', dateexpiry => '', dateenrolled => '' );
183 $borrower = GetMember( borrowernumber => $borrowernumber );
184 is( $borrower->{dateofbirth}, undef, 'ModMember should undef dateofbirth if empty string is given');
185 is( $borrower->{debarred}, undef, 'ModMember should undef debarred if empty string is given');
186 isnt( $borrower->{dateexpiry}, '0000-00-00', 'ModMember should not set dateexpiry to 0000-00-00 if empty string is given');
187 isnt( $borrower->{dateenrolled}, '0000-00-00', 'ModMember should not set dateenrolled to 0000-00-00 if empty string is given');
189 ModMember( borrowernumber => $borrowernumber, dateofbirth => '1970-01-01', debarred => '2042-01-01', dateexpiry => '9999-12-31', dateenrolled => '2015-09-06' );
190 $borrower = GetMember( borrowernumber => $borrowernumber );
191 is( $borrower->{dateofbirth}, '1970-01-01', 'ModMember should correctly set dateofbirth if a valid date is given');
192 is( $borrower->{debarred}, '2042-01-01', 'ModMember should correctly set debarred if a valid date is given');
193 is( $borrower->{dateexpiry}, '9999-12-31', 'ModMember should correctly set dateexpiry if a valid date is given');
194 is( $borrower->{dateenrolled}, '2015-09-06', 'ModMember should correctly set dateenrolled if a valid date is given');
196 # Add a new borrower with the same userid but different cardnumber
197 $data{ cardnumber } = "987654321";
198 my $new_borrowernumber = AddMember( %data );
199 is( Check_Userid( 'tomasito.none', '' ), 0,
200 'userid not unique (blank borrowernumber)' );
201 is( Check_Userid( 'tomasito.none', $new_borrowernumber ), 0,
202 'userid not unique (second borrowernumber passed)' );
203 $borrower = GetMember( borrowernumber => $new_borrowernumber );
204 ok( $borrower->{userid} ne 'tomasito', "Borrower with duplicate userid has new userid generated" );
206 $data{ cardnumber } = "234567890";
207 $data{userid} = 'a_user_id';
208 $borrowernumber = AddMember( %data );
209 $borrower = GetMember( borrowernumber => $borrowernumber );
210 is( $borrower->{userid}, $data{userid}, 'AddMember should insert the given userid' );
212 subtest 'ModMember should not update userid if not true' => sub {
213 plan tests => 3;
214 ModMember( borrowernumber => $borrowernumber, firstname => 'Tomas', userid => '' );
215 $borrower = GetMember( borrowernumber => $borrowernumber );
216 is ( $borrower->{userid}, $data{userid}, 'ModMember should not update the userid with an empty string' );
217 ModMember( borrowernumber => $borrowernumber, firstname => 'Tomas', userid => 0 );
218 $borrower = GetMember( borrowernumber => $borrowernumber );
219 is ( $borrower->{userid}, $data{userid}, 'ModMember should not update the userid with an 0');
220 ModMember( borrowernumber => $borrowernumber, firstname => 'Tomas', userid => undef );
221 $borrower = GetMember( borrowernumber => $borrowernumber );
222 is ( $borrower->{userid}, $data{userid}, 'ModMember should not update the userid with an undefined value');
225 #Regression tests for bug 10612
226 my $library3 = $builder->build({
227 source => 'Branch',
229 $builder->build({
230 source => 'Category',
231 value => {
232 categorycode => 'STAFFER',
233 description => 'Staff dont batch del',
234 category_type => 'S',
238 $builder->build({
239 source => 'Category',
240 value => {
241 categorycode => 'CIVILIAN',
242 description => 'Civilian batch del',
243 category_type => 'A',
247 $builder->build({
248 source => 'Category',
249 value => {
250 categorycode => 'KIDclamp',
251 description => 'Kid to be guaranteed',
252 category_type => 'C',
256 my $borrower1 = $builder->build({
257 source => 'Borrower',
258 value => {
259 categorycode=>'STAFFER',
260 branchcode => $library3->{branchcode},
261 dateexpiry => '2015-01-01',
262 guarantorid=> undef,
265 my $bor1inlist = $borrower1->{borrowernumber};
266 my $borrower2 = $builder->build({
267 source => 'Borrower',
268 value => {
269 categorycode=>'STAFFER',
270 branchcode => $library3->{branchcode},
271 dateexpiry => '2015-01-01',
272 guarantorid=> undef,
276 my $guarantee = $builder->build({
277 source => 'Borrower',
278 value => {
279 categorycode=>'KIDclamp',
280 branchcode => $library3->{branchcode},
281 dateexpiry => '2015-01-01',
282 guarantorid=> undef, # will be filled later
286 my $bor2inlist = $borrower2->{borrowernumber};
288 $builder->build({
289 source => 'OldIssue',
290 value => {
291 borrowernumber => $bor2inlist,
292 timestamp => '2016-01-01',
296 my $owner = AddMember (categorycode => 'STAFFER', branchcode => $library2->{branchcode} );
297 my $list1 = AddPatronList( { name => 'Test List 1', owner => $owner } );
298 my @listpatrons = ($bor1inlist, $bor2inlist);
299 AddPatronsToList( { list => $list1, borrowernumbers => \@listpatrons });
300 my $patstodel = GetBorrowersToExpunge( {patron_list_id => $list1->patron_list_id() } );
301 is( scalar(@$patstodel),0,'No staff deleted from list of all staff');
302 ModMember( borrowernumber => $bor2inlist, categorycode => 'CIVILIAN' );
303 $patstodel = GetBorrowersToExpunge( {patron_list_id => $list1->patron_list_id()} );
304 ok( scalar(@$patstodel)== 1 && $patstodel->[0]->{'borrowernumber'} eq $bor2inlist,'Staff patron not deleted from list');
305 $patstodel = GetBorrowersToExpunge( {branchcode => $library3->{branchcode},patron_list_id => $list1->patron_list_id() } );
306 ok( scalar(@$patstodel) == 1 && $patstodel->[0]->{'borrowernumber'} eq $bor2inlist,'Staff patron not deleted by branchcode and list');
307 $patstodel = GetBorrowersToExpunge( {expired_before => '2015-01-02', patron_list_id => $list1->patron_list_id() } );
308 ok( scalar(@$patstodel) == 1 && $patstodel->[0]->{'borrowernumber'} eq $bor2inlist,'Staff patron not deleted by expirationdate and list');
309 $patstodel = GetBorrowersToExpunge( {not_borrowed_since => '2016-01-02', patron_list_id => $list1->patron_list_id() } );
310 ok( scalar(@$patstodel) == 1 && $patstodel->[0]->{'borrowernumber'} eq $bor2inlist,'Staff patron not deleted by last issue date');
312 ModMember( borrowernumber => $bor1inlist, categorycode => 'CIVILIAN' );
313 ModMember( borrowernumber => $guarantee->{borrowernumber} ,guarantorid=>$bor1inlist );
315 $patstodel = GetBorrowersToExpunge( {patron_list_id => $list1->patron_list_id()} );
316 ok( scalar(@$patstodel)== 1 && $patstodel->[0]->{'borrowernumber'} eq $bor2inlist,'Guarantor patron not deleted from list');
317 $patstodel = GetBorrowersToExpunge( {branchcode => $library3->{branchcode},patron_list_id => $list1->patron_list_id() } );
318 ok( scalar(@$patstodel) == 1 && $patstodel->[0]->{'borrowernumber'} eq $bor2inlist,'Guarantor patron not deleted by branchcode and list');
319 $patstodel = GetBorrowersToExpunge( {expired_before => '2015-01-02', patron_list_id => $list1->patron_list_id() } );
320 ok( scalar(@$patstodel) == 1 && $patstodel->[0]->{'borrowernumber'} eq $bor2inlist,'Guarantor patron not deleted by expirationdate and list');
321 $patstodel = GetBorrowersToExpunge( {not_borrowed_since => '2016-01-02', patron_list_id => $list1->patron_list_id() } );
322 ok( scalar(@$patstodel) == 1 && $patstodel->[0]->{'borrowernumber'} eq $bor2inlist,'Guarantor patron not deleted by last issue date');
323 ModMember( borrowernumber => $guarantee->{borrowernumber}, guarantorid=>'' );
325 $builder->build({
326 source => 'Issue',
327 value => {
328 borrowernumber => $bor2inlist,
331 $patstodel = GetBorrowersToExpunge( {patron_list_id => $list1->patron_list_id()} );
332 is( scalar(@$patstodel),1,'Borrower with issue not deleted from list');
333 $patstodel = GetBorrowersToExpunge( {branchcode => $library3->{branchcode},patron_list_id => $list1->patron_list_id() } );
334 is( scalar(@$patstodel),1,'Borrower with issue not deleted by branchcode and list');
335 $patstodel = GetBorrowersToExpunge( {category_code => 'CIVILIAN',patron_list_id => $list1->patron_list_id() } );
336 is( scalar(@$patstodel),1,'Borrower with issue not deleted by category_code and list');
337 $patstodel = GetBorrowersToExpunge( {expired_before => '2015-01-02',patron_list_id => $list1->patron_list_id() } );
338 is( scalar(@$patstodel),1,'Borrower with issue not deleted by expiration_date and list');
339 $builder->schema->resultset( 'Issue' )->delete_all;
340 $patstodel = GetBorrowersToExpunge( {patron_list_id => $list1->patron_list_id()} );
341 ok( scalar(@$patstodel)== 2,'Borrowers without issue deleted from list');
342 $patstodel = GetBorrowersToExpunge( {category_code => 'CIVILIAN',patron_list_id => $list1->patron_list_id() } );
343 is( scalar(@$patstodel),2,'Borrowers without issues deleted by category_code and list');
344 $patstodel = GetBorrowersToExpunge( {expired_before => '2015-01-02',patron_list_id => $list1->patron_list_id() } );
345 is( scalar(@$patstodel),2,'Borrowers without issues deleted by expiration_date and list');
346 $patstodel = GetBorrowersToExpunge( {not_borrowed_since => '2016-01-02', patron_list_id => $list1->patron_list_id() } );
347 is( scalar(@$patstodel),2,'Borrowers without issues deleted by last issue date');
349 # Test GetBorrowersToExpunge and TrackLastPatronActivity
350 $dbh->do(q|UPDATE borrowers SET lastseen=NULL|);
351 $builder->build({ source => 'Borrower', value => { lastseen => '2016-01-01 01:01:01', categorycode => 'CIVILIAN', guarantorid => undef } } );
352 $builder->build({ source => 'Borrower', value => { lastseen => '2016-02-02 02:02:02', categorycode => 'CIVILIAN', guarantorid => undef } } );
353 $builder->build({ source => 'Borrower', value => { lastseen => '2016-03-03 03:03:03', categorycode => 'CIVILIAN', guarantorid => undef } } );
354 $patstodel = GetBorrowersToExpunge( { last_seen => '1999-12-12' });
355 is( scalar @$patstodel, 0, 'TrackLastPatronActivity - 0 patrons must be deleted' );
356 $patstodel = GetBorrowersToExpunge( { last_seen => '2016-02-15' });
357 is( scalar @$patstodel, 2, 'TrackLastPatronActivity - 2 patrons must be deleted' );
358 $patstodel = GetBorrowersToExpunge( { last_seen => '2016-04-04' });
359 is( scalar @$patstodel, 3, 'TrackLastPatronActivity - 3 patrons must be deleted' );
360 my $patron2 = $builder->build({ source => 'Borrower', value => { lastseen => undef } });
361 t::lib::Mocks::mock_preference( 'TrackLastPatronActivity', '0' );
362 Koha::Patrons->find( $patron2->{borrowernumber} )->track_login;
363 is( Koha::Patrons->find( $patron2->{borrowernumber} )->lastseen, undef, 'Lastseen should not be changed' );
364 Koha::Patrons->find( $patron2->{borrowernumber} )->track_login({ force => 1 });
365 isnt( Koha::Patrons->find( $patron2->{borrowernumber} )->lastseen, undef, 'Lastseen should be changed now' );
367 # Regression tests for BZ13502
368 ## Remove all entries with userid='' (should be only 1 max)
369 $dbh->do(q|DELETE FROM borrowers WHERE userid = ''|);
370 ## And create a patron with a userid=''
371 $borrowernumber = AddMember( categorycode => 'S', branchcode => $library2->{branchcode} );
372 $dbh->do(q|UPDATE borrowers SET userid = '' WHERE borrowernumber = ?|, undef, $borrowernumber);
373 # Create another patron and verify the userid has been generated
374 $borrowernumber = AddMember( categorycode => 'S', branchcode => $library2->{branchcode} );
375 ok( $borrowernumber > 0, 'AddMember should have inserted the patron even if no userid is given' );
376 $borrower = GetMember( borrowernumber => $borrowernumber );
377 ok( $borrower->{userid}, 'A userid should have been generated correctly' );
379 # Regression tests for BZ12226
380 is( Check_Userid( C4::Context->config('user'), '' ), 0,
381 'Check_Userid should return 0 for the DB user (Bug 12226)');
383 subtest 'GetMemberAccountRecords' => sub {
385 plan tests => 2;
387 my $borrowernumber = $builder->build({ source => 'Borrower' })->{ borrowernumber };
388 my $accountline_1 = $builder->build({
389 source => 'Accountline',
390 value => {
391 borrowernumber => $borrowernumber,
392 amountoutstanding => 64.60
396 my ($total,undef,undef) = GetMemberAccountRecords( $borrowernumber );
397 is( $total , 64.60, "Rounding works correctly in total calculation (single value)" );
399 my $accountline_2 = $builder->build({
400 source => 'Accountline',
401 value => {
402 borrowernumber => $borrowernumber,
403 amountoutstanding => 10.65
407 ($total,undef,undef) = GetMemberAccountRecords( $borrowernumber );
408 is( $total , 75.25, "Rounding works correctly in total calculation (multiple values)" );
412 subtest 'GetMemberAccountBalance' => sub {
414 plan tests => 6;
416 my $members_mock = new Test::MockModule('C4::Members');
417 $members_mock->mock( 'GetMemberAccountRecords', sub {
418 my ($borrowernumber) = @_;
419 if ($borrowernumber) {
420 my @accountlines = (
421 { amountoutstanding => '7', accounttype => 'Rent' },
422 { amountoutstanding => '5', accounttype => 'Res' },
423 { amountoutstanding => '3', accounttype => 'Pay' } );
424 return ( 15, \@accountlines );
426 else {
427 my @accountlines;
428 return ( 0, \@accountlines );
432 # do not count holds charges
433 t::lib::Mocks::mock_preference( 'HoldsInNoissuesCharge', '1' );
434 t::lib::Mocks::mock_preference( 'ManInvInNoissuesCharge', '0' );
435 my ($total, $total_minus_charges,
436 $other_charges) = C4::Members::GetMemberAccountBalance(123);
437 is( $total, 15 , "Total calculated correctly");
438 is( $total_minus_charges, 15, "Holds charges are not count if HoldsInNoissuesCharge=1");
439 is( $other_charges, 0, "Holds charges are not considered if HoldsInNoissuesCharge=1");
441 t::lib::Mocks::mock_preference( 'HoldsInNoissuesCharge', '0' );
442 ($total, $total_minus_charges,
443 $other_charges) = C4::Members::GetMemberAccountBalance(123);
444 is( $total, 15 , "Total calculated correctly");
445 is( $total_minus_charges, 10, "Holds charges are count if HoldsInNoissuesCharge=0");
446 is( $other_charges, 5, "Holds charges are considered if HoldsInNoissuesCharge=1");
449 subtest 'purgeSelfRegistration' => sub {
450 plan tests => 2;
452 #purge unverified
453 my $d=360;
454 C4::Members::DeleteUnverifiedOpacRegistrations($d);
455 foreach(1..3) {
456 $dbh->do("INSERT INTO borrower_modifications (timestamp, borrowernumber, verification_token) VALUES ('2014-01-01 01:02:03',0,?)", undef, (scalar localtime)."_$_");
458 is( C4::Members::DeleteUnverifiedOpacRegistrations($d), 3, 'Test for DeleteUnverifiedOpacRegistrations' );
460 #purge members in temporary category
461 my $c= 'XYZ';
462 $dbh->do("INSERT IGNORE INTO categories (categorycode) VALUES ('$c')");
463 t::lib::Mocks::mock_preference('PatronSelfRegistrationDefaultCategory', $c );
464 t::lib::Mocks::mock_preference('PatronSelfRegistrationExpireTemporaryAccountsDelay', 360);
465 C4::Members::DeleteExpiredOpacRegistrations();
466 $dbh->do("INSERT INTO borrowers (surname, address, city, branchcode, categorycode, dateenrolled) VALUES ('Testaabbcc', 'Street 1', 'CITY', ?, '$c', '2014-01-01 01:02:03')", undef, $library1->{branchcode});
467 is( C4::Members::DeleteExpiredOpacRegistrations(), 1, 'Test for DeleteExpiredOpacRegistrations');
470 sub _find_member {
471 my ($resultset) = @_;
472 my $found = $resultset && grep( { $_->{cardnumber} && $_->{cardnumber} eq $CARDNUMBER } @$resultset );
473 return $found;
476 # Regression tests for BZ15343
477 my $password="";
478 ( $borrowernumber, $password ) = AddMember_Opac(surname=>"Dick",firstname=>'Philip',branchcode => $library2->{branchcode});
479 is( $password =~ /^[a-zA-Z]{10}$/ , 1, 'Test for autogenerated password if none submitted');
480 ( $borrowernumber, $password ) = AddMember_Opac(surname=>"Deckard",firstname=>"Rick",password=>"Nexus-6",branchcode => $library2->{branchcode});
481 is( $password eq "Nexus-6", 1, 'Test password used if submitted');
482 $borrower = GetMember(borrowernumber => $borrowernumber);
483 my $hashed_up = Koha::AuthUtils::hash_password("Nexus-6", $borrower->{password});
484 is( $borrower->{password} eq $hashed_up, 1, 'Check password hash equals hash of submitted password' );
486 # regression test for bug 16009
487 my $patron;
488 eval {
489 my $patron = GetMember(cardnumber => undef);
491 is($@, '', 'Bug 16009: GetMember(cardnumber => undef) works');
492 is($patron, undef, 'Bug 16009: GetMember(cardnumber => undef) returns undef');