|
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 => 5; |
22 |
use Test::More tests => 6; |
| 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 336-339
subtest 'GetRecords' => sub {
Link Here
|
| 336 |
ok($result,'There is a result'); |
336 |
ok($result,'There is a result'); |
| 337 |
|
337 |
|
| 338 |
$schema->storage->txn_rollback; |
338 |
$schema->storage->txn_rollback; |
| 339 |
} |
339 |
}; |
|
|
340 |
|
| 341 |
subtest 'GetPatronInfo paginated loans' => sub { |
| 342 |
plan tests => 7; |
| 343 |
|
| 344 |
$schema->storage->txn_begin; |
| 345 |
|
| 346 |
my $library = $builder->build_object({ |
| 347 |
class => 'Koha::Libraries', |
| 348 |
}); |
| 349 |
|
| 350 |
my $item1 = $builder->build_sample_item({ library => $library->branchcode }); |
| 351 |
my $item2 = $builder->build_sample_item({ library => $library->branchcode }); |
| 352 |
my $item3 = $builder->build_sample_item({ library => $library->branchcode }); |
| 353 |
my $patron = $builder->build_object({ |
| 354 |
class => 'Koha::Patrons', |
| 355 |
value => { |
| 356 |
branchcode => $library->branchcode, |
| 357 |
}, |
| 358 |
}); |
| 359 |
my $module = new Test::MockModule('C4::Context'); |
| 360 |
$module->mock('userenv', sub { { branch => $library->branchcode } }); |
| 361 |
my $date_due = DateTime->now->add(weeks => 2); |
| 362 |
my $issue1 = C4::Circulation::AddIssue($patron->unblessed, $item1->barcode, $date_due); |
| 363 |
my $date_due1 = Koha::DateUtils::dt_from_string( $issue1->date_due ); |
| 364 |
my $issue2 = C4::Circulation::AddIssue($patron->unblessed, $item2->barcode, $date_due); |
| 365 |
my $date_due2 = Koha::DateUtils::dt_from_string( $issue2->date_due ); |
| 366 |
my $issue3 = C4::Circulation::AddIssue($patron->unblessed, $item3->barcode, $date_due); |
| 367 |
my $date_due3 = Koha::DateUtils::dt_from_string( $issue3->date_due ); |
| 368 |
|
| 369 |
my $cgi = new CGI; |
| 370 |
|
| 371 |
$cgi->param( 'service', 'GetPatronInfo' ); |
| 372 |
$cgi->param( 'patron_id', $patron->borrowernumber ); |
| 373 |
$cgi->param( 'show_loans', '1' ); |
| 374 |
$cgi->param( 'loans_per_page', '2' ); |
| 375 |
$cgi->param( 'loans_page', '1' ); |
| 376 |
my $reply = C4::ILSDI::Services::GetPatronInfo($cgi); |
| 377 |
|
| 378 |
is($reply->{total_loans}, 3, 'total_loans == 3'); |
| 379 |
is(scalar @{ $reply->{loans}->{loan} }, 2, 'GetPatronInfo returned only 2 loans'); |
| 380 |
is($reply->{loans}->{loan}->[0]->{itemnumber}, $item3->itemnumber); |
| 381 |
is($reply->{loans}->{loan}->[1]->{itemnumber}, $item2->itemnumber); |
| 382 |
|
| 383 |
$cgi->param( 'loans_page', '2' ); |
| 384 |
$reply = C4::ILSDI::Services::GetPatronInfo($cgi); |
| 385 |
|
| 386 |
is($reply->{total_loans}, 3, 'total_loans == 3'); |
| 387 |
is(scalar @{ $reply->{loans}->{loan} }, 1, 'GetPatronInfo returned only 1 loan'); |
| 388 |
is($reply->{loans}->{loan}->[0]->{itemnumber}, $item1->itemnumber); |
| 389 |
|
| 390 |
$schema->storage->txn_rollback; |
| 391 |
}; |
| 340 |
- |
|
|