Line 0
Link Here
|
0 |
- |
1 |
#!/usr/bin/perl |
|
|
2 |
# |
3 |
# This file is part of Koha. |
4 |
# |
5 |
# Koha is free software; you can redistribute it and/or modify it under the |
6 |
# terms of the GNU General Public License as published by the Free Software |
7 |
# Foundation; either version 2 of the License, or (at your option) any later |
8 |
# version. |
9 |
# |
10 |
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY |
11 |
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR |
12 |
# A PARTICULAR PURPOSE. See the GNU General Public License for more details. |
13 |
# |
14 |
# You should have received a copy of the GNU General Public License along |
15 |
# with Koha; if not, write to the Free Software Foundation, Inc., |
16 |
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
17 |
# |
18 |
|
19 |
use Modern::Perl; |
20 |
|
21 |
use File::Basename qw/basename/; |
22 |
use Koha::Database; |
23 |
use Koha::Illrequestattributes; |
24 |
use Koha::Illrequest::Config; |
25 |
use Koha::Patrons; |
26 |
use t::lib::Mocks; |
27 |
use t::lib::TestBuilder; |
28 |
use Test::MockObject; |
29 |
|
30 |
use Test::More tests => 10; |
31 |
|
32 |
# We want to test the Koha IllRequest object. At its core it's a simple |
33 |
# Koha::Object, mapping to the ill_request table. |
34 |
# |
35 |
# This object will supersede the Status object in ILLModule. |
36 |
# |
37 |
# We must ensure perfect backward compatibility between the current model and |
38 |
# the Status less model. |
39 |
|
40 |
my $schema = Koha::Database->new->schema; |
41 |
my $builder = t::lib::TestBuilder->new; |
42 |
use_ok('Koha::Illrequest'); |
43 |
use_ok('Koha::Illrequests'); |
44 |
|
45 |
subtest 'Basic object tests' => sub { |
46 |
|
47 |
plan tests => 21; |
48 |
|
49 |
$schema->storage->txn_begin; |
50 |
|
51 |
my $illrq = $builder->build({ source => 'Illrequest' }); |
52 |
my $illrq_obj = Koha::Illrequests->find($illrq->{illrequest_id}); |
53 |
|
54 |
isa_ok($illrq_obj, 'Koha::Illrequest', |
55 |
"Correctly create and load an illrequest object."); |
56 |
isa_ok($illrq_obj->_config, 'Koha::Illrequest::Config', |
57 |
"Created a config object as part of Illrequest creation."); |
58 |
|
59 |
is($illrq_obj->illrequest_id, $illrq->{illrequest_id}, |
60 |
"Illrequest_id getter works."); |
61 |
is($illrq_obj->borrowernumber, $illrq->{borrowernumber}, |
62 |
"Borrowernumber getter works."); |
63 |
is($illrq_obj->biblio_id, $illrq->{biblio_id}, |
64 |
"Biblio_Id getter works."); |
65 |
is($illrq_obj->branchcode, $illrq->{branchcode}, |
66 |
"Branchcode getter works."); |
67 |
is($illrq_obj->status, $illrq->{status}, |
68 |
"Status getter works."); |
69 |
is($illrq_obj->placed, $illrq->{placed}, |
70 |
"Placed getter works."); |
71 |
is($illrq_obj->replied, $illrq->{replied}, |
72 |
"Replied getter works."); |
73 |
is($illrq_obj->updated, $illrq->{updated}, |
74 |
"Updated getter works."); |
75 |
is($illrq_obj->completed, $illrq->{completed}, |
76 |
"Completed getter works."); |
77 |
is($illrq_obj->medium, $illrq->{medium}, |
78 |
"Medium getter works."); |
79 |
is($illrq_obj->accessurl, $illrq->{accessurl}, |
80 |
"Accessurl getter works."); |
81 |
is($illrq_obj->cost, $illrq->{cost}, |
82 |
"Cost getter works."); |
83 |
is($illrq_obj->notesopac, $illrq->{notesopac}, |
84 |
"Notesopac getter works."); |
85 |
is($illrq_obj->notesstaff, $illrq->{notesstaff}, |
86 |
"Notesstaff getter works."); |
87 |
is($illrq_obj->orderid, $illrq->{orderid}, |
88 |
"Orderid getter works."); |
89 |
is($illrq_obj->backend, $illrq->{backend}, |
90 |
"Backend getter works."); |
91 |
|
92 |
isnt($illrq_obj->status, 'COMP', |
93 |
"ILL is not currently marked complete."); |
94 |
$illrq_obj->mark_completed; |
95 |
is($illrq_obj->status, 'COMP', |
96 |
"ILL is now marked complete."); |
97 |
|
98 |
$illrq_obj->delete; |
99 |
|
100 |
is(Koha::Illrequests->search->count, 0, |
101 |
"No illrequest found after delete."); |
102 |
|
103 |
$schema->storage->txn_rollback; |
104 |
}; |
105 |
|
106 |
subtest 'Working with related objects' => sub { |
107 |
|
108 |
plan tests => 5; |
109 |
|
110 |
$schema->storage->txn_begin; |
111 |
|
112 |
my $patron = $builder->build({ source => 'Borrower' }); |
113 |
my $illrq = $builder->build({ |
114 |
source => 'Illrequest', |
115 |
value => { borrowernumber => $patron->{borrowernumber} } |
116 |
}); |
117 |
my $illrq_obj = Koha::Illrequests->find($illrq->{illrequest_id}); |
118 |
|
119 |
isa_ok($illrq_obj->patron, 'Koha::Patron', |
120 |
"OK accessing related patron."); |
121 |
|
122 |
$builder->build({ |
123 |
source => 'Illrequestattribute', |
124 |
value => { illrequest_id => $illrq_obj->illrequest_id, type => 'X' } |
125 |
}); |
126 |
$builder->build({ |
127 |
source => 'Illrequestattribute', |
128 |
value => { illrequest_id => $illrq_obj->illrequest_id, type => 'Y' } |
129 |
}); |
130 |
$builder->build({ |
131 |
source => 'Illrequestattribute', |
132 |
value => { illrequest_id => $illrq_obj->illrequest_id, type => 'Z' } |
133 |
}); |
134 |
|
135 |
is($illrq_obj->illrequestattributes->count, Koha::Illrequestattributes->search->count, |
136 |
"Fetching expected number of Illrequestattributes for our request."); |
137 |
|
138 |
my $illrq1 = $builder->build({ source => 'Illrequest' }); |
139 |
$builder->build({ |
140 |
source => 'Illrequestattribute', |
141 |
value => { illrequest_id => $illrq1->{illrequest_id}, type => 'X' } |
142 |
}); |
143 |
|
144 |
is($illrq_obj->illrequestattributes->count + 1, Koha::Illrequestattributes->search->count, |
145 |
"Fetching expected number of Illrequestattributes for our request."); |
146 |
|
147 |
$illrq_obj->delete; |
148 |
is(Koha::Illrequestattributes->search->count, 1, |
149 |
"Correct number of illrequestattributes after delete."); |
150 |
|
151 |
isa_ok(Koha::Patrons->find($patron->{borrowernumber}), 'Koha::Patron', |
152 |
"Borrower was not deleted after illrq delete."); |
153 |
|
154 |
$schema->storage->txn_rollback; |
155 |
}; |
156 |
|
157 |
subtest 'Status Graph tests' => sub { |
158 |
|
159 |
plan tests => 4; |
160 |
|
161 |
$schema->storage->txn_begin; |
162 |
|
163 |
my $illrq = $builder->build({source => 'Illrequest'}); |
164 |
my $illrq_obj = Koha::Illrequests->find($illrq->{illrequest_id}); |
165 |
|
166 |
# _core_status_graph tests: it's just a constant, so here we just make |
167 |
# sure it returns a hashref. |
168 |
is(ref $illrq_obj->_core_status_graph, "HASH", |
169 |
"_core_status_graph returns a hash."); |
170 |
|
171 |
# _status_graph_union: let's try different merge operations. |
172 |
# Identity operation |
173 |
is_deeply( |
174 |
$illrq_obj->_status_graph_union($illrq_obj->_core_status_graph, {}), |
175 |
$illrq_obj->_core_status_graph, |
176 |
"core_status_graph + null = core_status_graph" |
177 |
); |
178 |
|
179 |
# Simple addition |
180 |
is_deeply( |
181 |
$illrq_obj->_status_graph_union({}, $illrq_obj->_core_status_graph), |
182 |
$illrq_obj->_core_status_graph, |
183 |
"null + core_status_graph = core_status_graph" |
184 |
); |
185 |
|
186 |
# Correct merge behaviour |
187 |
is_deeply( |
188 |
$illrq_obj->_status_graph_union({ |
189 |
REQ => { |
190 |
prev_actions => [ ], |
191 |
id => 'REQ', |
192 |
next_actions => [ ], |
193 |
}, |
194 |
}, { |
195 |
QER => { |
196 |
prev_actions => [ 'REQ' ], |
197 |
id => 'QER', |
198 |
next_actions => [ 'REQ' ], |
199 |
}, |
200 |
}), |
201 |
{ |
202 |
REQ => { |
203 |
prev_actions => [ 'QER' ], |
204 |
id => 'REQ', |
205 |
next_actions => [ 'QER' ], |
206 |
}, |
207 |
QER => { |
208 |
prev_actions => [ 'REQ' ], |
209 |
id => 'QER', |
210 |
next_actions => [ 'REQ' ], |
211 |
}, |
212 |
}, |
213 |
"REQ atom + linking QER = cyclical status graph" |
214 |
); |
215 |
|
216 |
$schema->storage->txn_rollback; |
217 |
}; |
218 |
|
219 |
subtest 'Backend testing (mocks)' => sub { |
220 |
|
221 |
plan tests => 13; |
222 |
|
223 |
$schema->storage->txn_begin; |
224 |
|
225 |
# testing load_backend & available_backends requires that we have at least |
226 |
# the Dummy plugin installed. load_backend & available_backends don't |
227 |
# currently have tests as a result. |
228 |
|
229 |
my $backend = Test::MockObject->new; |
230 |
$backend->set_isa('Koha::Illbackends::Mock'); |
231 |
$backend->set_always('name', 'Mock'); |
232 |
|
233 |
my $patron = $builder->build({ source => 'Borrower' }); |
234 |
my $illrq = $builder->build({ |
235 |
source => 'Illrequest', |
236 |
value => { borrowernumber => $patron->{borrowernumber} } |
237 |
}); |
238 |
my $illrq_obj = Koha::Illrequests->find($illrq->{illrequest_id}); |
239 |
|
240 |
$illrq_obj->_backend($backend); |
241 |
|
242 |
isa_ok($illrq_obj->_backend, 'Koha::Illbackends::Mock', |
243 |
"OK accessing mocked backend."); |
244 |
|
245 |
# _backend_capability tests: |
246 |
# We need to test whether this optional feature of a mocked backend |
247 |
# behaves as expected. |
248 |
# 3 scenarios: feature not implemented, feature implemented, but requested |
249 |
# capability is not provided by backend, & feature is implemented & |
250 |
# capability exists. This method can be used to implement custom backend |
251 |
# functionality, such as unmediated in the BLDSS backend (also see |
252 |
# bugzilla 18837). |
253 |
$backend->set_always('capabilities', undef); |
254 |
is($illrq_obj->_backend_capability('Test'), 0, |
255 |
"0 returned on Mock not implementing capabilities."); |
256 |
|
257 |
$backend->set_always('capabilities', 0); |
258 |
is($illrq_obj->_backend_capability('Test'), 0, |
259 |
"0 returned on Mock not implementing Test capability."); |
260 |
|
261 |
$backend->set_always('capabilities', sub { return 'bar'; } ); |
262 |
is($illrq_obj->_backend_capability('Test'), 'bar', |
263 |
"'bar' returned on Mock implementing Test capability."); |
264 |
|
265 |
# metadata test: we need to be sure that we return the arbitrary values |
266 |
# from the backend. |
267 |
$backend->mock( |
268 |
'metadata', |
269 |
sub { |
270 |
my ( $self, $rq ) = @_; |
271 |
return { |
272 |
ID => $rq->illrequest_id, |
273 |
Title => $rq->patron->borrowernumber |
274 |
} |
275 |
} |
276 |
); |
277 |
|
278 |
is_deeply( |
279 |
$illrq_obj->metadata, |
280 |
{ |
281 |
ID => $illrq_obj->illrequest_id, |
282 |
Title => $illrq_obj->patron->borrowernumber |
283 |
}, |
284 |
"Test metadata." |
285 |
); |
286 |
|
287 |
# capabilities: |
288 |
|
289 |
# No backend graph extension |
290 |
$backend->set_always('status_graph', {}); |
291 |
is_deeply($illrq_obj->capabilities('COMP'), |
292 |
{ |
293 |
prev_actions => [ 'REQ' ], |
294 |
id => 'COMP', |
295 |
name => 'Completed', |
296 |
ui_method_name => 'Mark completed', |
297 |
method => 'mark_completed', |
298 |
next_actions => [ ], |
299 |
ui_method_icon => 'fa-check', |
300 |
}, |
301 |
"Dummy status graph for COMP."); |
302 |
is($illrq_obj->capabilities('UNKNOWN'), undef, |
303 |
"Dummy status graph for UNKNOWN."); |
304 |
is_deeply($illrq_obj->capabilities(), |
305 |
$illrq_obj->_core_status_graph, |
306 |
"Dummy full status graph."); |
307 |
# Simple backend graph extension |
308 |
$backend->set_always('status_graph', |
309 |
{ |
310 |
QER => { |
311 |
prev_actions => [ 'REQ' ], |
312 |
id => 'QER', |
313 |
next_actions => [ 'REQ' ], |
314 |
}, |
315 |
}); |
316 |
is_deeply($illrq_obj->capabilities('QER'), |
317 |
{ |
318 |
prev_actions => [ 'REQ' ], |
319 |
id => 'QER', |
320 |
next_actions => [ 'REQ' ], |
321 |
}, |
322 |
"Simple status graph for QER."); |
323 |
is($illrq_obj->capabilities('UNKNOWN'), undef, |
324 |
"Simple status graph for UNKNOWN."); |
325 |
is_deeply($illrq_obj->capabilities(), |
326 |
$illrq_obj->_status_graph_union( |
327 |
$illrq_obj->_core_status_graph, |
328 |
{ |
329 |
QER => { |
330 |
prev_actions => [ 'REQ' ], |
331 |
id => 'QER', |
332 |
next_actions => [ 'REQ' ], |
333 |
}, |
334 |
} |
335 |
), |
336 |
"Simple full status graph."); |
337 |
|
338 |
# custom_capability: |
339 |
|
340 |
# No backend graph extension |
341 |
$backend->set_always('status_graph', {}); |
342 |
is($illrq_obj->custom_capability('unknown', {}), 0, |
343 |
"Unknown candidate."); |
344 |
|
345 |
# Simple backend graph extension |
346 |
$backend->set_always('status_graph', |
347 |
{ |
348 |
ID => { |
349 |
prev_actions => [ 'REQ' ], |
350 |
id => 'ID', |
351 |
method => 'identity', |
352 |
next_actions => [ 'REQ' ], |
353 |
}, |
354 |
}); |
355 |
$backend->mock('identity', |
356 |
sub { my ( $self, $params ) = @_; return $params->{other}; }); |
357 |
is($illrq_obj->custom_capability('identity', { test => 1 })->{test}, 1, |
358 |
"Resolve identity custom_capability"); |
359 |
|
360 |
$schema->storage->txn_rollback; |
361 |
}; |
362 |
|
363 |
|
364 |
subtest 'Backend core methods' => sub { |
365 |
|
366 |
plan tests => 11; |
367 |
|
368 |
$schema->storage->txn_begin; |
369 |
|
370 |
# Build infrastructure |
371 |
my $backend = Test::MockObject->new; |
372 |
$backend->set_isa('Koha::Illbackends::Mock'); |
373 |
$backend->set_always('name', 'Mock'); |
374 |
|
375 |
my $config = Test::MockObject->new; |
376 |
$config->set_always('backend_dir', "/tmp"); |
377 |
$config->set_always('getLimitRules', |
378 |
{ default => { count => 0, method => 'active' } }); |
379 |
|
380 |
my $illrq = $builder->build({source => 'Illrequest'}); |
381 |
my $illrq_obj = Koha::Illrequests->find($illrq->{illrequest_id}); |
382 |
$illrq_obj->_config($config); |
383 |
$illrq_obj->_backend($backend); |
384 |
|
385 |
# expandTemplate: |
386 |
is_deeply($illrq_obj->expandTemplate({ test => 1, method => "bar" }), |
387 |
{ |
388 |
test => 1, |
389 |
method => "bar", |
390 |
template => "/tmp/Mock/intra-includes/bar.inc", |
391 |
opac_template => "/tmp/Mock/opac-includes/bar.inc", |
392 |
}, |
393 |
"ExpandTemplate"); |
394 |
|
395 |
# backend_create |
396 |
# we are testing simple cases. |
397 |
$backend->set_series('create', |
398 |
{ stage => 'bar', method => 'create' }, |
399 |
{ stage => 'commit', method => 'create' }, |
400 |
{ stage => 'commit', method => 'create' }); |
401 |
# Test Copyright Clearance |
402 |
t::lib::Mocks::mock_preference("ILLModuleCopyrightClearance", "Test Copyright Clearance."); |
403 |
is_deeply($illrq_obj->backend_create({test => 1}), |
404 |
{ |
405 |
error => 0, |
406 |
status => '', |
407 |
message => '', |
408 |
method => 'create', |
409 |
stage => 'copyrightclearance', |
410 |
value => { |
411 |
backend => "Mock" |
412 |
} |
413 |
}, |
414 |
"Backend create: copyright clearance."); |
415 |
t::lib::Mocks::mock_preference("ILLModuleCopyrightClearance", ""); |
416 |
# Test non-commit |
417 |
is_deeply($illrq_obj->backend_create({test => 1}), |
418 |
{ |
419 |
stage => 'bar', method => 'create', |
420 |
template => "/tmp/Mock/intra-includes/create.inc", |
421 |
opac_template => "/tmp/Mock/opac-includes/create.inc", |
422 |
}, |
423 |
"Backend create: arbitrary stage."); |
424 |
# Test commit |
425 |
is_deeply($illrq_obj->backend_create({test => 1}), |
426 |
{ |
427 |
stage => 'commit', method => 'create', permitted => 0, |
428 |
template => "/tmp/Mock/intra-includes/create.inc", |
429 |
opac_template => "/tmp/Mock/opac-includes/create.inc", |
430 |
}, |
431 |
"Backend create: arbitrary stage, not permitted."); |
432 |
is($illrq_obj->status, "QUEUED", "Backend create: queued if restricted."); |
433 |
$config->set_always('getLimitRules', {}); |
434 |
$illrq_obj->status('NEW'); |
435 |
is_deeply($illrq_obj->backend_create({test => 1}), |
436 |
{ |
437 |
stage => 'commit', method => 'create', permitted => 1, |
438 |
template => "/tmp/Mock/intra-includes/create.inc", |
439 |
opac_template => "/tmp/Mock/opac-includes/create.inc", |
440 |
}, |
441 |
"Backend create: arbitrary stage, permitted."); |
442 |
is($illrq_obj->status, "NEW", "Backend create: not-queued."); |
443 |
|
444 |
# backend_renew |
445 |
$backend->set_series('renew', { stage => 'bar', method => 'renew' }); |
446 |
is_deeply($illrq_obj->backend_renew({test => 1}), |
447 |
{ |
448 |
stage => 'bar', method => 'renew', |
449 |
template => "/tmp/Mock/intra-includes/renew.inc", |
450 |
opac_template => "/tmp/Mock/opac-includes/renew.inc", |
451 |
}, |
452 |
"Backend renew: arbitrary stage."); |
453 |
|
454 |
# backend_cancel |
455 |
$backend->set_series('cancel', { stage => 'bar', method => 'cancel' }); |
456 |
is_deeply($illrq_obj->backend_cancel({test => 1}), |
457 |
{ |
458 |
stage => 'bar', method => 'cancel', |
459 |
template => "/tmp/Mock/intra-includes/cancel.inc", |
460 |
opac_template => "/tmp/Mock/opac-includes/cancel.inc", |
461 |
}, |
462 |
"Backend cancel: arbitrary stage."); |
463 |
|
464 |
# backend_update_status |
465 |
$backend->set_series('update_status', { stage => 'bar', method => 'update_status' }); |
466 |
is_deeply($illrq_obj->backend_update_status({test => 1}), |
467 |
{ |
468 |
stage => 'bar', method => 'update_status', |
469 |
template => "/tmp/Mock/intra-includes/update_status.inc", |
470 |
opac_template => "/tmp/Mock/opac-includes/update_status.inc", |
471 |
}, |
472 |
"Backend update_status: arbitrary stage."); |
473 |
|
474 |
# backend_confirm |
475 |
$backend->set_series('confirm', { stage => 'bar', method => 'confirm' }); |
476 |
is_deeply($illrq_obj->backend_confirm({test => 1}), |
477 |
{ |
478 |
stage => 'bar', method => 'confirm', |
479 |
template => "/tmp/Mock/intra-includes/confirm.inc", |
480 |
opac_template => "/tmp/Mock/opac-includes/confirm.inc", |
481 |
}, |
482 |
"Backend confirm: arbitrary stage."); |
483 |
|
484 |
# FIXME have to test generic_confirm. |
485 |
|
486 |
$schema->storage->txn_rollback; |
487 |
}; |
488 |
|
489 |
|
490 |
subtest 'Helpers' => sub { |
491 |
|
492 |
plan tests => 9; |
493 |
|
494 |
$schema->storage->txn_begin; |
495 |
|
496 |
# Build infrastructure |
497 |
my $backend = Test::MockObject->new; |
498 |
$backend->set_isa('Koha::Illbackends::Mock'); |
499 |
$backend->set_always('name', 'Mock'); |
500 |
|
501 |
my $config = Test::MockObject->new; |
502 |
$config->set_always('backend_dir', "/tmp"); |
503 |
|
504 |
my $patron = $builder->build({ |
505 |
source => 'Borrower', |
506 |
value => { categorycode => "A" } |
507 |
}); |
508 |
my $illrq = $builder->build({ |
509 |
source => 'Illrequest', |
510 |
value => { branchcode => "CPL", borrowernumber => $patron->{borrowernumber} } |
511 |
}); |
512 |
my $illrq_obj = Koha::Illrequests->find($illrq->{illrequest_id}); |
513 |
$illrq_obj->_config($config); |
514 |
$illrq_obj->_backend($backend); |
515 |
|
516 |
# getPrefix |
517 |
$config->set_series('getPrefixes', |
518 |
{ CPL => "TEST", TSL => "BAR", default => "DEFAULT" }, |
519 |
{ A => "ATEST", C => "CBAR", default => "DEFAULT" }); |
520 |
is($illrq_obj->getPrefix({ brw_cat => "C", branch => "CPL" }), "CBAR", |
521 |
"getPrefix: brw_cat"); |
522 |
$config->set_series('getPrefixes', |
523 |
{ CPL => "TEST", TSL => "BAR", default => "DEFAULT" }, |
524 |
{ A => "ATEST", C => "CBAR", default => "DEFAULT" }); |
525 |
is($illrq_obj->getPrefix({ brw_cat => "UNKNOWN", branch => "CPL" }), "TEST", |
526 |
"getPrefix: branch"); |
527 |
$config->set_series('getPrefixes', |
528 |
{ CPL => "TEST", TSL => "BAR", default => "DEFAULT" }, |
529 |
{ A => "ATEST", C => "CBAR", default => "DEFAULT" }); |
530 |
is($illrq_obj->getPrefix({ brw_cat => "UNKNOWN", branch => "UNKNOWN" }), "DEFAULT", |
531 |
"getPrefix: default"); |
532 |
$config->set_always('getPrefixes', {}); |
533 |
is($illrq_obj->getPrefix({ brw_cat => "UNKNOWN", branch => "UNKNOWN" }), "", |
534 |
"getPrefix: the empty prefix"); |
535 |
|
536 |
# id_prefix |
537 |
$config->set_series('getPrefixes', |
538 |
{ CPL => "TEST", TSL => "BAR", default => "DEFAULT" }, |
539 |
{ A => "ATEST", C => "CBAR", default => "DEFAULT" }); |
540 |
is($illrq_obj->id_prefix, "ATEST-", "id_prefix: brw_cat"); |
541 |
$config->set_series('getPrefixes', |
542 |
{ CPL => "TEST", TSL => "BAR", default => "DEFAULT" }, |
543 |
{ AB => "ATEST", CD => "CBAR", default => "DEFAULT" }); |
544 |
is($illrq_obj->id_prefix, "TEST-", "id_prefix: branch"); |
545 |
$config->set_series('getPrefixes', |
546 |
{ CPLT => "TEST", TSLT => "BAR", default => "DEFAULT" }, |
547 |
{ AB => "ATEST", CD => "CBAR", default => "DEFAULT" }); |
548 |
is($illrq_obj->id_prefix, "DEFAULT-", "id_prefix: default"); |
549 |
|
550 |
# requires_moderation |
551 |
$illrq_obj->status('NEW')->store; |
552 |
is($illrq_obj->requires_moderation, undef, "requires_moderation: No."); |
553 |
$illrq_obj->status('CANCREQ')->store; |
554 |
is($illrq_obj->requires_moderation, 'CANCREQ', "requires_moderation: Yes."); |
555 |
|
556 |
$schema->storage->txn_rollback; |
557 |
}; |
558 |
|
559 |
|
560 |
subtest 'Censorship' => sub { |
561 |
|
562 |
plan tests => 4; |
563 |
|
564 |
$schema->storage->txn_begin; |
565 |
|
566 |
# Build infrastructure |
567 |
my $backend = Test::MockObject->new; |
568 |
$backend->set_isa('Koha::Illbackends::Mock'); |
569 |
$backend->set_always('name', 'Mock'); |
570 |
|
571 |
my $config = Test::MockObject->new; |
572 |
$config->set_always('backend_dir', "/tmp"); |
573 |
|
574 |
my $illrq = $builder->build({source => 'Illrequest'}); |
575 |
my $illrq_obj = Koha::Illrequests->find($illrq->{illrequest_id}); |
576 |
$illrq_obj->_config($config); |
577 |
$illrq_obj->_backend($backend); |
578 |
|
579 |
# getCensorNotesStaff |
580 |
$config->set_series('censorship', |
581 |
{ censor_notes_staff => 1 }, |
582 |
{ censor_notes_staff => 0 }); |
583 |
is($illrq_obj->getCensorNotesStaff, 1, |
584 |
"getCensorNotesStaff: on."); |
585 |
is($illrq_obj->getCensorNotesStaff, 0, |
586 |
"getCensorNotesStaff: off."); |
587 |
|
588 |
# getDisplayReplyDate |
589 |
$config->set_series('censorship', |
590 |
{ censor_reply_date => 1 }, |
591 |
{ censor_reply_date => 0 }); |
592 |
is($illrq_obj->getDisplayReplyDate, 0, |
593 |
"getDisplayReplyDate: off."); |
594 |
is($illrq_obj->getDisplayReplyDate, 1, |
595 |
"getDisplayReplyDate: on."); |
596 |
|
597 |
# FIXME need to test _censor |
598 |
|
599 |
$schema->storage->txn_rollback; |
600 |
}; |
601 |
|
602 |
subtest 'Checking Limits' => sub { |
603 |
|
604 |
plan tests => 3; |
605 |
|
606 |
$schema->storage->txn_begin; |
607 |
|
608 |
# Build infrastructure |
609 |
my $backend = Test::MockObject->new; |
610 |
$backend->set_isa('Koha::Illbackends::Mock'); |
611 |
$backend->set_always('name', 'Mock'); |
612 |
|
613 |
my $config = Test::MockObject->new; |
614 |
$config->set_always('backend_dir', "/tmp"); |
615 |
|
616 |
my $illrq = $builder->build({source => 'Illrequest'}); |
617 |
my $illrq_obj = Koha::Illrequests->find($illrq->{illrequest_id}); |
618 |
$illrq_obj->_config($config); |
619 |
$illrq_obj->_backend($backend); |
620 |
|
621 |
# getLimits |
622 |
$config->set_series('getLimitRules', |
623 |
{ CPL => { count => 1, method => 'test' } }, |
624 |
{ default => { count => 0, method => 'active' } }); |
625 |
is_deeply($illrq_obj->getLimits({ type => 'branch', value => "CPL" }), |
626 |
{ count => 1, method => 'test' }, |
627 |
"getLimits: by value."); |
628 |
is_deeply($illrq_obj->getLimits({ type => 'branch' }), |
629 |
{ count => 0, method => 'active' }, |
630 |
"getLimits: by default."); |
631 |
is_deeply($illrq_obj->getLimits({ type => 'branch', value => "CPL" }), |
632 |
{ count => -1, method => 'active' }, |
633 |
"getLimits: by hard-coded."); |
634 |
|
635 |
# FIXME need to test _limit_counter & check_limits |
636 |
|
637 |
$schema->storage->txn_rollback; |
638 |
}; |
639 |
|
640 |
|
641 |
|
642 |
1; |