|
Lines 19-28
use Modern::Perl;
Link Here
|
| 19 |
|
19 |
|
| 20 |
use CGI qw ( -utf8 ); |
20 |
use CGI qw ( -utf8 ); |
| 21 |
|
21 |
|
| 22 |
use Test::More tests => 10; |
22 |
use Test::More tests => 11; |
| 23 |
use Test::MockModule; |
23 |
use Test::MockModule; |
| 24 |
use t::lib::Mocks; |
24 |
use t::lib::Mocks; |
| 25 |
use t::lib::TestBuilder; |
25 |
use t::lib::TestBuilder; |
|
|
26 |
use C4::Circulation; |
| 27 |
use C4::Reserves; |
| 26 |
|
28 |
|
| 27 |
use C4::Items qw( ModItemTransfer ); |
29 |
use C4::Items qw( ModItemTransfer ); |
| 28 |
use C4::Circulation; |
30 |
use C4::Circulation; |
|
Lines 37-42
my $schema = Koha::Database->schema;
Link Here
|
| 37 |
my $dbh = C4::Context->dbh; |
39 |
my $dbh = C4::Context->dbh; |
| 38 |
my $builder = t::lib::TestBuilder->new; |
40 |
my $builder = t::lib::TestBuilder->new; |
| 39 |
|
41 |
|
|
|
42 |
# Mock userenv |
| 43 |
local $SIG{__WARN__} = sub { warn $_[0] unless $_[0] =~ /redefined/ }; |
| 44 |
my $userenv; |
| 45 |
*C4::Context::userenv = \&Mock_userenv; |
| 46 |
|
| 47 |
# C4::Context->userenv |
| 48 |
sub Mock_userenv { |
| 49 |
return $userenv; |
| 50 |
} |
| 51 |
|
| 40 |
subtest 'AuthenticatePatron test' => sub { |
52 |
subtest 'AuthenticatePatron test' => sub { |
| 41 |
|
53 |
|
| 42 |
plan tests => 14; |
54 |
plan tests => 14; |
|
Lines 103-108
subtest 'AuthenticatePatron test' => sub {
Link Here
|
| 103 |
$schema->storage->txn_rollback; |
115 |
$schema->storage->txn_rollback; |
| 104 |
}; |
116 |
}; |
| 105 |
|
117 |
|
|
|
118 |
subtest 'GetPatronInfo test for holds' => sub { |
| 119 |
plan tests => 8; |
| 120 |
|
| 121 |
$schema->storage->txn_begin; |
| 122 |
$schema->resultset( 'Issue' )->delete_all; |
| 123 |
$schema->resultset( 'Reserve' )->delete_all; |
| 124 |
$schema->resultset( 'Borrower' )->delete_all; |
| 125 |
$schema->resultset( 'Category' )->delete_all; |
| 126 |
$schema->resultset( 'Item' )->delete_all; # 'Branch' deps. on this |
| 127 |
$schema->resultset( 'Branch' )->delete_all; |
| 128 |
|
| 129 |
# Configure Koha to enable ILS-DI server |
| 130 |
t::lib::Mocks::mock_preference( 'ILS-DI', 1 ); |
| 131 |
|
| 132 |
# Set up a library/branch for our user to belong to: |
| 133 |
my $branchcode = 'T_ILSDI'; |
| 134 |
my $lib = $builder->build( { |
| 135 |
source => 'Branch', |
| 136 |
value => { |
| 137 |
branchcode => $branchcode, |
| 138 |
} |
| 139 |
} ); |
| 140 |
|
| 141 |
# Create a new category for user to belong to: |
| 142 |
my $cat = $builder->build( { |
| 143 |
source => 'Category', |
| 144 |
value => { |
| 145 |
category_type => 'A', |
| 146 |
BlockExpiredPatronOpacActions => -1, |
| 147 |
} |
| 148 |
} ); |
| 149 |
|
| 150 |
# Create new users: |
| 151 |
my $brwr = $builder->build( { |
| 152 |
source => 'Borrower', |
| 153 |
value => { |
| 154 |
categorycode => $cat->{'categorycode'}, |
| 155 |
branchcode => $lib->{'branchcode'}, |
| 156 |
} |
| 157 |
} ); |
| 158 |
my $brwr2 = $builder->build( { |
| 159 |
source => 'Borrower', |
| 160 |
value => { |
| 161 |
categorycode => $cat->{'categorycode'}, |
| 162 |
branchcode => $lib->{'branchcode'}, |
| 163 |
} |
| 164 |
} ); |
| 165 |
my $brwr3 = $builder->build( { |
| 166 |
source => 'Borrower', |
| 167 |
value => { |
| 168 |
categorycode => $cat->{'categorycode'}, |
| 169 |
branchcode => $lib->{'branchcode'}, |
| 170 |
} |
| 171 |
} ); |
| 172 |
|
| 173 |
|
| 174 |
# Place a loan |
| 175 |
my $biblio = $builder->build( { source => 'Biblio', } ); |
| 176 |
my $item = $builder->build( { source => 'Item', value => { biblionumber => $biblio->{biblionumber}, barcode => "mybarcode"} } ); |
| 177 |
my $biblioitem = $builder->build( { source => 'Biblioitem', value => { biblionumber => $biblio->{biblionumber} } } ); |
| 178 |
$userenv = { flags => 1, id => $brwr->{borrowernumber}, branch => 'T_ILSDI' }; |
| 179 |
my $issue = AddIssue($brwr, $item->{barcode}); |
| 180 |
|
| 181 |
# Prepare and send web request for IL-SDI server: |
| 182 |
my $query = new CGI; |
| 183 |
$query->param( 'service', 'GetPatronInfo' ); |
| 184 |
$query->param( 'patron_id', $brwr->{'borrowernumber'} ); |
| 185 |
$query->param( 'show_attributes', '0' ); |
| 186 |
$query->param( 'show_loans', '1' ); |
| 187 |
my $reply = C4::ILSDI::Services::GetPatronInfo( $query ); |
| 188 |
|
| 189 |
# Check that this loan is not on hold |
| 190 |
is ( $reply->{loans}->{loan}[0]->{recordonhold}, "0", "Record is not on hold"); |
| 191 |
is ( $reply->{loans}->{loan}[0]->{itemonhold}, "0", "Item is not on hold"); |
| 192 |
|
| 193 |
# Add a hold on the biblio |
| 194 |
my $biblioreserve = AddReserve($branchcode, $brwr2->{'borrowernumber'}, $biblio->{biblionumber}); |
| 195 |
|
| 196 |
# Check that it is on hold on biblio level |
| 197 |
$reply = C4::ILSDI::Services::GetPatronInfo( $query ); |
| 198 |
is ( $reply->{loans}->{loan}[0]->{recordonhold}, "1", "Record is on hold"); |
| 199 |
is ( $reply->{loans}->{loan}[0]->{itemonhold}, "0", "Item is on hold"); |
| 200 |
|
| 201 |
# Delete holds |
| 202 |
$schema->resultset( 'Reserve' )->delete_all; |
| 203 |
|
| 204 |
# Add a hold on the item |
| 205 |
my $itemreserve = AddReserve($branchcode, $brwr2->{'borrowernumber'}, $biblio->{biblionumber}, |
| 206 |
[$biblio->{biblionumber}], undef, undef, undef, undef, undef, $item->{itemnumber}); |
| 207 |
|
| 208 |
# When a specific item has a reserve, the item is on hold as well as the record |
| 209 |
$reply = C4::ILSDI::Services::GetPatronInfo( $query ); |
| 210 |
is ( $reply->{loans}->{loan}[0]->{recordonhold}, "1", "Record is on hold"); |
| 211 |
is ( $reply->{loans}->{loan}[0]->{itemonhold}, "1", "Item is on hold"); |
| 212 |
|
| 213 |
# Add another hold on the biblio |
| 214 |
$biblioreserve = AddReserve($branchcode, $brwr3->{'borrowernumber'}, $biblio->{biblionumber}); |
| 215 |
|
| 216 |
# Check that there are 2 holds on the biblio and 1 on this specific item |
| 217 |
$reply = C4::ILSDI::Services::GetPatronInfo( $query ); |
| 218 |
is ( $reply->{loans}->{loan}[0]->{recordonhold}, "2", "Record is on hold twice"); |
| 219 |
is ( $reply->{loans}->{loan}[0]->{itemonhold}, "1", "Item is on hold"); |
| 220 |
|
| 221 |
# Cleanup |
| 222 |
$schema->storage->txn_rollback; |
| 223 |
|
| 224 |
}; |
| 106 |
|
225 |
|
| 107 |
subtest 'GetPatronInfo/GetBorrowerAttributes test for extended patron attributes' => sub { |
226 |
subtest 'GetPatronInfo/GetBorrowerAttributes test for extended patron attributes' => sub { |
| 108 |
|
227 |
|
| 109 |
- |
|
|