|
Lines 27-33
use Test::More tests => 5;
Link Here
|
| 27 |
|
27 |
|
| 28 |
my $schema = Koha::Database->new->schema; |
28 |
my $schema = Koha::Database->new->schema; |
| 29 |
my $builder = t::lib::TestBuilder->new; |
29 |
my $builder = t::lib::TestBuilder->new; |
| 30 |
use_ok('Koha::Illrequest::Config'); |
30 |
use_ok('Koha::ILL::Request::Config'); |
| 31 |
|
31 |
|
| 32 |
my $base_limits = { |
32 |
my $base_limits = { |
| 33 |
branch => { CPL => { count => 1, method => 'annual' } }, |
33 |
branch => { CPL => { count => 1, method => 'annual' } }, |
|
Lines 46-53
subtest 'Basics' => sub {
Link Here
|
| 46 |
t::lib::Mocks::mock_config("interlibrary_loans", {}); |
46 |
t::lib::Mocks::mock_config("interlibrary_loans", {}); |
| 47 |
t::lib::Mocks::mock_preference('ILLPartnerCode', undef); |
47 |
t::lib::Mocks::mock_preference('ILLPartnerCode', undef); |
| 48 |
|
48 |
|
| 49 |
my $config = Koha::Illrequest::Config->new; |
49 |
my $config = Koha::ILL::Request::Config->new; |
| 50 |
isa_ok($config, "Koha::Illrequest::Config", |
50 |
isa_ok($config, "Koha::ILL::Request::Config", |
| 51 |
"Correctly create and load a config object."); |
51 |
"Correctly create and load a config object."); |
| 52 |
|
52 |
|
| 53 |
# backend: |
53 |
# backend: |
|
Lines 98-119
subtest '_load_unit_config' => sub {
Link Here
|
| 98 |
|
98 |
|
| 99 |
$schema->storage->txn_begin; |
99 |
$schema->storage->txn_begin; |
| 100 |
|
100 |
|
| 101 |
my $config = Koha::Illrequest::Config->new; |
101 |
my $config = Koha::ILL::Request::Config->new; |
| 102 |
|
102 |
|
| 103 |
dies_ok( |
103 |
dies_ok( |
| 104 |
sub { Koha::Illrequest::Config::_load_unit_config({ |
104 |
sub { Koha::ILL::Request::Config::_load_unit_config({ |
| 105 |
id => 'durineadu', type => 'baz' |
105 |
id => 'durineadu', type => 'baz' |
| 106 |
}) }, |
106 |
}) }, |
| 107 |
"_load_unit_config: die if ID is not default, and type is not branch or brw_cat." |
107 |
"_load_unit_config: die if ID is not default, and type is not branch or brw_cat." |
| 108 |
); |
108 |
); |
| 109 |
is_deeply( |
109 |
is_deeply( |
| 110 |
Koha::Illrequest::Config::_load_unit_config({ |
110 |
Koha::ILL::Request::Config::_load_unit_config({ |
| 111 |
unit => {}, id => 'default', config => {}, test => 1 |
111 |
unit => {}, id => 'default', config => {}, test => 1 |
| 112 |
}), {}, "_load_unit_config: invocation without id returns unmodified config." |
112 |
}), {}, "_load_unit_config: invocation without id returns unmodified config." |
| 113 |
); |
113 |
); |
| 114 |
|
114 |
|
| 115 |
is_deeply( |
115 |
is_deeply( |
| 116 |
Koha::Illrequest::Config::_load_unit_config({ |
116 |
Koha::ILL::Request::Config::_load_unit_config({ |
| 117 |
unit => { api_key => 'foo', api_auth => 'bar' }, |
117 |
unit => { api_key => 'foo', api_auth => 'bar' }, |
| 118 |
id => "CPL", type => 'branch', config => {} |
118 |
id => "CPL", type => 'branch', config => {} |
| 119 |
}), |
119 |
}), |
|
Lines 123-141
subtest '_load_unit_config' => sub {
Link Here
|
| 123 |
|
123 |
|
| 124 |
# Populate request_limits |
124 |
# Populate request_limits |
| 125 |
is_deeply( |
125 |
is_deeply( |
| 126 |
Koha::Illrequest::Config::_load_unit_config({ |
126 |
Koha::ILL::Request::Config::_load_unit_config({ |
| 127 |
unit => { request_limit => [ 'heelo', 1234 ] }, |
127 |
unit => { request_limit => [ 'heelo', 1234 ] }, |
| 128 |
id => "CPL", type => 'branch', config => {} |
128 |
id => "CPL", type => 'branch', config => {} |
| 129 |
}), {}, "_load_unit_config: invalid request_limit structure." |
129 |
}), {}, "_load_unit_config: invalid request_limit structure." |
| 130 |
); |
130 |
); |
| 131 |
is_deeply( |
131 |
is_deeply( |
| 132 |
Koha::Illrequest::Config::_load_unit_config({ |
132 |
Koha::ILL::Request::Config::_load_unit_config({ |
| 133 |
unit => { request_limit => { method => 'eudiren', count => '-5465' } }, |
133 |
unit => { request_limit => { method => 'eudiren', count => '-5465' } }, |
| 134 |
id => "CPL", type => 'branch', config => {} |
134 |
id => "CPL", type => 'branch', config => {} |
| 135 |
}), {}, "_load_unit_config: invalid method & count." |
135 |
}), {}, "_load_unit_config: invalid method & count." |
| 136 |
); |
136 |
); |
| 137 |
is_deeply( |
137 |
is_deeply( |
| 138 |
Koha::Illrequest::Config::_load_unit_config({ |
138 |
Koha::ILL::Request::Config::_load_unit_config({ |
| 139 |
unit => { request_limit => { method => 'annual', count => 6 } }, |
139 |
unit => { request_limit => { method => 'annual', count => 6 } }, |
| 140 |
id => "default", config => {} |
140 |
id => "default", config => {} |
| 141 |
}), |
141 |
}), |
|
Lines 145-151
subtest '_load_unit_config' => sub {
Link Here
|
| 145 |
|
145 |
|
| 146 |
# Populate prefix |
146 |
# Populate prefix |
| 147 |
is_deeply( |
147 |
is_deeply( |
| 148 |
Koha::Illrequest::Config::_load_unit_config({ |
148 |
Koha::ILL::Request::Config::_load_unit_config({ |
| 149 |
unit => { prefix => 'Foo-ill' }, |
149 |
unit => { prefix => 'Foo-ill' }, |
| 150 |
id => "default", config => {} |
150 |
id => "default", config => {} |
| 151 |
}), |
151 |
}), |
|
Lines 153-159
subtest '_load_unit_config' => sub {
Link Here
|
| 153 |
"_load_unit_config: correct default prefix." |
153 |
"_load_unit_config: correct default prefix." |
| 154 |
); |
154 |
); |
| 155 |
is_deeply( |
155 |
is_deeply( |
| 156 |
Koha::Illrequest::Config::_load_unit_config({ |
156 |
Koha::ILL::Request::Config::_load_unit_config({ |
| 157 |
unit => { prefix => 'Foo-ill' }, |
157 |
unit => { prefix => 'Foo-ill' }, |
| 158 |
id => "A", config => {}, type => 'brw_cat' |
158 |
id => "A", config => {}, type => 'brw_cat' |
| 159 |
}), |
159 |
}), |
|
Lines 163-169
subtest '_load_unit_config' => sub {
Link Here
|
| 163 |
|
163 |
|
| 164 |
# Populate digital_recipient |
164 |
# Populate digital_recipient |
| 165 |
is_deeply( |
165 |
is_deeply( |
| 166 |
Koha::Illrequest::Config::_load_unit_config({ |
166 |
Koha::ILL::Request::Config::_load_unit_config({ |
| 167 |
unit => { digital_recipient => 'borrower' }, |
167 |
unit => { digital_recipient => 'borrower' }, |
| 168 |
id => "default", config => {} |
168 |
id => "default", config => {} |
| 169 |
}), |
169 |
}), |
|
Lines 171-177
subtest '_load_unit_config' => sub {
Link Here
|
| 171 |
"_load_unit_config: correct default digital_recipient." |
171 |
"_load_unit_config: correct default digital_recipient." |
| 172 |
); |
172 |
); |
| 173 |
is_deeply( |
173 |
is_deeply( |
| 174 |
Koha::Illrequest::Config::_load_unit_config({ |
174 |
Koha::ILL::Request::Config::_load_unit_config({ |
| 175 |
unit => { digital_recipient => 'branch' }, |
175 |
unit => { digital_recipient => 'branch' }, |
| 176 |
id => "A", config => {}, type => 'brw_cat' |
176 |
id => "A", config => {}, type => 'brw_cat' |
| 177 |
}), |
177 |
}), |
|
Lines 198-209
subtest '_load_configuration' => sub {
Link Here
|
| 198 |
|
198 |
|
| 199 |
$schema->storage->txn_begin; |
199 |
$schema->storage->txn_begin; |
| 200 |
|
200 |
|
| 201 |
my $config = Koha::Illrequest::Config->new; |
201 |
my $config = Koha::ILL::Request::Config->new; |
| 202 |
t::lib::Mocks::mock_preference('ILLPartnerCode', 'IL'); |
202 |
t::lib::Mocks::mock_preference('ILLPartnerCode', 'IL'); |
| 203 |
|
203 |
|
| 204 |
# Return basic configuration |
204 |
# Return basic configuration |
| 205 |
is_deeply( |
205 |
is_deeply( |
| 206 |
Koha::Illrequest::Config::_load_configuration({}, 0), |
206 |
Koha::ILL::Request::Config::_load_configuration( {}, 0 ), |
| 207 |
{ |
207 |
{ |
| 208 |
backend_directory => undef, |
208 |
backend_directory => undef, |
| 209 |
censorship => { |
209 |
censorship => { |
|
Lines 221-227
subtest '_load_configuration' => sub {
Link Here
|
| 221 |
|
221 |
|
| 222 |
# Return correct backend_dir |
222 |
# Return correct backend_dir |
| 223 |
is_deeply( |
223 |
is_deeply( |
| 224 |
Koha::Illrequest::Config::_load_configuration({ backend_directory => '/tmp/' }, 0), |
224 |
Koha::ILL::Request::Config::_load_configuration( { backend_directory => '/tmp/' }, 0 ), |
| 225 |
{ |
225 |
{ |
| 226 |
backend_directory => '/tmp/', |
226 |
backend_directory => '/tmp/', |
| 227 |
censorship => { |
227 |
censorship => { |
|
Lines 247-253
subtest '_load_configuration' => sub {
Link Here
|
| 247 |
] |
247 |
] |
| 248 |
}; |
248 |
}; |
| 249 |
is_deeply( |
249 |
is_deeply( |
| 250 |
Koha::Illrequest::Config::_load_configuration($xml_config, 0), |
250 |
Koha::ILL::Request::Config::_load_configuration( $xml_config, 0 ), |
| 251 |
{ |
251 |
{ |
| 252 |
backend_directory => '/tmp/', |
252 |
backend_directory => '/tmp/', |
| 253 |
censorship => { |
253 |
censorship => { |
|
Lines 273-279
subtest '_load_configuration' => sub {
Link Here
|
| 273 |
} |
273 |
} |
| 274 |
}; |
274 |
}; |
| 275 |
is_deeply( |
275 |
is_deeply( |
| 276 |
Koha::Illrequest::Config::_load_configuration($xml_config, 0), |
276 |
Koha::ILL::Request::Config::_load_configuration( $xml_config, 0 ), |
| 277 |
{ |
277 |
{ |
| 278 |
backend_directory => '/tmp/', |
278 |
backend_directory => '/tmp/', |
| 279 |
censorship => { |
279 |
censorship => { |
|
Lines 299-305
subtest '_load_configuration' => sub {
Link Here
|
| 299 |
] |
299 |
] |
| 300 |
}; |
300 |
}; |
| 301 |
is_deeply( |
301 |
is_deeply( |
| 302 |
Koha::Illrequest::Config::_load_configuration($xml_config, 0), |
302 |
Koha::ILL::Request::Config::_load_configuration( $xml_config, 0 ), |
| 303 |
{ |
303 |
{ |
| 304 |
backend_directory => '/tmp/', |
304 |
backend_directory => '/tmp/', |
| 305 |
censorship => { |
305 |
censorship => { |
|
Lines 325-331
subtest '_load_configuration' => sub {
Link Here
|
| 325 |
} |
325 |
} |
| 326 |
}; |
326 |
}; |
| 327 |
is_deeply( |
327 |
is_deeply( |
| 328 |
Koha::Illrequest::Config::_load_configuration($xml_config, 0), |
328 |
Koha::ILL::Request::Config::_load_configuration( $xml_config, 0 ), |
| 329 |
{ |
329 |
{ |
| 330 |
backend_directory => '/tmp/', |
330 |
backend_directory => '/tmp/', |
| 331 |
censorship => { |
331 |
censorship => { |
|
Lines 349-355
subtest '_load_configuration' => sub {
Link Here
|
| 349 |
digital_recipient => 'branch', |
349 |
digital_recipient => 'branch', |
| 350 |
}; |
350 |
}; |
| 351 |
is_deeply( |
351 |
is_deeply( |
| 352 |
Koha::Illrequest::Config::_load_configuration($xml_config, 0), |
352 |
Koha::ILL::Request::Config::_load_configuration( $xml_config, 0 ), |
| 353 |
{ |
353 |
{ |
| 354 |
backend_directory => '/tmp/', |
354 |
backend_directory => '/tmp/', |
| 355 |
censorship => { |
355 |
censorship => { |
|
Lines 372-378
subtest '_load_configuration' => sub {
Link Here
|
| 372 |
reply_date => 'hide' |
372 |
reply_date => 'hide' |
| 373 |
}; |
373 |
}; |
| 374 |
is_deeply( |
374 |
is_deeply( |
| 375 |
Koha::Illrequest::Config::_load_configuration($xml_config, 0), |
375 |
Koha::ILL::Request::Config::_load_configuration( $xml_config, 0 ), |
| 376 |
{ |
376 |
{ |
| 377 |
backend_directory => '/tmp/', |
377 |
backend_directory => '/tmp/', |
| 378 |
censorship => { |
378 |
censorship => { |
|
Lines 390-396
subtest '_load_configuration' => sub {
Link Here
|
| 390 |
|
390 |
|
| 391 |
# Partner library category |
391 |
# Partner library category |
| 392 |
is_deeply( |
392 |
is_deeply( |
| 393 |
Koha::Illrequest::Config::_load_configuration( { partner_code => 'FOOBAR' } ), |
393 |
Koha::ILL::Request::Config::_load_configuration( { partner_code => 'FOOBAR' } ), |
| 394 |
{ |
394 |
{ |
| 395 |
backend_directory => undef, |
395 |
backend_directory => undef, |
| 396 |
censorship => { |
396 |
censorship => { |
|
Lines 409-415
subtest '_load_configuration' => sub {
Link Here
|
| 409 |
t::lib::Mocks::mock_preference( 'ILLPartnerCode', 'FOOBAR' ); |
409 |
t::lib::Mocks::mock_preference( 'ILLPartnerCode', 'FOOBAR' ); |
| 410 |
|
410 |
|
| 411 |
is_deeply( |
411 |
is_deeply( |
| 412 |
Koha::Illrequest::Config::_load_configuration(), |
412 |
Koha::ILL::Request::Config::_load_configuration(), |
| 413 |
{ |
413 |
{ |
| 414 |
backend_directory => undef, |
414 |
backend_directory => undef, |
| 415 |
censorship => { |
415 |
censorship => { |
|
Lines 437-443
subtest 'Final tests' => sub {
Link Here
|
| 437 |
|
437 |
|
| 438 |
t::lib::Mocks::mock_config("interlibrary_loans", {}); |
438 |
t::lib::Mocks::mock_config("interlibrary_loans", {}); |
| 439 |
|
439 |
|
| 440 |
my $config = Koha::Illrequest::Config->new; |
440 |
my $config = Koha::ILL::Request::Config->new; |
| 441 |
|
441 |
|
| 442 |
# getPrefixes (error & undef): |
442 |
# getPrefixes (error & undef): |
| 443 |
is($config->getPrefixes(), undef, |
443 |
is($config->getPrefixes(), undef, |
|
Lines 453-459
subtest 'Final tests' => sub {
Link Here
|
| 453 |
is_deeply($config->getDigitalRecipients("branch"), { default => undef}, |
453 |
is_deeply($config->getDigitalRecipients("branch"), { default => undef}, |
| 454 |
"getDigitalRecipients: Undefined branch dig rec is undefined."); |
454 |
"getDigitalRecipients: Undefined branch dig rec is undefined."); |
| 455 |
|
455 |
|
| 456 |
$config->{configuration} = Koha::Illrequest::Config::_load_configuration({ |
456 |
$config->{configuration} = Koha::ILL::Request::Config::_load_configuration({ |
| 457 |
backend_directory => '/tmp/', |
457 |
backend_directory => '/tmp/', |
| 458 |
prefix => 'DEFAULT-prefix', |
458 |
prefix => 'DEFAULT-prefix', |
| 459 |
digital_recipient => 'branch', |
459 |
digital_recipient => 'branch', |