View | Details | Raw Unified | Return to bug 17492
Collapse All | Expand All

(-)a/Koha/Patron.pm (-1 / +1 lines)
Lines 583-589 sub is_category_valid { Link Here
583
    my $patroncategory = $self->category;
583
    my $patroncategory = $self->category;
584
    my ($low,$high) = ($patroncategory->dateofbirthrequired, $patroncategory->upperagelimit);
584
    my ($low,$high) = ($patroncategory->dateofbirthrequired, $patroncategory->upperagelimit);
585
585
586
    return (($high && ($age > $high)) or ($age < $low)) ? 0 : 1;
586
    return (defined($age) && (($high && ($age > $high)) or ($age < $low))) ? 0 : 1;
587
}
587
}
588
588
589
=head3 account
589
=head3 account
(-)a/t/db_dependent/Koha/Patrons.t (-2 / +59 lines)
Lines 19-25 Link Here
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Test::More tests => 22;
22
use Test::More tests => 23;
23
use Test::Warn;
23
use Test::Warn;
24
use Time::Fake;
24
use Time::Fake;
25
use DateTime;
25
use DateTime;
Lines 531-536 subtest 'get_age' => sub { Link Here
531
    $patron->delete;
531
    $patron->delete;
532
};
532
};
533
533
534
subtest 'is_category_valid' => sub {
535
    plan tests => 10;
536
537
    my $today = dt_from_string;
538
539
    my $category = $builder->build({
540
        source => 'Category',
541
        value => {
542
            categorycode        => 'AGE_5_10',
543
            dateofbirthrequired => 5,
544
            upperagelimit       => 10
545
        }
546
    });
547
    $category = Koha::Patron::Categories->find( $category->{categorycode} );
548
549
    my $patron = $builder->build({
550
        source => 'Borrower',
551
        value => {
552
            categorycode        => 'AGE_5_10'
553
        }
554
    });
555
    $patron = Koha::Patrons->find( $patron->{borrowernumber} );
556
557
558
    $patron->dateofbirth( undef );
559
    is( $patron->is_category_valid, 1, 'Patron with no dateofbirth is always valid for any category');
560
561
    $patron->dateofbirth( $today->clone->add( years => -12, months => -6, days => -1 ) );
562
    is( $patron->is_category_valid, 0, 'Patron is 12, so his age is above allowed range 5-10 years');
563
564
    $patron->dateofbirth( $today->clone->add( years => -3, months => -6, days => -1 ) );
565
    is( $patron->is_category_valid, 0, 'Patron is 3, so his age is below allowed range 5-10 years');
566
567
    $patron->dateofbirth( $today->clone->add( years => -7, months => -6, days => -1 ) );
568
    is( $patron->is_category_valid, 1, 'Patron is 7, so his age perfectly suits allowed range 5-10 years');
569
570
    $patron->dateofbirth( $today->clone->add( years => -5, months => 0, days => 0 ) );
571
    is( $patron->is_category_valid, 1, 'Patron celebrates the 5th birthday today, so he is allowed for this category');
572
573
    $patron->dateofbirth( $today->clone->add( years => -5, months => 0, days => 1 ) );
574
    is( $patron->is_category_valid, 0, 'Patron will celebrate the 5th birthday tomorrow, so he is NOT allowed for this category');
575
576
    $patron->dateofbirth( $today->clone->add( years => -5, months => 0, days => -1 ) );
577
    is( $patron->is_category_valid, 1, 'Patron celebrated the 5th birthday yesterday, so he is allowed for this category');
578
579
    $patron->dateofbirth( $today->clone->add( years => -11, months => 0, days => 0 ) );
580
    is( $patron->is_category_valid, 0, 'Patron celebrate the 11th birthday today, so he is NOT allowed for this category');
581
582
    $patron->dateofbirth( $today->clone->add( years => -11, months => 0, days => 1 ) );
583
    is( $patron->is_category_valid, 1, 'Patron will celebrate the 11th birthday tomorrow, so he is allowed for this category');
584
585
    $patron->dateofbirth( $today->clone->add( years => -11, months => 0, days => -1 ) );
586
    is( $patron->is_category_valid, 0, 'Patron celebrated the 11th birthday yesterday, so he is NOT allowed for this category');
587
588
    $patron->delete;
589
    $category->delete;
590
};
591
534
subtest 'account' => sub {
592
subtest 'account' => sub {
535
    plan tests => 1;
593
    plan tests => 1;
536
594
537
- 

Return to bug 17492