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

(-)a/Koha/Patron/Restriction/Types.pm (-18 lines)
Lines 32-55 Koha::Patron::Restriction::Types - Koha Restriction Types Object set class Link Here
32
32
33
=cut
33
=cut
34
34
35
=head3 keyed_on_code
36
37
Return all restriction types as a hashref keyed on the code
38
39
=cut
40
41
sub keyed_on_code {
42
    my ( $self ) = @_;
43
44
    my @all = $self->_resultset()->search();
45
    my $out = {};
46
    for my $r( @all ) {
47
        my %col = $r->get_columns;
48
        $out->{$r->code} = \%col;
49
    }
50
    return $out;
51
}
52
53
=head3 _type
35
=head3 _type
54
36
55
=cut
37
=cut
(-)a/t/db_dependent/Koha/Patron/Restriction/Types.t (-64 lines)
Lines 1-63 Link Here
1
#!/usr/bin/perl
2
3
use Modern::Perl;
4
5
use C4::Context;
6
use Koha::Database;
7
use t::lib::TestBuilder;
8
9
use Test::More tests => 2;
10
11
my $schema = Koha::Database->new->schema;
12
$schema->storage->txn_begin;
13
my $dbh     = C4::Context->dbh;
14
my $builder = t::lib::TestBuilder->new;
15
16
use_ok('Koha::Patron::Restriction::Types');
17
18
$dbh->do(q|DELETE FROM borrower_debarments|);
19
$dbh->do(q|DELETE FROM restriction_types|);
20
21
$builder->build(
22
    {
23
        source => 'RestrictionType',
24
        value  => {
25
            code         => 'ONE',
26
            display_text => 'One',
27
            is_system    => 1,
28
            is_default   => 0
29
        }
30
    }
31
);
32
$builder->build(
33
    {
34
        source => 'RestrictionType',
35
        value  => {
36
            code         => 'TWO',
37
            display_text => 'Two',
38
            is_system    => 1,
39
            is_default   => 1
40
        }
41
    }
42
);
43
44
# keyed_on_code
45
my $keyed     = Koha::Patron::Restriction::Types->keyed_on_code;
46
my $expecting = {
47
    ONE => {
48
        code         => 'ONE',
49
        display_text => 'One',
50
        is_system    => 1,
51
        is_default   => 0
52
    },
53
    TWO => {
54
        code         => 'TWO',
55
        display_text => 'Two',
56
        is_system    => 1,
57
        is_default   => 1
58
    }
59
};
60
61
is_deeply( $keyed, $expecting, 'keyed_on_code returns correctly' );
62
63
$schema->storage->txn_rollback;
64
- 

Return to bug 31095