Bug 22421: Add tests for new constraints

Test plan:
* Read the updated tests and verify that they make sense and do not
remove anything previously tested for.

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Victor Grousset/tuxayo <victor@tuxayo.net>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Katrin Fischer <katrin.fischer@bsz-bw.de>
This commit is contained in:
Martin Renvoize 2019-06-06 12:26:47 +01:00 committed by Katrin Fischer
parent 48e7aad1f1
commit 311d3be1c5
No known key found for this signature in database
GPG Key ID: 0EF6E2C03357A834
1 changed files with 27 additions and 15 deletions

View File

@ -25,7 +25,7 @@ use Test::MockModule;
use DateTime;
use C4::Circulation qw( AddRenewal CanBookBeRenewed LostItem AddIssue AddReturn );
use C4::Circulation qw( AddRenewal CanBookBeRenewed LostItem AddIssue AddReturn MarkIssueReturned );
use Koha::Account;
use Koha::Account::Lines;
use Koha::Account::Offsets;
@ -448,9 +448,9 @@ subtest 'apply() tests' => sub {
$schema->storage->txn_rollback;
};
subtest 'Keep account info when related patron, staff, item or cash_register is deleted' => sub {
subtest 'Keep account info when related patron, staff, item, issue or cash_register is deleted' => sub {
plan tests => 4;
plan tests => 7;
$schema->storage->txn_begin;
@ -460,24 +460,36 @@ subtest 'Keep account info when related patron, staff, item or cash_register is
my $issue = $builder->build_object(
{
class => 'Koha::Checkouts',
value => { itemnumber => $item->itemnumber }
value => { itemnumber => $item->itemnumber, borrowernumber => $patron->borrowernumber }
}
);
my $register = $builder->build_object({ class => 'Koha::Cash::Registers' });
my $line = Koha::Account::Line->new(
{
borrowernumber => $patron->borrowernumber,
manager_id => $staff->borrowernumber,
itemnumber => $item->itemnumber,
debit_type_code => "OVERDUE",
status => "RETURNED",
amount => 10,
interface => 'commandline',
register_id => $register->id
})->store;
{
borrowernumber => $patron->borrowernumber,
manager_id => $staff->borrowernumber,
itemnumber => $item->itemnumber,
debit_type_code => "OVERDUE",
issue_id => $issue->id,
old_issue_id => undef,
status => "RETURNED",
amount => 10,
interface => 'commandline',
register_id => $register->id
}
)->store;
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 archived");
is( $line->old_issue_id, $issue->id, "The account line link to the archived issue");
my $old_issue = Koha::Old::Checkouts->find($issue->id);
$old_issue->delete;
$line = $line->get_from_storage;
is( $line->old_issue_id, undef, "The account line should not be deleted when the related old_issue is delete");
$issue->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");