Lines 17-23
Link Here
|
17 |
|
17 |
|
18 |
use Modern::Perl; |
18 |
use Modern::Perl; |
19 |
|
19 |
|
20 |
use Test::More tests => 79; |
20 |
use Test::More tests => 66; |
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 90-97
my %data = (
Link Here
|
90 |
userid => 'tomasito' |
90 |
userid => 'tomasito' |
91 |
); |
91 |
); |
92 |
|
92 |
|
93 |
testAgeAccessors(\%data); #Age accessor tests don't touch the db so it is safe to run them with just the object. |
|
|
94 |
|
95 |
my $addmem=AddMember(%data); |
93 |
my $addmem=AddMember(%data); |
96 |
ok($addmem, "AddMember()"); |
94 |
ok($addmem, "AddMember()"); |
97 |
|
95 |
|
Lines 497-580
$borrower = GetMember(borrowernumber => $borrowernumber);
Link Here
|
497 |
my $hashed_up = Koha::AuthUtils::hash_password("Nexus-6", $borrower->{password}); |
495 |
my $hashed_up = Koha::AuthUtils::hash_password("Nexus-6", $borrower->{password}); |
498 |
is( $borrower->{password} eq $hashed_up, 1, 'Check password hash equals hash of submitted password' ); |
496 |
is( $borrower->{password} eq $hashed_up, 1, 'Check password hash equals hash of submitted password' ); |
499 |
|
497 |
|
500 |
|
|
|
501 |
|
502 |
### ------------------------------------- ### |
503 |
### Testing GetAge() / SetAge() functions ### |
504 |
### ------------------------------------- ### |
505 |
#USES the package $member-variable to mock a koha.borrowers-object |
506 |
sub testAgeAccessors { |
507 |
my ($member) = @_; |
508 |
my $original_dateofbirth = $member->{dateofbirth}; |
509 |
|
510 |
##Testing GetAge() |
511 |
my $age=GetAge("1992-08-14", "2011-01-19"); |
512 |
is ($age, "18", "Age correct"); |
513 |
|
514 |
$age=GetAge("2011-01-19", "1992-01-19"); |
515 |
is ($age, "-19", "Birthday In the Future"); |
516 |
|
517 |
##Testing SetAge() for now() |
518 |
my $dt_now = DateTime->now(); |
519 |
$age = DateTime::Duration->new(years => 12, months => 6, days => 1); |
520 |
C4::Members::SetAge( $member, $age ); |
521 |
$age = C4::Members::GetAge( $member->{dateofbirth} ); |
522 |
is ($age, '12', "SetAge 12 years"); |
523 |
|
524 |
$age = DateTime::Duration->new(years => 18, months => 12, days => 31); |
525 |
C4::Members::SetAge( $member, $age ); |
526 |
$age = C4::Members::GetAge( $member->{dateofbirth} ); |
527 |
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. |
528 |
|
529 |
$age = DateTime::Duration->new(years => 18, months => 12, days => 30); |
530 |
C4::Members::SetAge( $member, $age ); |
531 |
$age = C4::Members::GetAge( $member->{dateofbirth} ); |
532 |
is ($age, '19', "SetAge 18 years"); |
533 |
|
534 |
$age = DateTime::Duration->new(years => 0, months => 1, days => 1); |
535 |
C4::Members::SetAge( $member, $age ); |
536 |
$age = C4::Members::GetAge( $member->{dateofbirth} ); |
537 |
is ($age, '0', "SetAge 0 years"); |
538 |
|
539 |
$age = '0018-12-31'; |
540 |
C4::Members::SetAge( $member, $age ); |
541 |
$age = C4::Members::GetAge( $member->{dateofbirth} ); |
542 |
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. |
543 |
|
544 |
$age = '0018-12-30'; |
545 |
C4::Members::SetAge( $member, $age ); |
546 |
$age = C4::Members::GetAge( $member->{dateofbirth} ); |
547 |
is ($age, '19', "SetAge ISO_Date 18 years"); |
548 |
|
549 |
$age = '18-1-1'; |
550 |
eval { C4::Members::SetAge( $member, $age ); }; |
551 |
is ((length $@ > 1), '1', "SetAge ISO_Date $age years FAILS"); |
552 |
|
553 |
$age = '0018-01-01'; |
554 |
eval { C4::Members::SetAge( $member, $age ); }; |
555 |
is ((length $@ == 0), '1', "SetAge ISO_Date $age years succeeds"); |
556 |
|
557 |
##Testing SetAge() for relative_date |
558 |
my $relative_date = DateTime->new(year => 3010, month => 3, day => 15); |
559 |
|
560 |
$age = DateTime::Duration->new(years => 10, months => 3); |
561 |
C4::Members::SetAge( $member, $age, $relative_date ); |
562 |
$age = C4::Members::GetAge( $member->{dateofbirth}, $relative_date->ymd() ); |
563 |
is ($age, '10', "SetAge, 10 years and 3 months old person was born on ".$member->{dateofbirth}." if todays is ".$relative_date->ymd()); |
564 |
|
565 |
$age = DateTime::Duration->new(years => 112, months => 1, days => 1); |
566 |
C4::Members::SetAge( $member, $age, $relative_date ); |
567 |
$age = C4::Members::GetAge( $member->{dateofbirth}, $relative_date->ymd() ); |
568 |
is ($age, '112', "SetAge, 112 years, 1 months and 1 days old person was born on ".$member->{dateofbirth}." if today is ".$relative_date->ymd()); |
569 |
|
570 |
$age = '0112-01-01'; |
571 |
C4::Members::SetAge( $member, $age, $relative_date ); |
572 |
$age = C4::Members::GetAge( $member->{dateofbirth}, $relative_date->ymd() ); |
573 |
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()); |
574 |
|
575 |
$member->{dateofbirth} = $original_dateofbirth; #It is polite to revert made changes in the unit tests. |
576 |
} #sub testAgeAccessors |
577 |
|
578 |
# regression test for bug 16009 |
498 |
# regression test for bug 16009 |
579 |
my $patron; |
499 |
my $patron; |
580 |
eval { |
500 |
eval { |
581 |
- |
|
|