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