Lines 18-24
Link Here
|
18 |
use Modern::Perl; |
18 |
use Modern::Perl; |
19 |
use utf8; |
19 |
use utf8; |
20 |
|
20 |
|
21 |
use Test::More tests => 52; |
21 |
use Test::More tests => 55; |
22 |
use Test::Exception; |
22 |
use Test::Exception; |
23 |
use Test::MockModule; |
23 |
use Test::MockModule; |
24 |
use Test::Deep qw( cmp_deeply ); |
24 |
use Test::Deep qw( cmp_deeply ); |
Lines 329-335
subtest "GetIssuingCharges tests" => sub {
Link Here
|
329 |
|
329 |
|
330 |
my ( $reused_itemnumber_1, $reused_itemnumber_2 ); |
330 |
my ( $reused_itemnumber_1, $reused_itemnumber_2 ); |
331 |
subtest "CanBookBeRenewed tests" => sub { |
331 |
subtest "CanBookBeRenewed tests" => sub { |
332 |
plan tests => 89; |
332 |
plan tests => 93; |
333 |
|
333 |
|
334 |
C4::Context->set_preference('ItemsDeniedRenewal',''); |
334 |
C4::Context->set_preference('ItemsDeniedRenewal',''); |
335 |
# Generate test biblio |
335 |
# Generate test biblio |
Lines 1338-1343
subtest "CanBookBeRenewed tests" => sub {
Link Here
|
1338 |
$item_3->itemcallnumber || '' ), |
1338 |
$item_3->itemcallnumber || '' ), |
1339 |
"Account line description must not contain 'Lost Items ', but be title, barcode, itemcallnumber" |
1339 |
"Account line description must not contain 'Lost Items ', but be title, barcode, itemcallnumber" |
1340 |
); |
1340 |
); |
|
|
1341 |
|
1342 |
# Recalls |
1343 |
t::lib::Mocks::mock_preference('UseRecalls', 1); |
1344 |
Koha::CirculationRules->set_rules({ |
1345 |
categorycode => undef, |
1346 |
branchcode => undef, |
1347 |
itemtype => undef, |
1348 |
rules => { |
1349 |
recalls_allowed => 10, |
1350 |
renewalsallowed => 5, |
1351 |
}, |
1352 |
}); |
1353 |
my $recall_borrower = $builder->build_object({ class => 'Koha::Patrons' }); |
1354 |
my $recall_biblio = $builder->build_object({ class => 'Koha::Biblios' }); |
1355 |
my $recall_item1 = $builder->build_object({ class => 'Koha::Items' }, { value => { biblionumber => $recall_biblio->biblionumber } }); |
1356 |
my $recall_item2 = $builder->build_object({ class => 'Koha::Items' }, { value => { biblionumber => $recall_biblio->biblionumber } }); |
1357 |
|
1358 |
AddIssue( $renewing_borrower, $recall_item1->barcode ); |
1359 |
|
1360 |
# item-level and this item: renewal not allowed |
1361 |
my $recall = Koha::Recall->new({ |
1362 |
biblionumber => $recall_item1->biblionumber, |
1363 |
itemnumber => $recall_item1->itemnumber, |
1364 |
borrowernumber => $recall_borrower->borrowernumber, |
1365 |
branchcode => $recall_borrower->branchcode, |
1366 |
item_level_recall => 1, |
1367 |
status => 'R', |
1368 |
})->store; |
1369 |
( $renewokay, $error ) = CanBookBeRenewed( $renewing_borrowernumber, $recall_item1->itemnumber ); |
1370 |
is( $error, 'recalled', 'Cannot renew item that has been recalled' ); |
1371 |
$recall->set_cancelled; |
1372 |
|
1373 |
# biblio-level requested recall: renewal not allowed |
1374 |
$recall = Koha::Recall->new({ |
1375 |
biblionumber => $recall_item1->biblionumber, |
1376 |
itemnumber => undef, |
1377 |
borrowernumber => $recall_borrower->borrowernumber, |
1378 |
branchcode => $recall_borrower->branchcode, |
1379 |
item_level_recall => 0, |
1380 |
status => 'R', |
1381 |
})->store; |
1382 |
( $renewokay, $error ) = CanBookBeRenewed( $renewing_borrowernumber, $recall_item1->itemnumber ); |
1383 |
is( $error, 'recalled', 'Cannot renew item if biblio is recalled and has no item allocated' ); |
1384 |
$recall->set_cancelled; |
1385 |
|
1386 |
# item-level and not this item: renewal allowed |
1387 |
$recall = Koha::Recall->new({ |
1388 |
biblionumber => $recall_item2->biblionumber, |
1389 |
itemnumber => $recall_item2->itemnumber, |
1390 |
borrowernumber => $recall_borrower->borrowernumber, |
1391 |
branchcode => $recall_borrower->branchcode, |
1392 |
item_level_recall => 1, |
1393 |
status => 'R', |
1394 |
})->store; |
1395 |
( $renewokay, $error ) = CanBookBeRenewed( $renewing_borrowernumber, $recall_item1->itemnumber ); |
1396 |
is( $renewokay, 1, 'Can renew item if item-level recall on biblio is not on this item' ); |
1397 |
$recall->set_cancelled; |
1398 |
|
1399 |
# biblio-level waiting recall: renewal allowed |
1400 |
$recall = Koha::Recall->new({ |
1401 |
biblionumber => $recall_item1->biblionumber, |
1402 |
itemnumber => undef, |
1403 |
borrowernumber => $recall_borrower->borrowernumber, |
1404 |
branchcode => $recall_borrower->branchcode, |
1405 |
item_level_recall => 0, |
1406 |
status => 'R', |
1407 |
})->store; |
1408 |
$recall->set_waiting({ item => $recall_item1 }); |
1409 |
( $renewokay, $error ) = CanBookBeRenewed( $renewing_borrowernumber, $recall_item1->itemnumber ); |
1410 |
is( $renewokay, 1, 'Can renew item if biblio-level recall has already been allocated an item' ); |
1411 |
$recall->set_cancelled; |
1341 |
}; |
1412 |
}; |
1342 |
|
1413 |
|
1343 |
subtest "GetUpcomingDueIssues" => sub { |
1414 |
subtest "GetUpcomingDueIssues" => sub { |
Lines 1818-1823
subtest 'AddIssue & AllowReturnToBranch' => sub {
Link Here
|
1818 |
# TODO t::lib::Mocks::mock_preference('AllowReturnToBranch', 'homeorholdingbranch'); |
1889 |
# TODO t::lib::Mocks::mock_preference('AllowReturnToBranch', 'homeorholdingbranch'); |
1819 |
}; |
1890 |
}; |
1820 |
|
1891 |
|
|
|
1892 |
subtest 'AddIssue | recalls' => sub { |
1893 |
plan tests => 3; |
1894 |
|
1895 |
t::lib::Mocks::mock_preference("UseRecalls", 1); |
1896 |
t::lib::Mocks::mock_preference("item-level_itypes", 1); |
1897 |
my $patron1 = $builder->build_object({ class => 'Koha::Patrons' }); |
1898 |
my $patron2 = $builder->build_object({ class => 'Koha::Patrons' }); |
1899 |
my $item = $builder->build_sample_item; |
1900 |
Koha::CirculationRules->set_rules({ |
1901 |
branchcode => undef, |
1902 |
itemtype => undef, |
1903 |
categorycode => undef, |
1904 |
rules => { |
1905 |
recalls_allowed => 10, |
1906 |
}, |
1907 |
}); |
1908 |
|
1909 |
# checking out item that they have recalled |
1910 |
my $recall1 = Koha::Recall->new({ |
1911 |
borrowernumber => $patron1->borrowernumber, |
1912 |
biblionumber => $item->biblionumber, |
1913 |
itemnumber => $item->itemnumber, |
1914 |
item_level_recall => 1, |
1915 |
branchcode => $patron1->branchcode, |
1916 |
status => 'R', |
1917 |
})->store; |
1918 |
AddIssue( $patron1->unblessed, $item->barcode, undef, undef, undef, undef, { recall_id => $recall1->recall_id } ); |
1919 |
$recall1 = Koha::Recalls->find( $recall1->recall_id ); |
1920 |
is( $recall1->finished, 1, 'Recall was fulfilled when patron checked out item' ); |
1921 |
AddReturn( $item->barcode, $item->homebranch ); |
1922 |
|
1923 |
# this item is has a recall request. cancel recall |
1924 |
my $recall2 = Koha::Recall->new({ |
1925 |
borrowernumber => $patron2->borrowernumber, |
1926 |
biblionumber => $item->biblionumber, |
1927 |
itemnumber => $item->itemnumber, |
1928 |
item_level_recall => 1, |
1929 |
branchcode => $patron2->branchcode, |
1930 |
status => 'R', |
1931 |
})->store; |
1932 |
AddIssue( $patron1->unblessed, $item->barcode, undef, undef, undef, undef, { recall_id => $recall2->recall_id, cancel_recall => 'cancel' } ); |
1933 |
$recall2 = Koha::Recalls->find( $recall2->recall_id ); |
1934 |
is( $recall2->cancelled, 1, 'Recall was cancelled when patron checked out item' ); |
1935 |
AddReturn( $item->barcode, $item->homebranch ); |
1936 |
|
1937 |
# this item is waiting to fulfill a recall. revert recall |
1938 |
my $recall3 = Koha::Recall->new({ |
1939 |
borrowernumber => $patron2->borrowernumber, |
1940 |
biblionumber => $item->biblionumber, |
1941 |
itemnumber => $item->itemnumber, |
1942 |
item_level_recall => 1, |
1943 |
branchcode => $patron2->branchcode, |
1944 |
status => 'R', |
1945 |
})->store; |
1946 |
$recall3->set_waiting; |
1947 |
AddIssue( $patron1->unblessed, $item->barcode, undef, undef, undef, undef, { recall_id => $recall3->recall_id, cancel_recall => 'revert' } ); |
1948 |
$recall3 = Koha::Recalls->find( $recall3->recall_id ); |
1949 |
is( $recall3->requested, 1, 'Recall was reverted from waiting when patron checked out item' ); |
1950 |
AddReturn( $item->barcode, $item->homebranch ); |
1951 |
}; |
1952 |
|
1953 |
|
1821 |
subtest 'CanBookBeIssued + Koha::Patron->is_debarred|has_overdues' => sub { |
1954 |
subtest 'CanBookBeIssued + Koha::Patron->is_debarred|has_overdues' => sub { |
1822 |
plan tests => 8; |
1955 |
plan tests => 8; |
1823 |
|
1956 |
|
Lines 3721-3726
subtest 'CanBookBeIssued | notforloan' => sub {
Link Here
|
3721 |
# TODO test with AllowNotForLoanOverride = 1 |
3854 |
# TODO test with AllowNotForLoanOverride = 1 |
3722 |
}; |
3855 |
}; |
3723 |
|
3856 |
|
|
|
3857 |
subtest 'CanBookBeIssued | recalls' => sub { |
3858 |
plan tests => 3; |
3859 |
|
3860 |
t::lib::Mocks::mock_preference("UseRecalls", 1); |
3861 |
t::lib::Mocks::mock_preference("item-level_itypes", 1); |
3862 |
my $patron1 = $builder->build_object({ class => 'Koha::Patrons' }); |
3863 |
my $patron2 = $builder->build_object({ class => 'Koha::Patrons' }); |
3864 |
my $item = $builder->build_sample_item; |
3865 |
Koha::CirculationRules->set_rules({ |
3866 |
branchcode => undef, |
3867 |
itemtype => undef, |
3868 |
categorycode => undef, |
3869 |
rules => { |
3870 |
recalls_allowed => 10, |
3871 |
}, |
3872 |
}); |
3873 |
|
3874 |
# item-level recall |
3875 |
my $recall = Koha::Recall->new({ |
3876 |
borrowernumber => $patron1->borrowernumber, |
3877 |
biblionumber => $item->biblionumber, |
3878 |
itemnumber => $item->itemnumber, |
3879 |
item_level_recall => 1, |
3880 |
branchcode => $patron1->branchcode, |
3881 |
status => 'R', |
3882 |
})->store; |
3883 |
|
3884 |
my ( $issuingimpossible, $needsconfirmation ) = CanBookBeIssued( $patron2, $item->barcode, undef, undef, undef, undef ); |
3885 |
is( $needsconfirmation->{RECALLED}->recall_id, $recall->recall_id, "Another patron has placed an item-level recall on this item" ); |
3886 |
|
3887 |
$recall->set_cancelled; |
3888 |
|
3889 |
# biblio-level recall |
3890 |
$recall = Koha::Recall->new({ |
3891 |
borrowernumber => $patron1->borrowernumber, |
3892 |
biblionumber => $item->biblionumber, |
3893 |
itemnumber => undef, |
3894 |
item_level_recall => 0, |
3895 |
branchcode => $patron1->branchcode, |
3896 |
status => 'R', |
3897 |
})->store; |
3898 |
|
3899 |
( $issuingimpossible, $needsconfirmation ) = CanBookBeIssued( $patron2, $item->barcode, undef, undef, undef, undef ); |
3900 |
is( $needsconfirmation->{RECALLED}->recall_id, $recall->recall_id, "Another patron has placed a biblio-level recall and this item is eligible to fill it" ); |
3901 |
|
3902 |
$recall->set_cancelled; |
3903 |
|
3904 |
# biblio-level recall |
3905 |
$recall = Koha::Recall->new({ |
3906 |
borrowernumber => $patron1->borrowernumber, |
3907 |
biblionumber => $item->biblionumber, |
3908 |
itemnumber => undef, |
3909 |
item_level_recall => 0, |
3910 |
branchcode => $patron1->branchcode, |
3911 |
status => 'R', |
3912 |
})->store; |
3913 |
$recall->set_waiting({ item => $item, expirationdate => dt_from_string() }); |
3914 |
|
3915 |
my ( undef, undef, undef, $messages ) = CanBookBeIssued( $patron1, $item->barcode, undef, undef, undef, undef ); |
3916 |
is( $messages->{RECALLED}, $recall->recall_id, "This book can be issued by this patron and they have placed a recall" ); |
3917 |
|
3918 |
$recall->set_cancelled; |
3919 |
}; |
3920 |
|
3724 |
subtest 'AddReturn should clear items.onloan for unissued items' => sub { |
3921 |
subtest 'AddReturn should clear items.onloan for unissued items' => sub { |
3725 |
plan tests => 1; |
3922 |
plan tests => 1; |
3726 |
|
3923 |
|
Lines 3736-3741
subtest 'AddReturn should clear items.onloan for unissued items' => sub {
Link Here
|
3736 |
is( $item->onloan, undef, 'AddReturn did clear items.onloan' ); |
3933 |
is( $item->onloan, undef, 'AddReturn did clear items.onloan' ); |
3737 |
}; |
3934 |
}; |
3738 |
|
3935 |
|
|
|
3936 |
subtest 'AddReturn | recalls' => sub { |
3937 |
plan tests => 3; |
3938 |
|
3939 |
t::lib::Mocks::mock_preference("UseRecalls", 1); |
3940 |
t::lib::Mocks::mock_preference("item-level_itypes", 1); |
3941 |
my $patron1 = $builder->build_object({ class => 'Koha::Patrons' }); |
3942 |
my $patron2 = $builder->build_object({ class => 'Koha::Patrons' }); |
3943 |
my $item1 = $builder->build_sample_item; |
3944 |
Koha::CirculationRules->set_rules({ |
3945 |
branchcode => undef, |
3946 |
itemtype => undef, |
3947 |
categorycode => undef, |
3948 |
rules => { |
3949 |
recalls_allowed => 10, |
3950 |
}, |
3951 |
}); |
3952 |
|
3953 |
# this item can fill a recall with pickup at this branch |
3954 |
AddIssue( $patron1->unblessed, $item1->barcode ); |
3955 |
my $recall1 = Koha::Recall->new({ |
3956 |
borrowernumber => $patron2->borrowernumber, |
3957 |
biblionumber => $item1->biblionumber, |
3958 |
itemnumber => $item1->itemnumber, |
3959 |
item_level_recall => 1, |
3960 |
branchcode => $item1->homebranch, |
3961 |
status => 'R', |
3962 |
})->store; |
3963 |
my ( $doreturn, $messages, $iteminfo, $borrowerinfo ) = AddReturn( $item1->barcode, $item1->homebranch ); |
3964 |
is( $messages->{RecallFound}->recall_id, $recall1->recall_id, "Recall found" ); |
3965 |
$recall1->set_cancelled; |
3966 |
|
3967 |
# this item can fill a recall but needs transfer |
3968 |
AddIssue( $patron1->unblessed, $item1->barcode ); |
3969 |
$recall1 = Koha::Recall->new({ |
3970 |
borrowernumber => $patron2->borrowernumber, |
3971 |
biblionumber => $item1->biblionumber, |
3972 |
itemnumber => $item1->itemnumber, |
3973 |
item_level_recall => 1, |
3974 |
branchcode => $patron2->branchcode, |
3975 |
status => 'R', |
3976 |
})->store; |
3977 |
( $doreturn, $messages, $iteminfo, $borrowerinfo ) = AddReturn( $item1->barcode, $item1->homebranch ); |
3978 |
is( $messages->{RecallNeedsTransfer}, $item1->homebranch, "Recall requiring transfer found" ); |
3979 |
$recall1->set_cancelled; |
3980 |
|
3981 |
# this item is already in transit, do not ask to transfer |
3982 |
AddIssue( $patron1->unblessed, $item1->barcode ); |
3983 |
$recall1 = Koha::Recall->new({ |
3984 |
borrowernumber => $patron2->borrowernumber, |
3985 |
biblionumber => $item1->biblionumber, |
3986 |
itemnumber => $item1->itemnumber, |
3987 |
item_level_recall => 1, |
3988 |
branchcode => $patron2->branchcode, |
3989 |
status => 'R', |
3990 |
})->store; |
3991 |
$recall1->start_transfer; |
3992 |
( $doreturn, $messages, $iteminfo, $borrowerinfo ) = AddReturn( $item1->barcode, $patron2->branchcode ); |
3993 |
is( $messages->{TransferredRecall}->recall_id, $recall1->recall_id, "In transit recall found" ); |
3994 |
$recall1->set_cancelled; |
3995 |
}; |
3739 |
|
3996 |
|
3740 |
subtest 'AddRenewal and AddIssuingCharge tests' => sub { |
3997 |
subtest 'AddRenewal and AddIssuingCharge tests' => sub { |
3741 |
|
3998 |
|