|
Lines 19-25
Link Here
|
| 19 |
|
19 |
|
| 20 |
use Modern::Perl; |
20 |
use Modern::Perl; |
| 21 |
|
21 |
|
| 22 |
use Test::More tests => 39; |
22 |
use Test::More tests => 40; |
| 23 |
use Test::Warn; |
23 |
use Test::Warn; |
| 24 |
use Test::Exception; |
24 |
use Test::Exception; |
| 25 |
use Test::MockModule; |
25 |
use Test::MockModule; |
|
Lines 639-644
subtest 'get_age' => sub {
Link Here
|
| 639 |
$patron->delete; |
639 |
$patron->delete; |
| 640 |
}; |
640 |
}; |
| 641 |
|
641 |
|
|
|
642 |
subtest 'is_category_valid' => sub { |
| 643 |
plan tests => 10; |
| 644 |
|
| 645 |
my $today = dt_from_string; |
| 646 |
|
| 647 |
my $category = $builder->build({ |
| 648 |
source => 'Category', |
| 649 |
value => { |
| 650 |
categorycode => 'AGE_5_10', |
| 651 |
dateofbirthrequired => 5, |
| 652 |
upperagelimit => 10 |
| 653 |
} |
| 654 |
}); |
| 655 |
$category = Koha::Patron::Categories->find( $category->{categorycode} ); |
| 656 |
|
| 657 |
my $patron = $builder->build({ |
| 658 |
source => 'Borrower', |
| 659 |
value => { |
| 660 |
categorycode => 'AGE_5_10' |
| 661 |
} |
| 662 |
}); |
| 663 |
$patron = Koha::Patrons->find( $patron->{borrowernumber} ); |
| 664 |
|
| 665 |
|
| 666 |
$patron->dateofbirth( undef ); |
| 667 |
is( $patron->is_category_valid, 1, 'Patron with no dateofbirth is always valid for any category'); |
| 668 |
|
| 669 |
$patron->dateofbirth( $today->clone->add( years => -12, months => -6, days => -1 ) ); |
| 670 |
is( $patron->is_category_valid, 0, 'Patron is 12, so the age is above allowed range 5-10 years'); |
| 671 |
|
| 672 |
$patron->dateofbirth( $today->clone->add( years => -3, months => -6, days => -1 ) ); |
| 673 |
is( $patron->is_category_valid, 0, 'Patron is 3, so the age is below allowed range 5-10 years'); |
| 674 |
|
| 675 |
$patron->dateofbirth( $today->clone->add( years => -7, months => -6, days => -1 ) ); |
| 676 |
is( $patron->is_category_valid, 1, 'Patron is 7, so the age perfectly suits allowed range 5-10 years'); |
| 677 |
|
| 678 |
$patron->dateofbirth( $today->clone->add( years => -5, months => 0, days => 0 ) ); |
| 679 |
is( $patron->is_category_valid, 1, 'Patron celebrates the 5th birthday today, so the age is allowed for this category'); |
| 680 |
|
| 681 |
$patron->dateofbirth( $today->clone->add( years => -5, months => 0, days => 1 ) ); |
| 682 |
is( $patron->is_category_valid, 0, 'Patron will celebrate the 5th birthday tomorrow, so the age is NOT allowed for this category'); |
| 683 |
|
| 684 |
$patron->dateofbirth( $today->clone->add( years => -5, months => 0, days => -1 ) ); |
| 685 |
is( $patron->is_category_valid, 1, 'Patron celebrated the 5th birthday yesterday, so the age is allowed for this category'); |
| 686 |
|
| 687 |
$patron->dateofbirth( $today->clone->add( years => -11, months => 0, days => 0 ) ); |
| 688 |
is( $patron->is_category_valid, 0, 'Patron celebrate the 11th birthday today, so the age is NOT allowed for this category'); |
| 689 |
|
| 690 |
$patron->dateofbirth( $today->clone->add( years => -11, months => 0, days => 1 ) ); |
| 691 |
is( $patron->is_category_valid, 1, 'Patron will celebrate the 11th birthday tomorrow, so the age is allowed for this category'); |
| 692 |
|
| 693 |
$patron->dateofbirth( $today->clone->add( years => -11, months => 0, days => -1 ) ); |
| 694 |
is( $patron->is_category_valid, 0, 'Patron celebrated the 11th birthday yesterday, so the age is NOT allowed for this category'); |
| 695 |
|
| 696 |
$patron->delete; |
| 697 |
$category->delete; |
| 698 |
}; |
| 699 |
|
| 642 |
subtest 'account' => sub { |
700 |
subtest 'account' => sub { |
| 643 |
plan tests => 1; |
701 |
plan tests => 1; |
| 644 |
|
702 |
|
| 645 |
- |
|
|