Lines 18-27
Link Here
|
18 |
use Modern::Perl; |
18 |
use Modern::Perl; |
19 |
|
19 |
|
20 |
use C4::Context; |
20 |
use C4::Context; |
|
|
21 |
use C4::Biblio qw( AddBiblio ); |
21 |
use Koha::Database; |
22 |
use Koha::Database; |
22 |
use Koha::Borrowers; |
23 |
use Koha::Borrowers; |
|
|
24 |
use Koha::Branches; |
25 |
use Koha::Item; |
23 |
|
26 |
|
24 |
use Test::More tests => 16; |
27 |
use Test::More tests => 23; |
25 |
|
28 |
|
26 |
use_ok('Koha::Hold'); |
29 |
use_ok('Koha::Hold'); |
27 |
|
30 |
|
Lines 31-74
$schema->storage->txn_begin();
Link Here
|
31 |
my $dbh = C4::Context->dbh; |
34 |
my $dbh = C4::Context->dbh; |
32 |
$dbh->{RaiseError} = 1; |
35 |
$dbh->{RaiseError} = 1; |
33 |
|
36 |
|
|
|
37 |
my @branches = Koha::Branches->search(); |
34 |
my $borrower = Koha::Borrowers->search()->next(); |
38 |
my $borrower = Koha::Borrowers->search()->next(); |
|
|
39 |
|
40 |
my $biblio = MARC::Record->new(); |
41 |
my $title = 'Silence in the library'; |
42 |
$biblio->append_fields( |
43 |
MARC::Field->new( '100', ' ', ' ', a => 'Moffat, Steven' ), |
44 |
MARC::Field->new( '245', ' ', ' ', a => $title ), |
45 |
); |
46 |
my ( $biblionumber, $biblioitemnumber ) = AddBiblio( $biblio, '' ); |
47 |
|
48 |
my $item = Koha::Item->new( |
49 |
{ |
50 |
biblionumber => $biblionumber, |
51 |
biblioitemnumber => $biblioitemnumber, |
52 |
holdingbranch => $branches[0]->branchcode(), |
53 |
homebranch => $branches[0]->branchcode(), |
54 |
} |
55 |
); |
56 |
$item->store(); |
57 |
|
35 |
my $hold = Koha::Hold->new( |
58 |
my $hold = Koha::Hold->new( |
36 |
{ |
59 |
{ |
|
|
60 |
biblionumber => $biblionumber, |
61 |
itemnumber => $item->id(), |
37 |
found => 'W', |
62 |
found => 'W', |
38 |
waitingdate => '2000-01-01', |
63 |
waitingdate => '2000-01-01', |
39 |
borrowernumber => $borrower->borrowernumber(), |
64 |
borrowernumber => $borrower->borrowernumber(), |
|
|
65 |
branchcode => $branches[1]->branchcode(), |
40 |
} |
66 |
} |
41 |
); |
67 |
); |
|
|
68 |
$hold->store(); |
69 |
|
70 |
$item = $hold->item(); |
71 |
|
42 |
my $hold_borrower = $hold->borrower(); |
72 |
my $hold_borrower = $hold->borrower(); |
43 |
ok( $hold_borrower, 'Got hold borrower' ); |
73 |
ok( $hold_borrower, 'Got hold borrower' ); |
44 |
is( $hold_borrower->borrowernumber(), $borrower->borrowernumber(), 'Hold borrower matches correct borrower' ); |
74 |
is( $hold_borrower->borrowernumber(), $borrower->borrowernumber(), 'Hold borrower matches correct borrower' ); |
45 |
|
75 |
|
46 |
C4::Context->set_preference( 'ReservesMaxPickUpDelay', '' ); |
76 |
C4::Context->set_preference( 'ReservesMaxPickUpDelay', '' ); |
47 |
my $dt = $hold->waiting_expires_on(); |
77 |
my $dt = $hold->waiting_expires_on(); |
48 |
is( $dt, undef, "Koha::Hold->waiting_expires_on returns undef if ReservesMaxPickUpDelay is not set"); |
78 |
is( $dt, undef, "Koha::Hold->waiting_expires_on returns undef if ReservesMaxPickUpDelay is not set" ); |
49 |
|
79 |
|
50 |
is( $hold->is_waiting, 1, 'The hold is waiting' ); |
80 |
is( $hold->is_waiting, 1, 'The hold is waiting' ); |
51 |
is( $hold->is_found, 1, 'The hold is found'); |
81 |
is( $hold->is_found, 1, 'The hold is found' ); |
52 |
ok( !$hold->is_in_transit, 'The hold is not in transit' ); |
82 |
ok( !$hold->is_in_transit, 'The hold is not in transit' ); |
53 |
|
83 |
|
54 |
C4::Context->set_preference( 'ReservesMaxPickUpDelay', '5' ); |
84 |
C4::Context->set_preference( 'ReservesMaxPickUpDelay', '5' ); |
55 |
$dt = $hold->waiting_expires_on(); |
85 |
$dt = $hold->waiting_expires_on(); |
56 |
is( $dt->ymd, "2000-01-06", "Koha::Hold->waiting_expires_on returns DateTime of waitingdate + ReservesMaxPickUpDelay if set"); |
86 |
is( $dt->ymd, "2000-01-06", |
|
|
87 |
"Koha::Hold->waiting_expires_on returns DateTime of waitingdate + ReservesMaxPickUpDelay if set" ); |
57 |
|
88 |
|
58 |
$hold->found('T'); |
89 |
$hold->found('T'); |
59 |
$dt = $hold->waiting_expires_on(); |
90 |
$dt = $hold->waiting_expires_on(); |
60 |
is( $dt, undef, "Koha::Hold->waiting_expires_on returns undef if found is not 'W' ( Set to 'T' )"); |
91 |
is( $dt, undef, "Koha::Hold->waiting_expires_on returns undef if found is not 'W' ( Set to 'T' )" ); |
61 |
isnt( $hold->is_waiting, 1, 'The hold is not waiting (T)' ); |
92 |
isnt( $hold->is_waiting, 1, 'The hold is not waiting (T)' ); |
62 |
is( $hold->is_found, 1, 'The hold is found'); |
93 |
is( $hold->is_found, 1, 'The hold is found' ); |
63 |
is( $hold->is_in_transit, 1, 'The hold is in transit' ); |
94 |
is( $hold->is_in_transit, 1, 'The hold is in transit' ); |
64 |
|
95 |
|
65 |
$hold->found(q{}); |
96 |
$hold->found(q{}); |
66 |
$dt = $hold->waiting_expires_on(); |
97 |
$dt = $hold->waiting_expires_on(); |
67 |
is( $dt, undef, "Koha::Hold->waiting_expires_on returns undef if found is not 'W' ( Set to empty string )"); |
98 |
is( $dt, undef, "Koha::Hold->waiting_expires_on returns undef if found is not 'W' ( Set to empty string )" ); |
68 |
isnt( $hold->is_waiting, 1, 'The hold is not waiting (W)' ); |
99 |
isnt( $hold->is_waiting, 1, 'The hold is not waiting (W)' ); |
69 |
is( $hold->is_found, 0, 'The hold is not found' ); |
100 |
is( $hold->is_found, 0, 'The hold is not found' ); |
70 |
ok( !$hold->is_in_transit, 'The hold is not in transit' ); |
101 |
ok( !$hold->is_in_transit, 'The hold is not in transit' ); |
71 |
|
102 |
|
|
|
103 |
# Test method is_cancelable |
104 |
$hold->found(undef); |
105 |
ok( $hold->is_cancelable(), "Unfound hold is cancelable" ); |
106 |
$hold->found('W'); |
107 |
ok( $hold->is_cancelable, "Waiting hold is cancelable" ); |
108 |
$hold->found('T'); |
109 |
ok( !$hold->is_cancelable, "In transit hold is not cancelable" ); |
110 |
|
111 |
# Test method is_at_destination |
112 |
$hold->found(undef); |
113 |
ok( !$hold->is_at_destination(), "Unfound hold cannot be at destination" ); |
114 |
$hold->found('T'); |
115 |
ok( !$hold->is_at_destination(), "In transit hold cannot be at destination" ); |
116 |
$hold->found('W'); |
117 |
ok( !$hold->is_at_destination(), "Waiting hold where hold branchcode is not the same as the item's holdingbranch is not at destination" ); |
118 |
$item->holdingbranch( $branches[1]->branchcode() ); |
119 |
ok( $hold->is_at_destination(), "Waiting hold where hold branchcode is the same as the item's holdingbranch is at destination" ); |
120 |
|
72 |
$schema->storage->txn_rollback(); |
121 |
$schema->storage->txn_rollback(); |
73 |
|
122 |
|
74 |
1; |
123 |
1; |
75 |
- |
|
|