Lines 17-23
Link Here
|
17 |
|
17 |
|
18 |
use Modern::Perl; |
18 |
use Modern::Perl; |
19 |
|
19 |
|
20 |
use Test::More tests => 56; |
20 |
use Test::More tests => 67; |
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 182-192
C4::Context->clear_syspref_cache();
Link Here
|
182 |
$checkcardnum=C4::Members::checkcardnumber($IMPOSSIBLE_CARDNUMBER, ""); |
184 |
$checkcardnum=C4::Members::checkcardnumber($IMPOSSIBLE_CARDNUMBER, ""); |
183 |
is ($checkcardnum, "2", "Card number is too long"); |
185 |
is ($checkcardnum, "2", "Card number is too long"); |
184 |
|
186 |
|
185 |
my $age=GetAge("1992-08-14", "2011-01-19"); |
|
|
186 |
is ($age, "18", "Age correct"); |
187 |
|
187 |
|
188 |
$age=GetAge("2011-01-19", "1992-01-19"); |
|
|
189 |
is ($age, "-19", "Birthday In the Future"); |
190 |
|
188 |
|
191 |
C4::Context->set_preference( 'AutoEmailPrimaryAddress', 'OFF' ); |
189 |
C4::Context->set_preference( 'AutoEmailPrimaryAddress', 'OFF' ); |
192 |
C4::Context->clear_syspref_cache(); |
190 |
C4::Context->clear_syspref_cache(); |
Lines 329-332
sub _find_member {
Link Here
|
329 |
return $found; |
327 |
return $found; |
330 |
} |
328 |
} |
331 |
|
329 |
|
|
|
330 |
### ------------------------------------- ### |
331 |
### Testing GetAge() / SetAge() functions ### |
332 |
### ------------------------------------- ### |
333 |
#USES the package $member-variable to mock a koha.borrowers-object |
334 |
sub testAgeAccessors { |
335 |
my ($member) = @_; |
336 |
|
337 |
##Testing GetAge() |
338 |
my $age=GetAge("1992-08-14", "2011-01-19"); |
339 |
is ($age, "18", "Age correct"); |
340 |
|
341 |
$age=GetAge("2011-01-19", "1992-01-19"); |
342 |
is ($age, "-19", "Birthday In the Future"); |
343 |
|
344 |
##Testing SetAge() for now() |
345 |
my $dt_now = DateTime->now(); |
346 |
my $age = DateTime::Duration->new(years => 12, months => 6, days => 1); |
347 |
C4::Members::SetAge( $member, $age ); |
348 |
$age = C4::Members::GetAge( $member->{dateofbirth} ); |
349 |
is ($age, '12', "SetAge 12 years"); |
350 |
|
351 |
$age = DateTime::Duration->new(years => 18, months => 12, days => 31); |
352 |
C4::Members::SetAge( $member, $age ); |
353 |
$age = C4::Members::GetAge( $member->{dateofbirth} ); |
354 |
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. |
355 |
|
356 |
$age = DateTime::Duration->new(years => 18, months => 12, days => 30); |
357 |
C4::Members::SetAge( $member, $age ); |
358 |
$age = C4::Members::GetAge( $member->{dateofbirth} ); |
359 |
is ($age, '19', "SetAge 18 years"); |
360 |
|
361 |
$age = DateTime::Duration->new(years => 0, months => 1, days => 1); |
362 |
C4::Members::SetAge( $member, $age ); |
363 |
$age = C4::Members::GetAge( $member->{dateofbirth} ); |
364 |
is ($age, '0', "SetAge 0 years"); |
365 |
|
366 |
$age = '0018-12-31'; |
367 |
C4::Members::SetAge( $member, $age ); |
368 |
$age = C4::Members::GetAge( $member->{dateofbirth} ); |
369 |
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. |
370 |
|
371 |
$age = '0018-12-30'; |
372 |
C4::Members::SetAge( $member, $age ); |
373 |
$age = C4::Members::GetAge( $member->{dateofbirth} ); |
374 |
is ($age, '19', "SetAge ISO_Date 18 years"); |
375 |
|
376 |
$age = '18-1-1'; |
377 |
eval { C4::Members::SetAge( $member, $age ); }; |
378 |
is ((length $@ > 1), '1', "SetAge ISO_Date $age years FAILS"); |
379 |
|
380 |
$age = '0018-01-01'; |
381 |
eval { C4::Members::SetAge( $member, $age ); }; |
382 |
is ((length $@ == 0), '1', "SetAge ISO_Date $age years succeeds"); |
383 |
|
384 |
##Testing SetAge() for relative_date |
385 |
my $relative_date = DateTime->new(year => 3010, month => 3, day => 15); |
386 |
|
387 |
$age = DateTime::Duration->new(years => 10, months => 3); |
388 |
C4::Members::SetAge( $member, $age, $relative_date ); |
389 |
$age = C4::Members::GetAge( $member->{dateofbirth}, $relative_date->ymd() ); |
390 |
is ($age, '10', "SetAge, 10 years and 3 months old person was born on ".$member->{dateofbirth}." if todays is ".$relative_date->ymd()); |
391 |
|
392 |
$age = DateTime::Duration->new(years => 112, months => 1, days => 1); |
393 |
C4::Members::SetAge( $member, $age, $relative_date ); |
394 |
$age = C4::Members::GetAge( $member->{dateofbirth}, $relative_date->ymd() ); |
395 |
is ($age, '112', "SetAge, 112 years, 1 months and 1 days old person was born on ".$member->{dateofbirth}." if today is ".$relative_date->ymd()); |
396 |
|
397 |
$age = '0112-01-01'; |
398 |
C4::Members::SetAge( $member, $age, $relative_date ); |
399 |
$age = C4::Members::GetAge( $member->{dateofbirth}, $relative_date->ymd() ); |
400 |
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()); |
401 |
|
402 |
} #sub testAgeAccessors |
403 |
|
332 |
1; |
404 |
1; |
333 |
- |
|
|