Bug 18789: Add tests for is_adult and is_child
This patch add 2 methods to the Koha::Patron module: is_adult and is_child. That way the business logic is at only one place and covered by tests. Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com> Signed-off-by: Josef Moravec <josef.moravec@gmail.com> Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
This commit is contained in:
parent
b4c23e1a3e
commit
e5f70a6010
2 changed files with 77 additions and 0 deletions
|
@ -806,6 +806,16 @@ sub has_permission {
|
|||
return C4::Auth::haspermission( $self->userid, $flagsrequired );
|
||||
}
|
||||
|
||||
sub is_adult {
|
||||
my ( $self ) = @_;
|
||||
return $self->category->category_type =~ /^(A|I)$/ ? 1 : 0;
|
||||
}
|
||||
|
||||
sub is_child {
|
||||
my( $self ) = @_;
|
||||
return $self->category->category_type eq 'C' ? 1 : 0;
|
||||
}
|
||||
|
||||
=head3 type
|
||||
|
||||
=cut
|
||||
|
|
|
@ -1055,6 +1055,73 @@ subtest 'account_locked' => sub {
|
|||
$patron->delete;
|
||||
};
|
||||
|
||||
subtest 'is_child | is_adult' => sub {
|
||||
plan tests => 8;
|
||||
my $category = $builder->build_object(
|
||||
{
|
||||
class => 'Koha::Patron::Categories',
|
||||
value => { category_type => 'A' }
|
||||
}
|
||||
);
|
||||
my $patron_adult = $builder->build_object(
|
||||
{
|
||||
class => 'Koha::Patrons',
|
||||
value => { categorycode => $category->categorycode }
|
||||
}
|
||||
);
|
||||
$category = $builder->build_object(
|
||||
{
|
||||
class => 'Koha::Patron::Categories',
|
||||
value => { category_type => 'I' }
|
||||
}
|
||||
);
|
||||
my $patron_adult_i = $builder->build_object(
|
||||
{
|
||||
class => 'Koha::Patrons',
|
||||
value => { categorycode => $category->categorycode }
|
||||
}
|
||||
);
|
||||
$category = $builder->build_object(
|
||||
{
|
||||
class => 'Koha::Patron::Categories',
|
||||
value => { category_type => 'C' }
|
||||
}
|
||||
);
|
||||
my $patron_child = $builder->build_object(
|
||||
{
|
||||
class => 'Koha::Patrons',
|
||||
value => { categorycode => $category->categorycode }
|
||||
}
|
||||
);
|
||||
$category = $builder->build_object(
|
||||
{
|
||||
class => 'Koha::Patron::Categories',
|
||||
value => { category_type => 'O' }
|
||||
}
|
||||
);
|
||||
my $patron_other = $builder->build_object(
|
||||
{
|
||||
class => 'Koha::Patrons',
|
||||
value => { categorycode => $category->categorycode }
|
||||
}
|
||||
);
|
||||
is( $patron_adult->is_adult, 1, 'Patron from category A should be considered adult' );
|
||||
is( $patron_adult_i->is_adult, 1, 'Patron from category I should be considered adult' );
|
||||
is( $patron_child->is_adult, 0, 'Patron from category C should not be considered adult' );
|
||||
is( $patron_other->is_adult, 0, 'Patron from category O should not be considered adult' );
|
||||
|
||||
is( $patron_adult->is_child, 0, 'Patron from category A should be considered child' );
|
||||
is( $patron_adult_i->is_child, 0, 'Patron from category I should be considered child' );
|
||||
is( $patron_child->is_child, 1, 'Patron from category C should not be considered child' );
|
||||
is( $patron_other->is_child, 0, 'Patron from category O should not be considered child' );
|
||||
|
||||
# Clean up
|
||||
$patron_adult->delete;
|
||||
$patron_adult_i->delete;
|
||||
$patron_child->delete;
|
||||
$patron_other->delete;
|
||||
};
|
||||
|
||||
$retrieved_patron_1->delete;
|
||||
is( Koha::Patrons->search->count, $nb_of_patrons + 1, 'Delete should have deleted the patron' );
|
||||
|
||||
|
|
Loading…
Reference in a new issue