From 0f0be0650e4e29cc061791cfe93401552e35a3fc Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Fri, 21 Dec 2018 11:59:41 +0000 Subject: [PATCH] Bug 22008: Add tests for new constraints --- t/db_dependent/Koha/Account/Lines.t | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/t/db_dependent/Koha/Account/Lines.t b/t/db_dependent/Koha/Account/Lines.t index f7f0c16554..284c1b692e 100755 --- a/t/db_dependent/Koha/Account/Lines.t +++ b/t/db_dependent/Koha/Account/Lines.t @@ -273,26 +273,43 @@ subtest 'apply() tests' => sub { $schema->storage->txn_rollback; }; -subtest 'Keep account info when a patron is deleted' => sub { +subtest 'Keep account info when related patron, staff, item or issue is deleted' => sub { - plan tests => 2; + plan tests => 4; $schema->storage->txn_begin; my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); + my $staff = $builder->build_object( { class => 'Koha::Patrons' } ); my $item = $builder->build_object({ class => 'Koha::Items' }); + my $issue = $builder->build_object( + { + class => 'Koha::Checkout', + 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 accounttype => "F", amount => 10, })->store; + $issue->delete; + $line = $line->get_from_storage; + is( $line->issue_id, undef, "The account line should not be deleted when the related issue is delete"); + $item->delete; $line = $line->get_from_storage; is( $line->itemnumber, undef, "The account line should not be deleted when the related item is delete"); + $staff->delete; + $line = $line->get_from_storage; + is( $line->manager_id, undef, "The account line should not be deleted when the related staff is delete"); + $patron->delete; $line = $line->get_from_storage; is( $line->borrowernumber, undef, "The account line should not be deleted when the related patron is delete"); -- 2.20.1