Line 0
Link Here
|
0 |
- |
1 |
#!/usr/bin/perl |
|
|
2 |
|
3 |
# Copyright 2017 Aleisha Amohia <aleisha@catalyst.net.nz> |
4 |
# |
5 |
# This file is part of Koha |
6 |
# |
7 |
# Koha is free software; you can redistribute it and/or modify it |
8 |
# under the terms of the GNU General Public License as published by |
9 |
# the Free Software Foundation; either version 3 of the License, or |
10 |
# (at your option) any later version. |
11 |
# |
12 |
# Koha is distributed in the hope that it will be useful, but |
13 |
# WITHOUT ANY WARRANTY; without even the implied warranty of |
14 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 |
# GNU General Public License for more details. |
16 |
# |
17 |
# You should have received a copy of the GNU General Public License |
18 |
# along with Koha; if not, see <http://www.gnu.org/licenses>. |
19 |
|
20 |
use Modern::Perl; |
21 |
|
22 |
use Test::More tests => 11; |
23 |
|
24 |
use Koha::Recalls; |
25 |
use Koha::Recall; |
26 |
use Koha::Database; |
27 |
use Koha::DateUtils; |
28 |
use C4::Circulation; |
29 |
use t::lib::TestBuilder; |
30 |
|
31 |
my $schema = Koha::Database->new->schema; |
32 |
$schema->storage->txn_begin; |
33 |
|
34 |
my $builder = t::lib::TestBuilder->new; |
35 |
my $library = $builder->build( { source => 'Branch' } ); |
36 |
my $patron = $builder->build( { source => 'Borrower', value => { branchcode => $library->{branchcode} } } ); |
37 |
my $biblio = $builder->build( { source => 'Biblio' } ); |
38 |
my $itemtype = $builder->build( { source => 'Itemtype' } ); |
39 |
my $item = $builder->build( { source => 'Item', value => { biblionumber => $biblio->{biblionumber}, itype => $itemtype->{itemtype}, holdingbranch => $library->{branchcode} } } ); |
40 |
my $checkout = $builder->build( { source => 'Issue', value => { borrowernumber => 5, itemnumber => $item->{itemnumber} } } ); |
41 |
|
42 |
# recall requested by second patron |
43 |
my $recall = Koha::Recall->new({ |
44 |
borrowernumber => $patron->{borrowernumber}, |
45 |
recalldate => dt_from_string(), |
46 |
branchcode => $item->{holdingbranch}, |
47 |
status => 'R', |
48 |
biblionumber => $biblio->{biblionumber}, |
49 |
itemnumber => $item->{itemnumber}, |
50 |
itemtype => $item->{itype}, |
51 |
})->store; |
52 |
|
53 |
is( Koha::Recalls->search->count, 1, 'The one recall should be added' ); |
54 |
is( $recall->is_requested, 1, 'Recall status is set to R, requested' ); |
55 |
|
56 |
$recall->update({ status => 'O' }); |
57 |
is( $recall->is_overdue, 1, 'Recall is overdue to be returned' ); |
58 |
|
59 |
$recall->update({ status => 'W', waitingdate => dt_from_string() }); |
60 |
is( $recall->is_waiting, 1, 'Recall is waiting for pickup' ); |
61 |
|
62 |
$recall->update({ status => 'C', cancellationdate => dt_from_string(), old => 1 }); |
63 |
is( $recall->is_cancelled, 1, 'Recall has been cancelled' ); |
64 |
|
65 |
$recall->update({ status => 'E', expirationdate => dt_from_string() }); |
66 |
is( $recall->has_expired, 1, 'Recall has expired' ); |
67 |
|
68 |
is( $biblio->{biblionumber}, $recall->biblio->biblionumber, 'Can access biblio from recall' ); |
69 |
|
70 |
is( $patron->{borrowernumber}, $recall->borrower->borrowernumber, 'Can access borrower from recall' ); |
71 |
|
72 |
is( $item->{itemnumber}, $recall->item->itemnumber, 'Can access item from recall' ); |
73 |
|
74 |
is( $library->{branchcode}, $recall->branch->branchcode, 'Can access branch from recall' ); |
75 |
|
76 |
is( $checkout->{issue_id}, $recall->checkout->issue_id, 'Can access checkout from recall' ); |
77 |
|
78 |
$schema->storage->txn_rollback; |