@@ -, +, @@ prove t/db_dependent/Koha/Patrons.t --- Koha/Patron.pm | 16 +++++++++++++--- t/db_dependent/Koha/Patrons.t | 15 ++++++++++++--- 2 files changed, 25 insertions(+), 6 deletions(-) --- a/Koha/Patron.pm +++ a/Koha/Patron.pm @@ -449,6 +449,18 @@ sub add_enrolment_fee_if_needed { return $enrolment_fee || 0; } +=head3 get_issues + +my $issues = $patron->get_issues + +=cut + +sub get_issues { + my ($self) = @_; + my $issues = $self->_result->issues; + return Koha::Issues->_new_from_dbic( $issues ); +} + =head3 get_overdues my $overdue_items = $patron->get_overdues @@ -460,16 +472,14 @@ Return the overdued items sub get_overdues { my ($self) = @_; my $dtf = Koha::Database->new->schema->storage->datetime_parser; - my $issues = Koha::Issues->search( + return $self->get_issues->search( { - 'me.borrowernumber' => $self->borrowernumber, 'me.date_due' => { '<' => $dtf->format_datetime(dt_from_string) }, }, { prefetch => { item => { biblio => 'biblioitems' } }, } ); - return $issues; } =head3 type --- a/t/db_dependent/Koha/Patrons.t +++ a/t/db_dependent/Koha/Patrons.t @@ -516,8 +516,8 @@ subtest 'search_patrons_to_anonymise & anonymise_issue_history' => sub { Koha::Patrons->find( $userenv_patron->{borrowernumber})->delete; }; -subtest 'get_overdues' => sub { - plan tests => 4; +subtest 'get_issues + get_overdues' => sub { + plan tests => 8; my $library = $builder->build( { source => 'Branch' } ); my ($biblionumber_1) = AddBiblio( MARC::Record->new, '' ); @@ -559,8 +559,13 @@ subtest 'get_overdues' => sub { } ); + $patron = Koha::Patrons->find( $patron->{borrowernumber} ); + my $issues = $patron->get_issues; + is( $issues->count, 0, 'get_issues should not return any issues for that patron' ); + is( ref($issues), 'Koha::Issues', 'get_issues should return a Koha::Issues object' ); + # Not sure how this is useful, but AddIssue pass this variable to different other subroutines - $patron = GetMember( borrowernumber => $patron->{borrowernumber} ); + $patron = GetMember( borrowernumber => $patron->borrowernumber ); my $module = new Test::MockModule('C4::Context'); $module->mock( 'userenv', sub { { branch => $library->{branchcode} } } ); @@ -570,6 +575,10 @@ subtest 'get_overdues' => sub { AddIssue( $patron, $item_3->{barcode} ); $patron = Koha::Patrons->find( $patron->{borrowernumber} ); + $issues = $patron->get_issues; + is( $issues->count, 3, 'get_issues should return 3 issues for that patron' ); + is( ref($issues), 'Koha::Issues', 'get_issues should return a Koha::Issues object' ); + my $overdues = $patron->get_overdues; is( $overdues->count, 2, 'Patron should have 2 overdues'); is( ref($overdues), 'Koha::Issues', 'Koha::Patron->get_overdues should return Koha::Issues' ); --