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 => 50; |
21 |
use Test::More tests => 53; |
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 1258-1263
subtest "CanBookBeRenewed tests" => sub {
Link Here
|
1258 |
$item_3->itemcallnumber || '' ), |
1258 |
$item_3->itemcallnumber || '' ), |
1259 |
"Account line description must not contain 'Lost Items ', but be title, barcode, itemcallnumber" |
1259 |
"Account line description must not contain 'Lost Items ', but be title, barcode, itemcallnumber" |
1260 |
); |
1260 |
); |
|
|
1261 |
|
1262 |
# Recalls |
1263 |
t::lib::Mocks::mock_preference('UseRecalls', 1); |
1264 |
Koha::CirculationRules->set_rules({ |
1265 |
categorycode => undef, |
1266 |
branchcode => undef, |
1267 |
itemtype => undef, |
1268 |
rules => { |
1269 |
recalls_allowed => 10, |
1270 |
renewalsallowed => 5, |
1271 |
}, |
1272 |
}); |
1273 |
my $recall_borrower = $builder->build_object({ class => 'Koha::Patrons' }); |
1274 |
my $recall_biblio = $builder->build_object({ class => 'Koha::Biblios' }); |
1275 |
my $recall_item1 = $builder->build_object({ class => 'Koha::Items' }, { value => { biblionumber => $recall_biblio->biblionumber } }); |
1276 |
my $recall_item2 = $builder->build_object({ class => 'Koha::Items' }, { value => { biblionumber => $recall_biblio->biblionumber } }); |
1277 |
|
1278 |
AddIssue( $renewing_borrower, $recall_item1->barcode ); |
1279 |
|
1280 |
# item-level and this item: renewal not allowed |
1281 |
my $recall = Koha::Recall->new({ |
1282 |
biblionumber => $recall_item1->biblionumber, |
1283 |
itemnumber => $recall_item1->itemnumber, |
1284 |
borrowernumber => $recall_borrower->borrowernumber, |
1285 |
branchcode => $recall_borrower->branchcode, |
1286 |
item_level_recall => 1, |
1287 |
status => 'R', |
1288 |
})->store; |
1289 |
( $renewokay, $error ) = CanBookBeRenewed( $renewing_borrowernumber, $recall_item1->itemnumber ); |
1290 |
is( $error, 'recalled', 'Cannot renew item that has been recalled' ); |
1291 |
$recall->set_cancelled; |
1292 |
|
1293 |
# biblio-level requested recall: renewal not allowed |
1294 |
$recall = Koha::Recall->new({ |
1295 |
biblionumber => $recall_item1->biblionumber, |
1296 |
itemnumber => undef, |
1297 |
borrowernumber => $recall_borrower->borrowernumber, |
1298 |
branchcode => $recall_borrower->branchcode, |
1299 |
item_level_recall => 0, |
1300 |
status => 'R', |
1301 |
})->store; |
1302 |
( $renewokay, $error ) = CanBookBeRenewed( $renewing_borrowernumber, $recall_item1->itemnumber ); |
1303 |
is( $error, 'recalled', 'Cannot renew item if biblio is recalled and has no item allocated' ); |
1304 |
$recall->set_cancelled; |
1305 |
|
1306 |
# item-level and not this item: renewal allowed |
1307 |
$recall = Koha::Recall->new({ |
1308 |
biblionumber => $recall_item2->biblionumber, |
1309 |
itemnumber => $recall_item2->itemnumber, |
1310 |
borrowernumber => $recall_borrower->borrowernumber, |
1311 |
branchcode => $recall_borrower->branchcode, |
1312 |
item_level_recall => 1, |
1313 |
status => 'R', |
1314 |
})->store; |
1315 |
( $renewokay, $error ) = CanBookBeRenewed( $renewing_borrowernumber, $recall_item1->itemnumber ); |
1316 |
is( $renewokay, 1, 'Can renew item if item-level recall on biblio is not on this item' ); |
1317 |
$recall->set_cancelled; |
1318 |
|
1319 |
# biblio-level waiting recall: renewal allowed |
1320 |
$recall = Koha::Recall->new({ |
1321 |
biblionumber => $recall_item1->biblionumber, |
1322 |
itemnumber => undef, |
1323 |
borrowernumber => $recall_borrower->borrowernumber, |
1324 |
branchcode => $recall_borrower->branchcode, |
1325 |
item_level_recall => 0, |
1326 |
status => 'R', |
1327 |
})->store; |
1328 |
$recall->set_waiting({ item => $recall_item1 }); |
1329 |
( $renewokay, $error ) = CanBookBeRenewed( $renewing_borrowernumber, $recall_item1->itemnumber ); |
1330 |
is( $renewokay, 1, 'Can renew item if biblio-level recall has already been allocated an item' ); |
1331 |
$recall->set_cancelled; |
1261 |
}; |
1332 |
}; |
1262 |
|
1333 |
|
1263 |
subtest "GetUpcomingDueIssues" => sub { |
1334 |
subtest "GetUpcomingDueIssues" => sub { |
Lines 1738-1743
subtest 'AddIssue & AllowReturnToBranch' => sub {
Link Here
|
1738 |
# TODO t::lib::Mocks::mock_preference('AllowReturnToBranch', 'homeorholdingbranch'); |
1809 |
# TODO t::lib::Mocks::mock_preference('AllowReturnToBranch', 'homeorholdingbranch'); |
1739 |
}; |
1810 |
}; |
1740 |
|
1811 |
|
|
|
1812 |
subtest 'AddIssue | recalls' => sub { |
1813 |
plan tests => 3; |
1814 |
|
1815 |
t::lib::Mocks::mock_preference("UseRecalls", 1); |
1816 |
t::lib::Mocks::mock_preference("item-level_itypes", 1); |
1817 |
my $patron1 = $builder->build_object({ class => 'Koha::Patrons' }); |
1818 |
my $patron2 = $builder->build_object({ class => 'Koha::Patrons' }); |
1819 |
my $item = $builder->build_sample_item; |
1820 |
Koha::CirculationRules->set_rules({ |
1821 |
branchcode => undef, |
1822 |
itemtype => undef, |
1823 |
categorycode => undef, |
1824 |
rules => { |
1825 |
recalls_allowed => 10, |
1826 |
}, |
1827 |
}); |
1828 |
|
1829 |
# checking out item that they have recalled |
1830 |
my $recall1 = Koha::Recall->new({ |
1831 |
borrowernumber => $patron1->borrowernumber, |
1832 |
biblionumber => $item->biblionumber, |
1833 |
itemnumber => $item->itemnumber, |
1834 |
item_level_recall => 1, |
1835 |
branchcode => $patron1->branchcode, |
1836 |
status => 'R', |
1837 |
})->store; |
1838 |
AddIssue( $patron1->unblessed, $item->barcode, undef, undef, undef, undef, { recall_id => $recall1->recall_id } ); |
1839 |
$recall1 = Koha::Recalls->find( $recall1->recall_id ); |
1840 |
is( $recall1->finished, 1, 'Recall was fulfilled when patron checked out item' ); |
1841 |
AddReturn( $item->barcode, $item->homebranch ); |
1842 |
|
1843 |
# this item is has a recall request. cancel recall |
1844 |
my $recall2 = Koha::Recall->new({ |
1845 |
borrowernumber => $patron2->borrowernumber, |
1846 |
biblionumber => $item->biblionumber, |
1847 |
itemnumber => $item->itemnumber, |
1848 |
item_level_recall => 1, |
1849 |
branchcode => $patron2->branchcode, |
1850 |
status => 'R', |
1851 |
})->store; |
1852 |
AddIssue( $patron1->unblessed, $item->barcode, undef, undef, undef, undef, { recall_id => $recall2->recall_id, cancel_recall => 'cancel' } ); |
1853 |
$recall2 = Koha::Recalls->find( $recall2->recall_id ); |
1854 |
is( $recall2->cancelled, 1, 'Recall was cancelled when patron checked out item' ); |
1855 |
AddReturn( $item->barcode, $item->homebranch ); |
1856 |
|
1857 |
# this item is waiting to fulfill a recall. revert recall |
1858 |
my $recall3 = Koha::Recall->new({ |
1859 |
borrowernumber => $patron2->borrowernumber, |
1860 |
biblionumber => $item->biblionumber, |
1861 |
itemnumber => $item->itemnumber, |
1862 |
item_level_recall => 1, |
1863 |
branchcode => $patron2->branchcode, |
1864 |
status => 'R', |
1865 |
})->store; |
1866 |
$recall3->set_waiting; |
1867 |
AddIssue( $patron1->unblessed, $item->barcode, undef, undef, undef, undef, { recall_id => $recall3->recall_id, cancel_recall => 'revert' } ); |
1868 |
$recall3 = Koha::Recalls->find( $recall3->recall_id ); |
1869 |
is( $recall3->requested, 1, 'Recall was reverted from waiting when patron checked out item' ); |
1870 |
AddReturn( $item->barcode, $item->homebranch ); |
1871 |
}; |
1872 |
|
1873 |
|
1741 |
subtest 'CanBookBeIssued + Koha::Patron->is_debarred|has_overdues' => sub { |
1874 |
subtest 'CanBookBeIssued + Koha::Patron->is_debarred|has_overdues' => sub { |
1742 |
plan tests => 8; |
1875 |
plan tests => 8; |
1743 |
|
1876 |
|
Lines 3641-3646
subtest 'CanBookBeIssued | notforloan' => sub {
Link Here
|
3641 |
# TODO test with AllowNotForLoanOverride = 1 |
3774 |
# TODO test with AllowNotForLoanOverride = 1 |
3642 |
}; |
3775 |
}; |
3643 |
|
3776 |
|
|
|
3777 |
subtest 'CanBookBeIssued | recalls' => sub { |
3778 |
plan tests => 3; |
3779 |
|
3780 |
t::lib::Mocks::mock_preference("UseRecalls", 1); |
3781 |
t::lib::Mocks::mock_preference("item-level_itypes", 1); |
3782 |
my $patron1 = $builder->build_object({ class => 'Koha::Patrons' }); |
3783 |
my $patron2 = $builder->build_object({ class => 'Koha::Patrons' }); |
3784 |
my $item = $builder->build_sample_item; |
3785 |
Koha::CirculationRules->set_rules({ |
3786 |
branchcode => undef, |
3787 |
itemtype => undef, |
3788 |
categorycode => undef, |
3789 |
rules => { |
3790 |
recalls_allowed => 10, |
3791 |
}, |
3792 |
}); |
3793 |
|
3794 |
# item-level recall |
3795 |
my $recall = Koha::Recall->new({ |
3796 |
borrowernumber => $patron1->borrowernumber, |
3797 |
biblionumber => $item->biblionumber, |
3798 |
itemnumber => $item->itemnumber, |
3799 |
item_level_recall => 1, |
3800 |
branchcode => $patron1->branchcode, |
3801 |
status => 'R', |
3802 |
})->store; |
3803 |
|
3804 |
my ( $issuingimpossible, $needsconfirmation ) = CanBookBeIssued( $patron2, $item->barcode, undef, undef, undef, undef ); |
3805 |
is( $needsconfirmation->{RECALLED}->recall_id, $recall->recall_id, "Another patron has placed an item-level recall on this item" ); |
3806 |
|
3807 |
$recall->set_cancelled; |
3808 |
|
3809 |
# biblio-level recall |
3810 |
$recall = Koha::Recall->new({ |
3811 |
borrowernumber => $patron1->borrowernumber, |
3812 |
biblionumber => $item->biblionumber, |
3813 |
itemnumber => undef, |
3814 |
item_level_recall => 0, |
3815 |
branchcode => $patron1->branchcode, |
3816 |
status => 'R', |
3817 |
})->store; |
3818 |
|
3819 |
( $issuingimpossible, $needsconfirmation ) = CanBookBeIssued( $patron2, $item->barcode, undef, undef, undef, undef ); |
3820 |
is( $needsconfirmation->{RECALLED}->recall_id, $recall->recall_id, "Another patron has placed a biblio-level recall and this item is eligible to fill it" ); |
3821 |
|
3822 |
$recall->set_cancelled; |
3823 |
|
3824 |
# biblio-level recall |
3825 |
$recall = Koha::Recall->new({ |
3826 |
borrowernumber => $patron1->borrowernumber, |
3827 |
biblionumber => $item->biblionumber, |
3828 |
itemnumber => undef, |
3829 |
item_level_recall => 0, |
3830 |
branchcode => $patron1->branchcode, |
3831 |
status => 'R', |
3832 |
})->store; |
3833 |
$recall->set_waiting({ item => $item, expirationdate => dt_from_string() }); |
3834 |
|
3835 |
my ( undef, undef, undef, $messages ) = CanBookBeIssued( $patron1, $item->barcode, undef, undef, undef, undef ); |
3836 |
is( $messages->{RECALLED}, $recall->recall_id, "This book can be issued by this patron and they have placed a recall" ); |
3837 |
|
3838 |
$recall->set_cancelled; |
3839 |
}; |
3840 |
|
3644 |
subtest 'AddReturn should clear items.onloan for unissued items' => sub { |
3841 |
subtest 'AddReturn should clear items.onloan for unissued items' => sub { |
3645 |
plan tests => 1; |
3842 |
plan tests => 1; |
3646 |
|
3843 |
|
Lines 3656-3661
subtest 'AddReturn should clear items.onloan for unissued items' => sub {
Link Here
|
3656 |
is( $item->onloan, undef, 'AddReturn did clear items.onloan' ); |
3853 |
is( $item->onloan, undef, 'AddReturn did clear items.onloan' ); |
3657 |
}; |
3854 |
}; |
3658 |
|
3855 |
|
|
|
3856 |
subtest 'AddReturn | recalls' => sub { |
3857 |
plan tests => 3; |
3858 |
|
3859 |
t::lib::Mocks::mock_preference("UseRecalls", 1); |
3860 |
t::lib::Mocks::mock_preference("item-level_itypes", 1); |
3861 |
my $patron1 = $builder->build_object({ class => 'Koha::Patrons' }); |
3862 |
my $patron2 = $builder->build_object({ class => 'Koha::Patrons' }); |
3863 |
my $item1 = $builder->build_sample_item; |
3864 |
Koha::CirculationRules->set_rules({ |
3865 |
branchcode => undef, |
3866 |
itemtype => undef, |
3867 |
categorycode => undef, |
3868 |
rules => { |
3869 |
recalls_allowed => 10, |
3870 |
}, |
3871 |
}); |
3872 |
|
3873 |
# this item can fill a recall with pickup at this branch |
3874 |
AddIssue( $patron1->unblessed, $item1->barcode ); |
3875 |
my $recall1 = Koha::Recall->new({ |
3876 |
borrowernumber => $patron2->borrowernumber, |
3877 |
biblionumber => $item1->biblionumber, |
3878 |
itemnumber => $item1->itemnumber, |
3879 |
item_level_recall => 1, |
3880 |
branchcode => $item1->homebranch, |
3881 |
status => 'R', |
3882 |
})->store; |
3883 |
my ( $doreturn, $messages, $iteminfo, $borrowerinfo ) = AddReturn( $item1->barcode, $item1->homebranch ); |
3884 |
is( $messages->{RecallFound}->recall_id, $recall1->recall_id, "Recall found" ); |
3885 |
$recall1->set_cancelled; |
3886 |
|
3887 |
# this item can fill a recall but needs transfer |
3888 |
AddIssue( $patron1->unblessed, $item1->barcode ); |
3889 |
$recall1 = Koha::Recall->new({ |
3890 |
borrowernumber => $patron2->borrowernumber, |
3891 |
biblionumber => $item1->biblionumber, |
3892 |
itemnumber => $item1->itemnumber, |
3893 |
item_level_recall => 1, |
3894 |
branchcode => $patron2->branchcode, |
3895 |
status => 'R', |
3896 |
})->store; |
3897 |
( $doreturn, $messages, $iteminfo, $borrowerinfo ) = AddReturn( $item1->barcode, $item1->homebranch ); |
3898 |
is( $messages->{RecallNeedsTransfer}, $item1->homebranch, "Recall requiring transfer found" ); |
3899 |
$recall1->set_cancelled; |
3900 |
|
3901 |
# this item is already in transit, do not ask to transfer |
3902 |
AddIssue( $patron1->unblessed, $item1->barcode ); |
3903 |
$recall1 = Koha::Recall->new({ |
3904 |
borrowernumber => $patron2->borrowernumber, |
3905 |
biblionumber => $item1->biblionumber, |
3906 |
itemnumber => $item1->itemnumber, |
3907 |
item_level_recall => 1, |
3908 |
branchcode => $patron2->branchcode, |
3909 |
status => 'R', |
3910 |
})->store; |
3911 |
$recall1->start_transfer; |
3912 |
( $doreturn, $messages, $iteminfo, $borrowerinfo ) = AddReturn( $item1->barcode, $patron2->branchcode ); |
3913 |
is( $messages->{TransferredRecall}->recall_id, $recall1->recall_id, "In transit recall found" ); |
3914 |
$recall1->set_cancelled; |
3915 |
}; |
3659 |
|
3916 |
|
3660 |
subtest 'AddRenewal and AddIssuingCharge tests' => sub { |
3917 |
subtest 'AddRenewal and AddIssuingCharge tests' => sub { |
3661 |
|
3918 |
|