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