|
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 |
}; |