|
Lines 19-25
use Modern::Perl;
Link Here
|
| 19 |
|
19 |
|
| 20 |
use CGI qw ( -utf8 ); |
20 |
use CGI qw ( -utf8 ); |
| 21 |
|
21 |
|
| 22 |
use Test::More tests => 12; |
22 |
use Test::More tests => 13; |
| 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; |
|
Lines 123-128
subtest 'AuthenticatePatron test' => sub {
Link Here
|
| 123 |
$schema->storage->txn_rollback; |
123 |
$schema->storage->txn_rollback; |
| 124 |
}; |
124 |
}; |
| 125 |
|
125 |
|
|
|
126 |
subtest 'GetPatronInfo test for holds' => sub { |
| 127 |
plan tests => 8; |
| 128 |
|
| 129 |
$schema->storage->txn_begin; |
| 130 |
$schema->resultset( 'Issue' )->delete_all; |
| 131 |
$schema->resultset( 'Reserve' )->delete_all; |
| 132 |
$schema->resultset( 'Borrower' )->delete_all; |
| 133 |
$schema->resultset( 'Category' )->delete_all; |
| 134 |
$schema->resultset( 'Item' )->delete_all; # 'Branch' deps. on this |
| 135 |
$schema->resultset( 'Branch' )->delete_all; |
| 136 |
|
| 137 |
# Configure Koha to enable ILS-DI server |
| 138 |
t::lib::Mocks::mock_preference( 'ILS-DI', 1 ); |
| 139 |
|
| 140 |
my $library = $builder->build_object({ |
| 141 |
class => 'Koha::Libraries', |
| 142 |
}); |
| 143 |
|
| 144 |
# Create new users: |
| 145 |
my $brwr = $builder->build_object( { |
| 146 |
class => 'Koha::Patrons', |
| 147 |
value => { |
| 148 |
branchcode => $library->branchcode, |
| 149 |
} |
| 150 |
} ); |
| 151 |
my $brwr2 = $builder->build_object( { |
| 152 |
class => 'Koha::Patrons', |
| 153 |
value => { |
| 154 |
branchcode => $library->branchcode, |
| 155 |
} |
| 156 |
} ); |
| 157 |
my $brwr3 = $builder->build_object( { |
| 158 |
class => 'Koha::Patrons', |
| 159 |
value => { |
| 160 |
branchcode => $library->branchcode, |
| 161 |
} |
| 162 |
} ); |
| 163 |
|
| 164 |
my $module = Test::MockModule->new('C4::Context'); |
| 165 |
$module->mock('userenv', sub { { branch => $library->branchcode } }); |
| 166 |
|
| 167 |
# Place a loan |
| 168 |
my $biblio = $builder->build_object( { class => 'Koha::Biblios' } ); |
| 169 |
my $itemtype = $builder->build_object({ class => 'Koha::ItemTypes' }); |
| 170 |
my $biblioitem = $builder->build_object( { class => 'Koha::Biblioitems', value => { biblionumber => $biblio->biblionumber } } ); |
| 171 |
my $item = $builder->build_sample_item({ biblionumber => $biblio->biblionumber, library => $library->branchcode, itype => $itemtype->itemtype }); |
| 172 |
my $issue = AddIssue($brwr, $item->barcode); |
| 173 |
|
| 174 |
# Prepare and send web request for IL-SDI server: |
| 175 |
my $query = new CGI; |
| 176 |
$query->param( 'service', 'GetPatronInfo' ); |
| 177 |
$query->param( 'patron_id', $brwr->borrowernumber ); |
| 178 |
$query->param( 'show_loans', '1' ); |
| 179 |
my $reply = C4::ILSDI::Services::GetPatronInfo( $query ); |
| 180 |
|
| 181 |
# Check that this loan is not on hold |
| 182 |
is ( $reply->{loans}->{loan}[0]->{recordonhold}, "0", "Record is not on hold"); |
| 183 |
is ( $reply->{loans}->{loan}[0]->{itemonhold}, "0", "Item is not on hold"); |
| 184 |
|
| 185 |
# Place a loan |
| 186 |
# Add a hold on the biblio |
| 187 |
my $biblioreserve = AddReserve({ branchcode => $library->branchcode, borrowernumber => $brwr2->borrowernumber, biblionumber => $biblio->biblionumber }); |
| 188 |
|
| 189 |
# Check that it is on hold on biblio level |
| 190 |
$reply = C4::ILSDI::Services::GetPatronInfo( $query ); |
| 191 |
is ( $reply->{loans}->{loan}[0]->{recordonhold}, "1", "Record is on hold"); |
| 192 |
is ( $reply->{loans}->{loan}[0]->{itemonhold}, "0", "Item is on hold"); |
| 193 |
|
| 194 |
# Delete holds |
| 195 |
$schema->resultset( 'Reserve' )->delete_all; |
| 196 |
|
| 197 |
# Add a hold on the item |
| 198 |
my $itemreserve = AddReserve({ |
| 199 |
branchcode => $library->branchcode, |
| 200 |
borrowernumber => $brwr2->borrowernumber, |
| 201 |
biblionumber => $biblio->biblionumber, |
| 202 |
itemnumber => $item->itemnumber |
| 203 |
}); |
| 204 |
|
| 205 |
# When a specific item has a reserve, the item is on hold as well as the record |
| 206 |
$reply = C4::ILSDI::Services::GetPatronInfo( $query ); |
| 207 |
is ( $reply->{loans}->{loan}[0]->{recordonhold}, "1", "Record is on hold"); |
| 208 |
is ( $reply->{loans}->{loan}[0]->{itemonhold}, "1", "Item is on hold"); |
| 209 |
|
| 210 |
# Add another hold on the biblio |
| 211 |
$biblioreserve = AddReserve({ branchcode => $library->branchcode, borrowernumber => $brwr3->borrowernumber, biblionumber => $biblio->biblionumber }); |
| 212 |
|
| 213 |
# Check that there are 2 holds on the biblio and 1 on this specific item |
| 214 |
$reply = C4::ILSDI::Services::GetPatronInfo( $query ); |
| 215 |
is ( $reply->{loans}->{loan}[0]->{recordonhold}, "2", "Record is on hold twice"); |
| 216 |
is ( $reply->{loans}->{loan}[0]->{itemonhold}, "1", "Item is on hold"); |
| 217 |
|
| 218 |
# Cleanup |
| 219 |
$schema->storage->txn_rollback; |
| 220 |
|
| 221 |
}; |
| 126 |
|
222 |
|
| 127 |
subtest 'GetPatronInfo/GetBorrowerAttributes test for extended patron attributes' => sub { |
223 |
subtest 'GetPatronInfo/GetBorrowerAttributes test for extended patron attributes' => sub { |
| 128 |
|
224 |
|
| 129 |
- |
|
|