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

(-)a/Koha/Patron/Attribute.pm (+30 lines)
Lines 17-22 package Koha::Patron::Attribute; Link Here
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use Koha::Patron::Attribute::Types;
21
20
use base qw(Koha::Object);
22
use base qw(Koha::Object);
21
23
22
=head1 NAME
24
=head1 NAME
Lines 29-34 Koha::Patron::Attribute - Koha Patron Attribute Object class Link Here
29
31
30
=cut
32
=cut
31
33
34
=head3 opac_display
35
36
    my $attribute = Koha::Patron::Attribute->new({ code => 'a_code', ... });
37
    if ( $attribute->opac_display ) { ... }
38
39
=cut
40
41
sub opac_display {
42
43
    my $self = shift;
44
45
    return Koha::Patron::Attribute::Types->find( $self->code )->opac_display;
46
}
47
48
=head3 opac_editable
49
50
    my $attribute = Koha::Patron::Attribute->new({ code => 'a_code', ... });
51
    if ( $attribute->is_opac_editable ) { ... }
52
53
=cut
54
55
sub opac_editable {
56
57
    my $self = shift;
58
59
    return Koha::Patron::Attribute::Types->find( $self->code )->opac_editable;
60
}
61
32
=head3 _type
62
=head3 _type
33
63
34
=cut
64
=cut
(-)a/t/db_dependent/Koha/Patron/Attributes.t (-1 / +110 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/perl
2
3
# Copyright 2016 Koha Development team
4
#
5
# This file is part of Koha
6
#
7
# Koha is free software; you can redistribute it and/or modify it
8
# under the terms of the GNU General Public License as published by
9
# the Free Software Foundation; either version 3 of the License, or
10
# (at your option) any later version.
11
#
12
# Koha is distributed in the hope that it will be useful, but
13
# WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
16
#
17
# You should have received a copy of the GNU General Public License
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
19
20
use Modern::Perl;
21
22
use Test::More tests => 2;
23
24
use t::lib::TestBuilder;
25
26
use Koha::Database;
27
use Koha::Patron::Attribute;
28
29
my $schema  = Koha::Database->new->schema;
30
my $builder = t::lib::TestBuilder->new;
31
32
subtest 'opac_display() tests' => sub {
33
34
    plan tests => 2;
35
36
    $schema->storage->txn_begin;
37
38
    my $patron
39
        = $builder->build( { source => 'Borrower' } )->{borrowernumber};
40
    my $attribute_type_1 = $builder->build(
41
        {   source => 'BorrowerAttributeType',
42
            value  => { opac_display => 1 }
43
        }
44
    );
45
46
    my $attribute_1 = Koha::Patron::Attribute->new(
47
        {   borrowernumber => $patron,
48
            code           => $attribute_type_1->{code},
49
            attribute      => $patron
50
        }
51
    );
52
    is( $attribute_1->opac_display, 1, '->opac_display returns 1' );
53
54
    my $attribute_type_2 = $builder->build(
55
        {   source => 'BorrowerAttributeType',
56
            value  => { opac_display => 0 }
57
        }
58
    );
59
60
    my $attribute_2 = Koha::Patron::Attribute->new(
61
        {   borrowernumber => $patron,
62
            code           => $attribute_type_2->{code},
63
            attribute      => $patron
64
        }
65
    );
66
    is( $attribute_2->opac_display, 0, '->opac_display returns 0' );
67
68
    $schema->storage->txn_rollback;
69
};
70
71
subtest 'opac_editable() tests' => sub {
72
73
    plan tests => 2;
74
75
    $schema->storage->txn_begin;
76
77
    my $patron
78
        = $builder->build( { source => 'Borrower' } )->{borrowernumber};
79
    my $attribute_type_1 = $builder->build(
80
        {   source => 'BorrowerAttributeType',
81
            value  => { opac_editable => 1 }
82
        }
83
    );
84
85
    my $attribute_1 = Koha::Patron::Attribute->new(
86
        {   borrowernumber => $patron,
87
            code           => $attribute_type_1->{code},
88
            attribute      => $patron
89
        }
90
    );
91
    is( $attribute_1->opac_editable, 1, '->opac_editable returns 1' );
92
93
    my $attribute_type_2 = $builder->build(
94
        {   source => 'BorrowerAttributeType',
95
            value  => { opac_editable => 0 }
96
        }
97
    );
98
99
    my $attribute_2 = Koha::Patron::Attribute->new(
100
        {   borrowernumber => $patron,
101
            code           => $attribute_type_2->{code},
102
            attribute      => $patron
103
        }
104
    );
105
    is( $attribute_2->opac_editable, 0, '->opac_editable returns 0' );
106
107
    $schema->storage->txn_rollback;
108
};
109
110
1;

Return to bug 17792