From f687f50dc397c2de2dcb1a983237a7f73c7db4be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nazl=C4=B1=20=C3=87etin?= Date: Fri, 23 Nov 2018 11:56:45 +0000 Subject: [PATCH] Bug 19489: (Improvements in Unit test and Koha::Account::Line->issue method) Signed-off-by: Nick Clemens --- Koha/Account/Line.pm | 16 +++++++++++++++ t/db_dependent/Koha/Account/Lines.t | 41 ++++++++++++++++++++++++++++++++++++- 2 files changed, 56 insertions(+), 1 deletion(-) diff --git a/Koha/Account/Line.pm b/Koha/Account/Line.pm index 3573e604e6..b599d6a78e 100644 --- a/Koha/Account/Line.pm +++ b/Koha/Account/Line.pm @@ -51,6 +51,22 @@ sub item { return Koha::Item->_new_from_dbic( $rs ); } +=head3 issue + +Return the issue linked to this account line if exists + +=cut + +sub issue { + my ( $self ) = @_; + + return unless $self->issue_id ; + + my $issue = Koha::Checkouts->find( $self->issue_id ); + $issue = Koha::Old::Checkouts->find( $self->issue_id ) unless $issue; + return $issue; +} + =head3 void $payment_accountline->void(); diff --git a/t/db_dependent/Koha/Account/Lines.t b/t/db_dependent/Koha/Account/Lines.t index eb8dfdd1c0..bdf42f873a 100755 --- a/t/db_dependent/Koha/Account/Lines.t +++ b/t/db_dependent/Koha/Account/Lines.t @@ -19,7 +19,7 @@ use Modern::Perl; -use Test::More tests => 4; +use Test::More tests => 5; use Test::Exception; use Koha::Account; @@ -268,3 +268,42 @@ subtest 'apply() tests' => sub { $schema->storage->txn_rollback; }; + +subtest 'issue() tests' => sub { + + plan tests => 5; + + $schema->storage->txn_begin; + + my $library = $builder->build( { source => 'Branch' } ); + my $patron = $builder->build( { source => 'Borrower' } ); + my $item = $builder->build( { source => 'Item' } ); + + my $checkout = Koha::Checkout->new( + { borrowernumber => $patron->{borrowernumber}, + itemnumber => $item->{itemnumber}, + branchcode => $library->{branchcode}, + })->store; + + my $line = Koha::Account::Line->new( + { + borrowernumber => $patron->{borrowernumber}, + itemnumber => $item->{itemnumber}, + issue_id => $checkout->issue_id, + accounttype => "F", + amount => 10, + })->store; + + my $line_issue = $line->issue; + is( ref($line_issue), 'Koha::Checkout', 'Result type is correct' ); + is( $line_issue->issue_id, $checkout->issue_id, 'Koha::Account::Line->issue should return the correct issue'); + + my ( $returned, undef, $old_checkout) = C4::Circulation::AddReturn( $item->{barcode} ,$library->{branchcode} ); + is( $returned, 1, 'The item should have been returned' ); + + my $old_line_issue = $line->issue; + is( ref($old_line_issue), 'Koha::Old::Checkout', 'Result type is correct' ); + is( $old_line_issue->issue_id, $old_checkout->issue_id, 'Koha::Account::Line->issue should return the correct old_issue' ); + + $schema->storage->txn_rollback; +}; -- 2.11.0