Lines 17-23
Link Here
|
17 |
|
17 |
|
18 |
use Modern::Perl; |
18 |
use Modern::Perl; |
19 |
|
19 |
|
20 |
use Test::More tests => 58; |
20 |
use Test::More tests => 69; |
21 |
use Test::MockModule; |
21 |
use Test::MockModule; |
22 |
use Data::Dumper; |
22 |
use Data::Dumper; |
23 |
use C4::Context; |
23 |
use C4::Context; |
Lines 82-87
my %data = (
Link Here
|
82 |
userid => 'tomasito' |
82 |
userid => 'tomasito' |
83 |
); |
83 |
); |
84 |
|
84 |
|
|
|
85 |
testAgeAccessors(\%data); #Age accessor tests don't touch the db so it is safe to run them with just the object. |
86 |
|
85 |
my $addmem=AddMember(%data); |
87 |
my $addmem=AddMember(%data); |
86 |
ok($addmem, "AddMember()"); |
88 |
ok($addmem, "AddMember()"); |
87 |
|
89 |
|
Lines 196-206
C4::Context->clear_syspref_cache();
Link Here
|
196 |
$checkcardnum=C4::Members::checkcardnumber($IMPOSSIBLE_CARDNUMBER, ""); |
198 |
$checkcardnum=C4::Members::checkcardnumber($IMPOSSIBLE_CARDNUMBER, ""); |
197 |
is ($checkcardnum, "2", "Card number is too long"); |
199 |
is ($checkcardnum, "2", "Card number is too long"); |
198 |
|
200 |
|
199 |
my $age=GetAge("1992-08-14", "2011-01-19"); |
|
|
200 |
is ($age, "18", "Age correct"); |
201 |
|
201 |
|
202 |
$age=GetAge("2011-01-19", "1992-01-19"); |
|
|
203 |
is ($age, "-19", "Birthday In the Future"); |
204 |
|
202 |
|
205 |
C4::Context->set_preference( 'AutoEmailPrimaryAddress', 'OFF' ); |
203 |
C4::Context->set_preference( 'AutoEmailPrimaryAddress', 'OFF' ); |
206 |
C4::Context->clear_syspref_cache(); |
204 |
C4::Context->clear_syspref_cache(); |
Lines 343-346
sub _find_member {
Link Here
|
343 |
return $found; |
341 |
return $found; |
344 |
} |
342 |
} |
345 |
|
343 |
|
|
|
344 |
### ------------------------------------- ### |
345 |
### Testing GetAge() / SetAge() functions ### |
346 |
### ------------------------------------- ### |
347 |
#USES the package $member-variable to mock a koha.borrowers-object |
348 |
sub testAgeAccessors { |
349 |
my ($member) = @_; |
350 |
my $original_dateofbirth = $member->{dateofbirth}; |
351 |
|
352 |
##Testing GetAge() |
353 |
my $age=GetAge("1992-08-14", "2011-01-19"); |
354 |
is ($age, "18", "Age correct"); |
355 |
|
356 |
$age=GetAge("2011-01-19", "1992-01-19"); |
357 |
is ($age, "-19", "Birthday In the Future"); |
358 |
|
359 |
##Testing SetAge() for now() |
360 |
my $dt_now = DateTime->now(); |
361 |
my $age = DateTime::Duration->new(years => 12, months => 6, days => 1); |
362 |
C4::Members::SetAge( $member, $age ); |
363 |
$age = C4::Members::GetAge( $member->{dateofbirth} ); |
364 |
is ($age, '12', "SetAge 12 years"); |
365 |
|
366 |
$age = DateTime::Duration->new(years => 18, months => 12, days => 31); |
367 |
C4::Members::SetAge( $member, $age ); |
368 |
$age = C4::Members::GetAge( $member->{dateofbirth} ); |
369 |
is ($age, '19', "SetAge 18+1 years"); #This is a special case, where months=>12 and days=>31 constitute one full year, hence we get age 19 instead of 18. |
370 |
|
371 |
$age = DateTime::Duration->new(years => 18, months => 12, days => 30); |
372 |
C4::Members::SetAge( $member, $age ); |
373 |
$age = C4::Members::GetAge( $member->{dateofbirth} ); |
374 |
is ($age, '19', "SetAge 18 years"); |
375 |
|
376 |
$age = DateTime::Duration->new(years => 0, months => 1, days => 1); |
377 |
C4::Members::SetAge( $member, $age ); |
378 |
$age = C4::Members::GetAge( $member->{dateofbirth} ); |
379 |
is ($age, '0', "SetAge 0 years"); |
380 |
|
381 |
$age = '0018-12-31'; |
382 |
C4::Members::SetAge( $member, $age ); |
383 |
$age = C4::Members::GetAge( $member->{dateofbirth} ); |
384 |
is ($age, '19', "SetAge ISO_Date 18+1 years"); #This is a special case, where months=>12 and days=>31 constitute one full year, hence we get age 19 instead of 18. |
385 |
|
386 |
$age = '0018-12-30'; |
387 |
C4::Members::SetAge( $member, $age ); |
388 |
$age = C4::Members::GetAge( $member->{dateofbirth} ); |
389 |
is ($age, '19', "SetAge ISO_Date 18 years"); |
390 |
|
391 |
$age = '18-1-1'; |
392 |
eval { C4::Members::SetAge( $member, $age ); }; |
393 |
is ((length $@ > 1), '1', "SetAge ISO_Date $age years FAILS"); |
394 |
|
395 |
$age = '0018-01-01'; |
396 |
eval { C4::Members::SetAge( $member, $age ); }; |
397 |
is ((length $@ == 0), '1', "SetAge ISO_Date $age years succeeds"); |
398 |
|
399 |
##Testing SetAge() for relative_date |
400 |
my $relative_date = DateTime->new(year => 3010, month => 3, day => 15); |
401 |
|
402 |
$age = DateTime::Duration->new(years => 10, months => 3); |
403 |
C4::Members::SetAge( $member, $age, $relative_date ); |
404 |
$age = C4::Members::GetAge( $member->{dateofbirth}, $relative_date->ymd() ); |
405 |
is ($age, '10', "SetAge, 10 years and 3 months old person was born on ".$member->{dateofbirth}." if todays is ".$relative_date->ymd()); |
406 |
|
407 |
$age = DateTime::Duration->new(years => 112, months => 1, days => 1); |
408 |
C4::Members::SetAge( $member, $age, $relative_date ); |
409 |
$age = C4::Members::GetAge( $member->{dateofbirth}, $relative_date->ymd() ); |
410 |
is ($age, '112', "SetAge, 112 years, 1 months and 1 days old person was born on ".$member->{dateofbirth}." if today is ".$relative_date->ymd()); |
411 |
|
412 |
$age = '0112-01-01'; |
413 |
C4::Members::SetAge( $member, $age, $relative_date ); |
414 |
$age = C4::Members::GetAge( $member->{dateofbirth}, $relative_date->ymd() ); |
415 |
is ($age, '112', "SetAge ISO_Date, 112 years, 1 months and 1 days old person was born on ".$member->{dateofbirth}." if today is ".$relative_date->ymd()); |
416 |
|
417 |
$member->{dateofbirth} = $original_dateofbirth; #It is polite to revert made changes in the unit tests. |
418 |
} #sub testAgeAccessors |
419 |
|
346 |
1; |
420 |
1; |
347 |
- |
|
|