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

(-)a/Koha/Patron.pm (+10 lines)
Lines 801-806 sub can { Link Here
801
    return C4::Auth::haspermission( $self->userid, $flagsrequired );
801
    return C4::Auth::haspermission( $self->userid, $flagsrequired );
802
}
802
}
803
803
804
sub is_adult {
805
    my ( $self ) = @_;
806
    return $self->category->category_type =~ /^(A|I)$/ ? 1 : 0;
807
}
808
809
sub is_child {
810
    my( $self ) = @_;
811
    return $self->category->category_type eq 'C' ? 1 : 0;
812
}
813
804
=head3 type
814
=head3 type
805
815
806
=cut
816
=cut
(-)a/t/db_dependent/Koha/Patrons.t (-1 / +67 lines)
Lines 1055-1060 subtest 'account_locked' => sub { Link Here
1055
    $patron->delete;
1055
    $patron->delete;
1056
};
1056
};
1057
1057
1058
subtest 'is_child | is_adult' => sub {
1059
    plan tests => 8;
1060
    my $category = $builder->build_object(
1061
        {
1062
            class => 'Koha::Patron::Categories',
1063
            value => { category_type => 'A' }
1064
        }
1065
    );
1066
    my $patron_adult = $builder->build_object(
1067
        {
1068
            class => 'Koha::Patrons',
1069
            value => { categorycode => $category->categorycode }
1070
        }
1071
    );
1072
    $category = $builder->build_object(
1073
        {
1074
            class => 'Koha::Patron::Categories',
1075
            value => { category_type => 'I' }
1076
        }
1077
    );
1078
    my $patron_adult_i = $builder->build_object(
1079
        {
1080
            class => 'Koha::Patrons',
1081
            value => { categorycode => $category->categorycode }
1082
        }
1083
    );
1084
    $category = $builder->build_object(
1085
        {
1086
            class => 'Koha::Patron::Categories',
1087
            value => { category_type => 'C' }
1088
        }
1089
    );
1090
    my $patron_child = $builder->build_object(
1091
        {
1092
            class => 'Koha::Patrons',
1093
            value => { categorycode => $category->categorycode }
1094
        }
1095
    );
1096
    $category = $builder->build_object(
1097
        {
1098
            class => 'Koha::Patron::Categories',
1099
            value => { category_type => 'O' }
1100
        }
1101
    );
1102
    my $patron_other = $builder->build_object(
1103
        {
1104
            class => 'Koha::Patrons',
1105
            value => { categorycode => $category->categorycode }
1106
        }
1107
    );
1108
    is( $patron_adult->is_adult, 1, 'Patron from category A should be considered adult' );
1109
    is( $patron_adult_i->is_adult, 1, 'Patron from category I should be considered adult' );
1110
    is( $patron_child->is_adult, 0, 'Patron from category C should not be considered adult' );
1111
    is( $patron_other->is_adult, 0, 'Patron from category O should not be considered adult' );
1112
1113
    is( $patron_adult->is_child, 0, 'Patron from category A should be considered child' );
1114
    is( $patron_adult_i->is_child, 0, 'Patron from category I should be considered child' );
1115
    is( $patron_child->is_child, 1, 'Patron from category C should not be considered child' );
1116
    is( $patron_other->is_child, 0, 'Patron from category O should not be considered child' );
1117
1118
    # Clean up
1119
    $patron_adult->delete;
1120
    $patron_adult_i->delete;
1121
    $patron_child->delete;
1122
    $patron_other->delete;
1123
};
1124
1058
$retrieved_patron_1->delete;
1125
$retrieved_patron_1->delete;
1059
is( Koha::Patrons->search->count, $nb_of_patrons + 1, 'Delete should have deleted the patron' );
1126
is( Koha::Patrons->search->count, $nb_of_patrons + 1, 'Delete should have deleted the patron' );
1060
1127
1061
- 

Return to bug 18789