Lines 41-52
use Test::Exception;
Link Here
|
41 |
use Test::Deep qw/ cmp_deeply ignore /; |
41 |
use Test::Deep qw/ cmp_deeply ignore /; |
42 |
use Test::Warn; |
42 |
use Test::Warn; |
43 |
|
43 |
|
44 |
use Test::More tests => 15; |
44 |
use Test::More tests => 16; |
45 |
|
45 |
|
46 |
my $schema = Koha::Database->new->schema; |
46 |
my $schema = Koha::Database->new->schema; |
47 |
my $builder = t::lib::TestBuilder->new; |
47 |
my $builder = t::lib::TestBuilder->new; |
48 |
use_ok('Koha::Illrequest'); |
48 |
use_ok('Koha::ILL::Request'); |
49 |
use_ok('Koha::Illrequests'); |
49 |
use_ok('Koha::ILL::Requests'); |
50 |
|
50 |
|
51 |
subtest 'Basic object tests' => sub { |
51 |
subtest 'Basic object tests' => sub { |
52 |
|
52 |
|
Lines 54-64
subtest 'Basic object tests' => sub {
Link Here
|
54 |
|
54 |
|
55 |
$schema->storage->txn_begin; |
55 |
$schema->storage->txn_begin; |
56 |
|
56 |
|
57 |
Koha::Illrequests->search->delete; |
57 |
Koha::ILL::Requests->search->delete; |
58 |
my $illrq = $builder->build({ source => 'Illrequest' }); |
58 |
my $illrq = $builder->build({ source => 'Illrequest' }); |
59 |
my $illrq_obj = Koha::Illrequests->find($illrq->{illrequest_id}); |
59 |
my $illrq_obj = Koha::ILL::Requests->find($illrq->{illrequest_id}); |
60 |
|
60 |
|
61 |
isa_ok($illrq_obj, 'Koha::Illrequest', |
61 |
isa_ok($illrq_obj, 'Koha::ILL::Request', |
62 |
"Correctly create and load an illrequest object."); |
62 |
"Correctly create and load an illrequest object."); |
63 |
isa_ok($illrq_obj->_config, 'Koha::ILL::Request::Config', |
63 |
isa_ok($illrq_obj->_config, 'Koha::ILL::Request::Config', |
64 |
"Created a config object as part of Illrequest creation."); |
64 |
"Created a config object as part of Illrequest creation."); |
Lines 119-125
subtest 'Basic object tests' => sub {
Link Here
|
119 |
|
119 |
|
120 |
$illrq_obj->delete; |
120 |
$illrq_obj->delete; |
121 |
|
121 |
|
122 |
is(Koha::Illrequests->search->count, 0, |
122 |
is(Koha::ILL::Requests->search->count, 0, |
123 |
"No illrequest found after delete."); |
123 |
"No illrequest found after delete."); |
124 |
|
124 |
|
125 |
$schema->storage->txn_rollback; |
125 |
$schema->storage->txn_rollback; |
Lines 130-143
subtest 'store borrowernumber change also updates holds' => sub {
Link Here
|
130 |
|
130 |
|
131 |
$schema->storage->txn_begin; |
131 |
$schema->storage->txn_begin; |
132 |
|
132 |
|
133 |
Koha::Illrequests->search->delete; |
133 |
Koha::ILL::Requests->search->delete; |
134 |
|
134 |
|
135 |
my $patron = $builder->build_object({ class => 'Koha::Patrons' }); |
135 |
my $patron = $builder->build_object({ class => 'Koha::Patrons' }); |
136 |
my $other_patron = $builder->build_object({ class => 'Koha::Patrons' }); |
136 |
my $other_patron = $builder->build_object({ class => 'Koha::Patrons' }); |
137 |
my $biblio = $builder->build_object({ class => 'Koha::Biblios' }); |
137 |
my $biblio = $builder->build_object({ class => 'Koha::Biblios' }); |
138 |
|
138 |
|
139 |
my $request = $builder->build_object({ |
139 |
my $request = $builder->build_object({ |
140 |
class => 'Koha::Illrequests', |
140 |
class => 'Koha::ILL::Requests', |
141 |
value => { |
141 |
value => { |
142 |
borrowernumber => $patron->borrowernumber, |
142 |
borrowernumber => $patron->borrowernumber, |
143 |
biblio_id => $biblio->biblionumber, |
143 |
biblio_id => $biblio->biblionumber, |
Lines 170-182
subtest 'store borrowernumber change also updates holds' => sub {
Link Here
|
170 |
is( $request->borrowernumber, $other_patron->borrowernumber, |
170 |
is( $request->borrowernumber, $other_patron->borrowernumber, |
171 |
'after change, changed borrowernumber found in illrequests' ); |
171 |
'after change, changed borrowernumber found in illrequests' ); |
172 |
|
172 |
|
173 |
my $new_request = Koha::Illrequest->new({ |
173 |
my $new_request = Koha::ILL::Request->new({ |
174 |
biblio_id => $biblio->biblionumber, |
174 |
biblio_id => $biblio->biblionumber, |
175 |
branchcode => $patron->branchcode, |
175 |
branchcode => $patron->branchcode, |
176 |
})->borrowernumber( $patron->borrowernumber )->store; |
176 |
})->borrowernumber( $patron->borrowernumber )->store; |
177 |
|
177 |
|
178 |
is( $new_request->borrowernumber, $patron->borrowernumber, |
178 |
is( $new_request->borrowernumber, $patron->borrowernumber, |
179 |
'Koha::Illrequest->new()->store() works as expected'); |
179 |
'Koha::ILL::Request->new()->store() works as expected'); |
180 |
|
180 |
|
181 |
my $new_holds_found = Koha::Holds->search({ |
181 |
my $new_holds_found = Koha::Holds->search({ |
182 |
biblionumber => $new_request->biblio_id, |
182 |
biblionumber => $new_request->biblio_id, |
Lines 197-203
subtest 'Working with related objects' => sub {
Link Here
|
197 |
|
197 |
|
198 |
my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); |
198 |
my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); |
199 |
my $illrq = $builder->build_object( |
199 |
my $illrq = $builder->build_object( |
200 |
{ class => 'Koha::Illrequests', |
200 |
{ class => 'Koha::ILL::Requests', |
201 |
value => { borrowernumber => $patron->id, biblio_id => undef } |
201 |
value => { borrowernumber => $patron->id, biblio_id => undef } |
202 |
} |
202 |
} |
203 |
); |
203 |
); |
Lines 228-234
subtest 'Working with related objects' => sub {
Link Here
|
228 |
is( $illrq->biblio, undef, "->biblio returns undef if no biblio" ); |
228 |
is( $illrq->biblio, undef, "->biblio returns undef if no biblio" ); |
229 |
my $biblio = $builder->build_object( { class => 'Koha::Biblios' } ); |
229 |
my $biblio = $builder->build_object( { class => 'Koha::Biblios' } ); |
230 |
my $req_bib = $builder->build_object( |
230 |
my $req_bib = $builder->build_object( |
231 |
{ class => 'Koha::Illrequests', |
231 |
{ class => 'Koha::ILL::Requests', |
232 |
value => { biblio_id => $biblio->biblionumber } |
232 |
value => { biblio_id => $biblio->biblionumber } |
233 |
} |
233 |
} |
234 |
); |
234 |
); |
Lines 249-255
subtest 'Status Graph tests' => sub {
Link Here
|
249 |
$schema->storage->txn_begin; |
249 |
$schema->storage->txn_begin; |
250 |
|
250 |
|
251 |
my $illrq = $builder->build({source => 'Illrequest'}); |
251 |
my $illrq = $builder->build({source => 'Illrequest'}); |
252 |
my $illrq_obj = Koha::Illrequests->find($illrq->{illrequest_id}); |
252 |
my $illrq_obj = Koha::ILL::Requests->find($ illrq->{illrequest_id}) ; |
253 |
|
253 |
|
254 |
# _core_status_graph tests: it's just a constant, so here we just make |
254 |
# _core_status_graph tests: it's just a constant, so here we just make |
255 |
# sure it returns a hashref. |
255 |
# sure it returns a hashref. |
Lines 314-320
subtest 'Status Graph tests' => sub {
Link Here
|
314 |
my $new_graph = $illrq_obj->_status_graph_union( $new_node, $illrq_obj->_core_status_graph); |
314 |
my $new_graph = $illrq_obj->_status_graph_union( $new_node, $illrq_obj->_core_status_graph); |
315 |
# Compare the updated graph to the expected graph |
315 |
# Compare the updated graph to the expected graph |
316 |
# The structure we compare against here is just a copy of the structure found |
316 |
# The structure we compare against here is just a copy of the structure found |
317 |
# in Koha::Illrequest::_core_status_graph() + the new node we created above |
317 |
# in Koha::ILL::Request::_core_status_graph() + the new node we created above |
318 |
cmp_deeply( $new_graph, |
318 |
cmp_deeply( $new_graph, |
319 |
{ |
319 |
{ |
320 |
TEST => { |
320 |
TEST => { |
Lines 438-444
subtest 'Status Graph tests' => sub {
Link Here
|
438 |
my $dupe_graph = $illrq_obj->_status_graph_union( $illrq_obj->_core_status_graph, $dupe_node); |
438 |
my $dupe_graph = $illrq_obj->_status_graph_union( $illrq_obj->_core_status_graph, $dupe_node); |
439 |
# Compare the updated graph to the expected graph |
439 |
# Compare the updated graph to the expected graph |
440 |
# The structure we compare against here is just a copy of the structure found |
440 |
# The structure we compare against here is just a copy of the structure found |
441 |
# in Koha::Illrequest::_core_status_graph() + the new node we created above |
441 |
# in Koha::ILL::Request::_core_status_graph() + the new node we created above |
442 |
cmp_deeply( $dupe_graph, |
442 |
cmp_deeply( $dupe_graph, |
443 |
{ |
443 |
{ |
444 |
NEW => { |
444 |
NEW => { |
Lines 561-567
subtest 'Backend testing (mocks)' => sub {
Link Here
|
561 |
|
561 |
|
562 |
my $patron = $builder->build({ source => 'Borrower' }); |
562 |
my $patron = $builder->build({ source => 'Borrower' }); |
563 |
my $illrq = $builder->build_object({ |
563 |
my $illrq = $builder->build_object({ |
564 |
class => 'Koha::Illrequests', |
564 |
class => 'Koha::ILL::Requests', |
565 |
}); |
565 |
}); |
566 |
|
566 |
|
567 |
$illrq->_backend($backend); |
567 |
$illrq->_backend($backend); |
Lines 706-712
subtest 'Backend core methods' => sub {
Link Here
|
706 |
{ default => { count => 0, method => 'active' } }); |
706 |
{ default => { count => 0, method => 'active' } }); |
707 |
|
707 |
|
708 |
my $illrq = $builder->build_object({ |
708 |
my $illrq = $builder->build_object({ |
709 |
class => 'Koha::Illrequests', |
709 |
class => 'Koha::ILL::Requests', |
710 |
value => { backend => undef } |
710 |
value => { backend => undef } |
711 |
}); |
711 |
}); |
712 |
$illrq->_config($config); |
712 |
$illrq->_config($config); |
Lines 944-950
subtest 'Helpers' => sub {
Link Here
|
944 |
source => 'Illrequest', |
944 |
source => 'Illrequest', |
945 |
value => { branchcode => "HDE", borrowernumber => $patron->{borrowernumber} } |
945 |
value => { branchcode => "HDE", borrowernumber => $patron->{borrowernumber} } |
946 |
}); |
946 |
}); |
947 |
my $illrq_obj = Koha::Illrequests->find($illrq->{illrequest_id}); |
947 |
my $illrq_obj = Koha::ILL::Requests->find($illrq->{illrequest_id}); |
948 |
$illrq_obj->_config($config); |
948 |
$illrq_obj->_config($config); |
949 |
$illrq_obj->_backend($backend); |
949 |
$illrq_obj->_backend($backend); |
950 |
|
950 |
|
Lines 1168-1174
subtest 'Censorship' => sub {
Link Here
|
1168 |
$config->set_always('backend_dir', "/tmp"); |
1168 |
$config->set_always('backend_dir', "/tmp"); |
1169 |
|
1169 |
|
1170 |
my $illrq = $builder->build({source => 'Illrequest'}); |
1170 |
my $illrq = $builder->build({source => 'Illrequest'}); |
1171 |
my $illrq_obj = Koha::Illrequests->find($illrq->{illrequest_id}); |
1171 |
my $illrq_obj = Koha::ILL::Requests->find($illrq->{illrequest_id}); |
1172 |
$illrq_obj->_config($config); |
1172 |
$illrq_obj->_config($config); |
1173 |
$illrq_obj->_backend($backend); |
1173 |
$illrq_obj->_backend($backend); |
1174 |
|
1174 |
|
Lines 1203-1209
subtest 'Checking out' => sub {
Link Here
|
1203 |
my $biblio = $builder->build_sample_biblio(); |
1203 |
my $biblio = $builder->build_sample_biblio(); |
1204 |
my $patron = $builder->build_object({ class => 'Koha::Patrons' }); |
1204 |
my $patron = $builder->build_object({ class => 'Koha::Patrons' }); |
1205 |
my $request = $builder->build_object({ |
1205 |
my $request = $builder->build_object({ |
1206 |
class => 'Koha::Illrequests', |
1206 |
class => 'Koha::ILL::Requests', |
1207 |
value => { |
1207 |
value => { |
1208 |
borrowernumber => $patron->borrowernumber, |
1208 |
borrowernumber => $patron->borrowernumber, |
1209 |
biblio_id => $biblio->biblionumber |
1209 |
biblio_id => $biblio->biblionumber |
Lines 1330-1336
subtest 'Checking out with custom due date' => sub {
Link Here
|
1330 |
} |
1330 |
} |
1331 |
}); |
1331 |
}); |
1332 |
my $request = $builder->build_object({ |
1332 |
my $request = $builder->build_object({ |
1333 |
class => 'Koha::Illrequests', |
1333 |
class => 'Koha::ILL::Requests', |
1334 |
value => { |
1334 |
value => { |
1335 |
borrowernumber => $patron->borrowernumber, |
1335 |
borrowernumber => $patron->borrowernumber, |
1336 |
biblio_id => $biblio->biblionumber |
1336 |
biblio_id => $biblio->biblionumber |
Lines 1365-1371
subtest 'Checking Limits' => sub {
Link Here
|
1365 |
$config->set_always('backend_dir', "/tmp"); |
1365 |
$config->set_always('backend_dir', "/tmp"); |
1366 |
|
1366 |
|
1367 |
my $illrq = $builder->build({source => 'Illrequest'}); |
1367 |
my $illrq = $builder->build({source => 'Illrequest'}); |
1368 |
my $illrq_obj = Koha::Illrequests->find($illrq->{illrequest_id}); |
1368 |
my $illrq_obj = Koha::ILL::Requests->find($illrq->{illrequest_id}); |
1369 |
$illrq_obj->_config($config); |
1369 |
$illrq_obj->_config($config); |
1370 |
$illrq_obj->_backend($backend); |
1370 |
$illrq_obj->_backend($backend); |
1371 |
|
1371 |
|
Lines 1554-1560
subtest 'Custom statuses' => sub {
Link Here
|
1554 |
|
1554 |
|
1555 |
my $ill_req = $builder->build_object( |
1555 |
my $ill_req = $builder->build_object( |
1556 |
{ |
1556 |
{ |
1557 |
class => 'Koha::Illrequests', |
1557 |
class => 'Koha::ILL::Requests', |
1558 |
value => { |
1558 |
value => { |
1559 |
status_alias => $av->authorised_value |
1559 |
status_alias => $av->authorised_value |
1560 |
} |
1560 |
} |
Lines 1565-1571
subtest 'Custom statuses' => sub {
Link Here
|
1565 |
|
1565 |
|
1566 |
$ill_req->status("COMP"); |
1566 |
$ill_req->status("COMP"); |
1567 |
is($ill_req->statusalias, undef, |
1567 |
is($ill_req->statusalias, undef, |
1568 |
"Koha::Illrequest->status overloading resetting status_alias"); |
1568 |
"Koha::ILL::Request->status overloading resetting status_alias"); |
1569 |
|
1569 |
|
1570 |
$schema->storage->txn_rollback; |
1570 |
$schema->storage->txn_rollback; |
1571 |
}; |
1571 |
}; |
Lines 1596-1602
subtest 'Checking in hook' => sub {
Link Here
|
1596 |
|
1596 |
|
1597 |
my $illrq = $builder->build_object( |
1597 |
my $illrq = $builder->build_object( |
1598 |
{ |
1598 |
{ |
1599 |
class => 'Koha::Illrequests', |
1599 |
class => 'Koha::ILL::Requests', |
1600 |
value => { |
1600 |
value => { |
1601 |
biblio_id => $item->biblio->biblionumber, |
1601 |
biblio_id => $item->biblio->biblionumber, |
1602 |
status => 'NEW' |
1602 |
status => 'NEW' |
Lines 1628-1630
subtest 'Checking in hook' => sub {
Link Here
|
1628 |
|
1628 |
|
1629 |
$schema->storage->txn_rollback; |
1629 |
$schema->storage->txn_rollback; |
1630 |
}; |
1630 |
}; |
|
|
1631 |
|
1632 |
subtest 'filter_by_visible() tests' => sub { |
1633 |
|
1634 |
plan tests => 4; |
1635 |
|
1636 |
$schema->storage->txn_begin; |
1637 |
|
1638 |
my $req = |
1639 |
$builder->build_object( { class => 'Koha::ILL::Requests', value => { status => 'REQ', biblio_id => undef } } ); |
1640 |
my $chk = |
1641 |
$builder->build_object( { class => 'Koha::ILL::Requests', value => { status => 'CHK', biblio_id => undef } } ); |
1642 |
my $ret = |
1643 |
$builder->build_object( { class => 'Koha::ILL::Requests', value => { status => 'RET', biblio_id => undef } } ); |
1644 |
|
1645 |
my $reqs_rs = Koha::ILL::Requests->search( { illrequest_id => [ $req->id, $chk->id, $ret->id ] } ); |
1646 |
|
1647 |
is( $reqs_rs->count, 3, 'Count is correct' ); |
1648 |
|
1649 |
t::lib::Mocks::mock_preference( 'ILLHiddenRequestStatuses', '' ); |
1650 |
|
1651 |
is( $reqs_rs->filter_by_visible->count, 3, 'No hidden statuses, same count' ); |
1652 |
|
1653 |
t::lib::Mocks::mock_preference( 'ILLHiddenRequestStatuses', 'CHK|RET' ); |
1654 |
|
1655 |
my $filtered_reqs = $reqs_rs->filter_by_visible; |
1656 |
|
1657 |
is( $filtered_reqs->count, 1, 'Count is correct' ); |
1658 |
is( $filtered_reqs->next->status, 'REQ' ); |
1659 |
|
1660 |
$schema->storage->txn_rollback; |
1661 |
}; |