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

(-)a/Koha/Z3950Server.pm (-2 / +14 lines)
Lines 19-25 use Modern::Perl; Link Here
19
19
20
use Koha::Database;
20
use Koha::Database;
21
21
22
use base qw(Koha::Object);
22
use base qw(Koha::Object Koha::Object::Limit::Library);
23
23
24
=head1 NAME
24
=head1 NAME
25
25
Lines 27-36 Koha::Z3950Server - Koha Z3950Server Object class Link Here
27
27
28
=head1 API
28
=head1 API
29
29
30
=head2 Class Methods
30
=head2 Internal methods
31
32
=head3 _library_limits
33
34
Configure library limits for Z39.50 servers
31
35
32
=cut
36
=cut
33
37
38
sub _library_limits {
39
    return {
40
        class   => "Z3950serversBranch",
41
        id      => "server_id",
42
        library => "branchcode",
43
    };
44
}
45
34
=head3 _type
46
=head3 _type
35
47
36
Return type of Object relating to Schema ResultSet
48
Return type of Object relating to Schema ResultSet
(-)a/Koha/Z3950Servers.pm (-1 / +1 lines)
Lines 21-27 use Koha::Database; Link Here
21
21
22
use Koha::Z3950Server;
22
use Koha::Z3950Server;
23
23
24
use base qw(Koha::Objects);
24
use base qw(Koha::Objects Koha::Objects::Limit::Library);
25
25
26
=head1 NAME
26
=head1 NAME
27
27
(-)a/t/db_dependent/Koha/Z3950Servers.t (-2 / +64 lines)
Lines 19-25 Link Here
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
use Test::NoWarnings;
21
use Test::NoWarnings;
22
use Test::More tests => 3;
22
use Test::More tests => 4;
23
use Test::Exception;
23
use Test::Exception;
24
24
25
use t::lib::TestBuilder;
25
use t::lib::TestBuilder;
Lines 105-107 subtest 'Host, syntax and encoding are NOT NULL now (BZ 30571)' => sub { Link Here
105
105
106
    $schema->storage->txn_rollback;
106
    $schema->storage->txn_rollback;
107
};
107
};
108
- 
108
109
subtest 'library_limits' => sub {
110
    plan tests => 8;
111
112
    $schema->storage->txn_begin;
113
114
    my $library1 = $builder->build_object( { class => 'Koha::Libraries' } );
115
    my $library2 = $builder->build_object( { class => 'Koha::Libraries' } );
116
117
    my $server = $builder->build_object(
118
        {
119
            class => 'Koha::Z3950Servers',
120
            value => {
121
                host => 'test.example.com',
122
                port => 210,
123
                db   => 'testdb'
124
            }
125
        }
126
    );
127
128
    # Test adding library limit
129
    $server->add_library_limit( $library1->branchcode );
130
    my $limits = $server->library_limits();
131
    is( $limits->count,            1,                     'One library limit added' );
132
    is( $limits->next->branchcode, $library1->branchcode, 'Correct library limit' );
133
134
    # Test search with library limits
135
    my $servers = Koha::Z3950Servers->search_with_library_limits(
136
        { id => $server->id },
137
        {},
138
        $library1->branchcode
139
    );
140
    is( $servers->count, 1, 'Server found for authorized library' );
141
142
    $servers = Koha::Z3950Servers->search_with_library_limits(
143
        { id => $server->id },
144
        {},
145
        $library2->branchcode
146
    );
147
    is( $servers->count, 0, 'Server not found for unauthorized library' );
148
149
    # Test replacing library limits
150
    $server->library_limits( [ $library1->branchcode, $library2->branchcode ] );
151
    $limits = $server->library_limits();
152
    is( $limits->count, 2, 'Two library limits set' );
153
154
    # Test removing library limit
155
    $server->del_library_limit( $library1->branchcode );
156
    $limits = $server->library_limits();
157
    is( $limits->count,            1,                     'One library limit remains' );
158
    is( $limits->next->branchcode, $library2->branchcode, 'Correct remaining limit' );
159
160
    # Test server with no limits (available to all)
161
    my $unrestricted_server = $builder->build_object( { class => 'Koha::Z3950Servers' } );
162
    $servers = Koha::Z3950Servers->search_with_library_limits(
163
        { id => $unrestricted_server->id },
164
        {},
165
        $library1->branchcode
166
    );
167
    is( $servers->count, 1, 'Unrestricted server available to all libraries' );
168
169
    $schema->storage->txn_rollback;
170
};

Return to bug 40481