From a7eeaf95b74cb445fc121bf9a331d2bcbae4389f Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Wed, 27 Feb 2019 12:03:25 +0000 Subject: [PATCH] Bug 22421: Add tests for new constraints --- t/db_dependent/Koha/Account/Lines.t | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/t/db_dependent/Koha/Account/Lines.t b/t/db_dependent/Koha/Account/Lines.t index 31543dc4d5..deef58e3ef 100755 --- a/t/db_dependent/Koha/Account/Lines.t +++ b/t/db_dependent/Koha/Account/Lines.t @@ -22,6 +22,8 @@ use Modern::Perl; use Test::More tests => 6; use Test::Exception; +use C4::Circulation qw/MarkIssueReturned/; + use Koha::Account; use Koha::Account::Lines; use Koha::Account::Offsets; @@ -273,9 +275,9 @@ subtest 'apply() tests' => sub { $schema->storage->txn_rollback; }; -subtest 'Keep account info when related patron, staff or item is deleted' => sub { +subtest 'Keep account info when related patron, staff, item or issue is deleted' => sub { - plan tests => 3; + plan tests => 4; $schema->storage->txn_begin; @@ -288,11 +290,14 @@ subtest 'Keep account info when related patron, staff or item is deleted' => sub value => { itemnumber => $item->itemnumber } } ); + my $line = Koha::Account::Line->new( { borrowernumber => $patron->borrowernumber, manager_id => $staff->borrowernumber, itemnumber => $item->itemnumber, + issue_id => $issue->issue_id, + old_issue_id => undef, accounttype => "F", amount => 10, })->store; @@ -309,6 +314,15 @@ subtest 'Keep account info when related patron, staff or item is deleted' => sub $line = $line->get_from_storage; is( $line->borrowernumber, undef, "The account line should not be deleted when the related patron is delete"); + my $issue_id = $issue->issue_id; + MarkIssueReturned($patron->borrowernumber, $item->itemnumber, undef, 0 ); + $line = $line->get_from_storage; + is( $line->issue_id, undef, "The account line should not be deleted when the related issue is delete"); + + my $old_issue = Koha::Old::Checkouts->find($issue_id); + $old_issue->delete; + is( $line->old_issue_id, undef, "The account line should not be deleted when the related old_issue is deleted"); + $schema->storage->txn_rollback; }; -- 2.20.1