|
Lines 220-239
subtest 'Backend testing (mocks)' => sub {
Link Here
|
| 220 |
# the Dummy plugin installed. load_backend & available_backends don't |
220 |
# the Dummy plugin installed. load_backend & available_backends don't |
| 221 |
# currently have tests as a result. |
221 |
# currently have tests as a result. |
| 222 |
|
222 |
|
|
|
223 |
t::lib::Mocks->mock_config('interlibrary_loans', { backend_dir => 'a_dir' } ); |
| 223 |
my $backend = Test::MockObject->new; |
224 |
my $backend = Test::MockObject->new; |
| 224 |
$backend->set_isa('Koha::Illbackends::Mock'); |
225 |
$backend->set_isa('Koha::Illbackends::Mock'); |
| 225 |
$backend->set_always('name', 'Mock'); |
226 |
$backend->set_always('name', 'Mock'); |
| 226 |
|
227 |
|
| 227 |
my $patron = $builder->build({ source => 'Borrower' }); |
228 |
my $patron = $builder->build({ source => 'Borrower' }); |
| 228 |
my $illrq = $builder->build({ |
229 |
my $illrq = $builder->build_object({ |
| 229 |
source => 'Illrequest', |
230 |
class => 'Koha::Illrequests', |
| 230 |
value => { borrowernumber => $patron->{borrowernumber} } |
231 |
value => { borrowernumber => $patron->{borrowernumber} } |
| 231 |
}); |
232 |
}); |
| 232 |
my $illrq_obj = Koha::Illrequests->find($illrq->{illrequest_id}); |
|
|
| 233 |
|
233 |
|
| 234 |
$illrq_obj->_backend($backend); |
234 |
$illrq->_backend($backend); |
| 235 |
|
235 |
|
| 236 |
isa_ok($illrq_obj->_backend, 'Koha::Illbackends::Mock', |
236 |
isa_ok($illrq->_backend, 'Koha::Illbackends::Mock', |
| 237 |
"OK accessing mocked backend."); |
237 |
"OK accessing mocked backend."); |
| 238 |
|
238 |
|
| 239 |
# _backend_capability tests: |
239 |
# _backend_capability tests: |
|
Lines 245-259
subtest 'Backend testing (mocks)' => sub {
Link Here
|
| 245 |
# functionality, such as unmediated in the BLDSS backend (also see |
245 |
# functionality, such as unmediated in the BLDSS backend (also see |
| 246 |
# bugzilla 18837). |
246 |
# bugzilla 18837). |
| 247 |
$backend->set_always('capabilities', undef); |
247 |
$backend->set_always('capabilities', undef); |
| 248 |
is($illrq_obj->_backend_capability('Test'), 0, |
248 |
is($illrq->_backend_capability('Test'), 0, |
| 249 |
"0 returned on Mock not implementing capabilities."); |
249 |
"0 returned on Mock not implementing capabilities."); |
| 250 |
|
250 |
|
| 251 |
$backend->set_always('capabilities', 0); |
251 |
$backend->set_always('capabilities', 0); |
| 252 |
is($illrq_obj->_backend_capability('Test'), 0, |
252 |
is($illrq->_backend_capability('Test'), 0, |
| 253 |
"0 returned on Mock not implementing Test capability."); |
253 |
"0 returned on Mock not implementing Test capability."); |
| 254 |
|
254 |
|
| 255 |
$backend->set_always('capabilities', sub { return 'bar'; } ); |
255 |
$backend->set_always('capabilities', sub { return 'bar'; } ); |
| 256 |
is($illrq_obj->_backend_capability('Test'), 'bar', |
256 |
is($illrq->_backend_capability('Test'), 'bar', |
| 257 |
"'bar' returned on Mock implementing Test capability."); |
257 |
"'bar' returned on Mock implementing Test capability."); |
| 258 |
|
258 |
|
| 259 |
# metadata test: we need to be sure that we return the arbitrary values |
259 |
# metadata test: we need to be sure that we return the arbitrary values |
|
Lines 270-279
subtest 'Backend testing (mocks)' => sub {
Link Here
|
| 270 |
); |
270 |
); |
| 271 |
|
271 |
|
| 272 |
is_deeply( |
272 |
is_deeply( |
| 273 |
$illrq_obj->metadata, |
273 |
$illrq->metadata, |
| 274 |
{ |
274 |
{ |
| 275 |
ID => $illrq_obj->illrequest_id, |
275 |
ID => $illrq->illrequest_id, |
| 276 |
Title => $illrq_obj->patron->borrowernumber |
276 |
Title => $illrq->patron->borrowernumber |
| 277 |
}, |
277 |
}, |
| 278 |
"Test metadata." |
278 |
"Test metadata." |
| 279 |
); |
279 |
); |
|
Lines 282-288
subtest 'Backend testing (mocks)' => sub {
Link Here
|
| 282 |
|
282 |
|
| 283 |
# No backend graph extension |
283 |
# No backend graph extension |
| 284 |
$backend->set_always('status_graph', {}); |
284 |
$backend->set_always('status_graph', {}); |
| 285 |
is_deeply($illrq_obj->capabilities('COMP'), |
285 |
is_deeply($illrq->capabilities('COMP'), |
| 286 |
{ |
286 |
{ |
| 287 |
prev_actions => [ 'REQ' ], |
287 |
prev_actions => [ 'REQ' ], |
| 288 |
id => 'COMP', |
288 |
id => 'COMP', |
|
Lines 293-302
subtest 'Backend testing (mocks)' => sub {
Link Here
|
| 293 |
ui_method_icon => 'fa-check', |
293 |
ui_method_icon => 'fa-check', |
| 294 |
}, |
294 |
}, |
| 295 |
"Dummy status graph for COMP."); |
295 |
"Dummy status graph for COMP."); |
| 296 |
is($illrq_obj->capabilities('UNKNOWN'), undef, |
296 |
is($illrq->capabilities('UNKNOWN'), undef, |
| 297 |
"Dummy status graph for UNKNOWN."); |
297 |
"Dummy status graph for UNKNOWN."); |
| 298 |
is_deeply($illrq_obj->capabilities(), |
298 |
is_deeply($illrq->capabilities(), |
| 299 |
$illrq_obj->_core_status_graph, |
299 |
$illrq->_core_status_graph, |
| 300 |
"Dummy full status graph."); |
300 |
"Dummy full status graph."); |
| 301 |
# Simple backend graph extension |
301 |
# Simple backend graph extension |
| 302 |
$backend->set_always('status_graph', |
302 |
$backend->set_always('status_graph', |
|
Lines 307-324
subtest 'Backend testing (mocks)' => sub {
Link Here
|
| 307 |
next_actions => [ 'REQ' ], |
307 |
next_actions => [ 'REQ' ], |
| 308 |
}, |
308 |
}, |
| 309 |
}); |
309 |
}); |
| 310 |
is_deeply($illrq_obj->capabilities('QER'), |
310 |
is_deeply($illrq->capabilities('QER'), |
| 311 |
{ |
311 |
{ |
| 312 |
prev_actions => [ 'REQ' ], |
312 |
prev_actions => [ 'REQ' ], |
| 313 |
id => 'QER', |
313 |
id => 'QER', |
| 314 |
next_actions => [ 'REQ' ], |
314 |
next_actions => [ 'REQ' ], |
| 315 |
}, |
315 |
}, |
| 316 |
"Simple status graph for QER."); |
316 |
"Simple status graph for QER."); |
| 317 |
is($illrq_obj->capabilities('UNKNOWN'), undef, |
317 |
is($illrq->capabilities('UNKNOWN'), undef, |
| 318 |
"Simple status graph for UNKNOWN."); |
318 |
"Simple status graph for UNKNOWN."); |
| 319 |
is_deeply($illrq_obj->capabilities(), |
319 |
is_deeply($illrq->capabilities(), |
| 320 |
$illrq_obj->_status_graph_union( |
320 |
$illrq->_status_graph_union( |
| 321 |
$illrq_obj->_core_status_graph, |
321 |
$illrq->_core_status_graph, |
| 322 |
{ |
322 |
{ |
| 323 |
QER => { |
323 |
QER => { |
| 324 |
prev_actions => [ 'REQ' ], |
324 |
prev_actions => [ 'REQ' ], |
|
Lines 333-339
subtest 'Backend testing (mocks)' => sub {
Link Here
|
| 333 |
|
333 |
|
| 334 |
# No backend graph extension |
334 |
# No backend graph extension |
| 335 |
$backend->set_always('status_graph', {}); |
335 |
$backend->set_always('status_graph', {}); |
| 336 |
is($illrq_obj->custom_capability('unknown', {}), 0, |
336 |
is($illrq->custom_capability('unknown', {}), 0, |
| 337 |
"Unknown candidate."); |
337 |
"Unknown candidate."); |
| 338 |
|
338 |
|
| 339 |
# Simple backend graph extension |
339 |
# Simple backend graph extension |
|
Lines 348-354
subtest 'Backend testing (mocks)' => sub {
Link Here
|
| 348 |
}); |
348 |
}); |
| 349 |
$backend->mock('identity', |
349 |
$backend->mock('identity', |
| 350 |
sub { my ( $self, $params ) = @_; return $params->{other}; }); |
350 |
sub { my ( $self, $params ) = @_; return $params->{other}; }); |
| 351 |
is($illrq_obj->custom_capability('identity', { test => 1 })->{test}, 1, |
351 |
is($illrq->custom_capability('identity', { test => 1, method => 'blah' })->{test}, 1, |
| 352 |
"Resolve identity custom_capability"); |
352 |
"Resolve identity custom_capability"); |
| 353 |
|
353 |
|
| 354 |
$schema->storage->txn_rollback; |
354 |
$schema->storage->txn_rollback; |
| 355 |
- |
|
|