Lines 17-23
Link Here
|
17 |
|
17 |
|
18 |
use Modern::Perl; |
18 |
use Modern::Perl; |
19 |
|
19 |
|
20 |
use Test::More tests => 74; |
20 |
use Test::More tests => 79; |
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 374-416
sub testAgeAccessors {
Link Here
|
374 |
my $original_dateofbirth = $member->{dateofbirth}; |
374 |
my $original_dateofbirth = $member->{dateofbirth}; |
375 |
|
375 |
|
376 |
##Testing GetAge() |
376 |
##Testing GetAge() |
377 |
my $age=GetAge("1992-08-14", "2011-01-19"); |
377 |
my ($age_year, $age_month) = GetAge("1992-08-14", "2011-01-19"); |
378 |
is ($age, "18", "Age correct"); |
378 |
is ($age_year, "18", "Age year correct"); |
|
|
379 |
is ($age_month, "5", "Age month correct"); |
379 |
|
380 |
|
380 |
$age=GetAge("2011-01-19", "1992-01-19"); |
381 |
($age_year, $age_month) = GetAge("2011-01-19", "1992-01-19"); |
381 |
is ($age, "-19", "Birthday In the Future"); |
382 |
is ($age_year, "-19", "Birthday In the Future"); |
382 |
|
383 |
|
383 |
##Testing SetAge() for now() |
384 |
##Testing SetAge() for now() |
384 |
my $dt_now = DateTime->now(); |
385 |
my $dt_now = DateTime->now(); |
385 |
$age = DateTime::Duration->new(years => 12, months => 6, days => 1); |
386 |
my $age = DateTime::Duration->new(years => 12, months => 6, days => 1); |
386 |
C4::Members::SetAge( $member, $age ); |
387 |
C4::Members::SetAge( $member, $age ); |
387 |
$age = C4::Members::GetAge( $member->{dateofbirth} ); |
388 |
($age_year, $age_month) = C4::Members::GetAge( $member->{dateofbirth} ); |
388 |
is ($age, '12', "SetAge 12 years"); |
389 |
is ($age_year, '12', "SetAge 12 years and 6 months"); |
|
|
390 |
is ($age_month, '6', "SetAge 12 years and 6 months"); |
389 |
|
391 |
|
390 |
$age = DateTime::Duration->new(years => 18, months => 12, days => 31); |
392 |
$age = DateTime::Duration->new(years => 18, months => 12, days => 31); |
391 |
C4::Members::SetAge( $member, $age ); |
393 |
C4::Members::SetAge( $member, $age ); |
392 |
$age = C4::Members::GetAge( $member->{dateofbirth} ); |
394 |
($age_year, $age_month) = C4::Members::GetAge( $member->{dateofbirth} ); |
393 |
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. |
395 |
is ($age_year, '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. |
|
|
396 |
is ($age_month, '1', "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. |
394 |
|
397 |
|
395 |
$age = DateTime::Duration->new(years => 18, months => 12, days => 30); |
398 |
$age = DateTime::Duration->new(years => 18, months => 12, days => 30); |
396 |
C4::Members::SetAge( $member, $age ); |
399 |
C4::Members::SetAge( $member, $age ); |
397 |
$age = C4::Members::GetAge( $member->{dateofbirth} ); |
400 |
($age_year, $age_month) = C4::Members::GetAge( $member->{dateofbirth} ); |
398 |
is ($age, '19', "SetAge 18 years"); |
401 |
is ($age_year, '19', "SetAge 18 years"); |
|
|
402 |
is ($age_month, '1', "SetAge 18 years"); |
399 |
|
403 |
|
400 |
$age = DateTime::Duration->new(years => 0, months => 1, days => 1); |
404 |
$age = DateTime::Duration->new(years => 0, months => 1, days => 1); |
401 |
C4::Members::SetAge( $member, $age ); |
405 |
C4::Members::SetAge( $member, $age ); |
402 |
$age = C4::Members::GetAge( $member->{dateofbirth} ); |
406 |
($age_year, $age_month) = C4::Members::GetAge( $member->{dateofbirth} ); |
403 |
is ($age, '0', "SetAge 0 years"); |
407 |
is ($age_year, '0', "SetAge 0 years"); |
|
|
408 |
is ($age_month, '1', "SetAge 0 years"); |
404 |
|
409 |
|
405 |
$age = '0018-12-31'; |
410 |
$age = '0018-12-31'; |
406 |
C4::Members::SetAge( $member, $age ); |
411 |
C4::Members::SetAge( $member, $age ); |
407 |
$age = C4::Members::GetAge( $member->{dateofbirth} ); |
412 |
($age_year, $age_month) = C4::Members::GetAge( $member->{dateofbirth} ); |
408 |
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. |
413 |
is ($age_year, '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. |
409 |
|
414 |
|
410 |
$age = '0018-12-30'; |
415 |
$age = '0018-12-30'; |
411 |
C4::Members::SetAge( $member, $age ); |
416 |
C4::Members::SetAge( $member, $age ); |
412 |
$age = C4::Members::GetAge( $member->{dateofbirth} ); |
417 |
($age_year, $age_month) = C4::Members::GetAge( $member->{dateofbirth} ); |
413 |
is ($age, '19', "SetAge ISO_Date 18 years"); |
418 |
is ($age_year, '19', "SetAge ISO_Date 18 years"); |
414 |
|
419 |
|
415 |
$age = '18-1-1'; |
420 |
$age = '18-1-1'; |
416 |
eval { C4::Members::SetAge( $member, $age ); }; |
421 |
eval { C4::Members::SetAge( $member, $age ); }; |
Lines 425-442
sub testAgeAccessors {
Link Here
|
425 |
|
430 |
|
426 |
$age = DateTime::Duration->new(years => 10, months => 3); |
431 |
$age = DateTime::Duration->new(years => 10, months => 3); |
427 |
C4::Members::SetAge( $member, $age, $relative_date ); |
432 |
C4::Members::SetAge( $member, $age, $relative_date ); |
428 |
$age = C4::Members::GetAge( $member->{dateofbirth}, $relative_date->ymd() ); |
433 |
($age_year, $age_month) = C4::Members::GetAge( $member->{dateofbirth}, $relative_date->ymd() ); |
429 |
is ($age, '10', "SetAge, 10 years and 3 months old person was born on ".$member->{dateofbirth}." if todays is ".$relative_date->ymd()); |
434 |
is ($age_year, '10', "SetAge, 10 years and 3 months old person was born on ".$member->{dateofbirth}." if todays is ".$relative_date->ymd()); |
430 |
|
435 |
|
431 |
$age = DateTime::Duration->new(years => 112, months => 1, days => 1); |
436 |
$age = DateTime::Duration->new(years => 112, months => 1, days => 1); |
432 |
C4::Members::SetAge( $member, $age, $relative_date ); |
437 |
C4::Members::SetAge( $member, $age, $relative_date ); |
433 |
$age = C4::Members::GetAge( $member->{dateofbirth}, $relative_date->ymd() ); |
438 |
($age_year, $age_month) = C4::Members::GetAge( $member->{dateofbirth}, $relative_date->ymd() ); |
434 |
is ($age, '112', "SetAge, 112 years, 1 months and 1 days old person was born on ".$member->{dateofbirth}." if today is ".$relative_date->ymd()); |
439 |
is ($age_year, '112', "SetAge, 112 years, 1 months and 1 days old person was born on ".$member->{dateofbirth}." if today is ".$relative_date->ymd()); |
435 |
|
440 |
|
436 |
$age = '0112-01-01'; |
441 |
$age = '0112-01-01'; |
437 |
C4::Members::SetAge( $member, $age, $relative_date ); |
442 |
C4::Members::SetAge( $member, $age, $relative_date ); |
438 |
$age = C4::Members::GetAge( $member->{dateofbirth}, $relative_date->ymd() ); |
443 |
($age_year, $age_month) = C4::Members::GetAge( $member->{dateofbirth}, $relative_date->ymd() ); |
439 |
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()); |
444 |
is ($age_year, '112', "SetAge ISO_Date, 112 years, 1 months and 1 days old person was born on ".$member->{dateofbirth}." if today is ".$relative_date->ymd()); |
440 |
|
445 |
|
441 |
$member->{dateofbirth} = $original_dateofbirth; #It is polite to revert made changes in the unit tests. |
446 |
$member->{dateofbirth} = $original_dateofbirth; #It is polite to revert made changes in the unit tests. |
442 |
} #sub testAgeAccessors |
447 |
} #sub testAgeAccessors |
443 |
- |
|
|