Bug 25998: Add Unit Tests

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
(cherry picked from commit e9927e7290)

Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
This commit is contained in:
Martin Renvoize 2020-07-17 08:01:06 +01:00 committed by Lucas Gass
parent a224b11688
commit 6be906d1d6
1 changed files with 43 additions and 1 deletions

View File

@ -19,7 +19,7 @@
use Modern::Perl;
use Test::More tests => 12;
use Test::More tests => 13;
use Test::Exception;
use Test::MockModule;
@ -105,6 +105,48 @@ subtest 'item() tests' => sub {
$schema->storage->txn_rollback;
};
subtest 'library() tests' => sub {
plan tests => 4;
$schema->storage->txn_begin;
my $library = $builder->build_object( { class => 'Koha::Libraries' } );
my $patron = $builder->build( { source => 'Borrower' } );
my $line = Koha::Account::Line->new(
{
borrowernumber => $patron->{borrowernumber},
branchcode => $library->branchcode,
debit_type_code => "OVERDUE",
status => "RETURNED",
amount => 10,
interface => 'commandline',
}
)->store;
my $account_line_library = $line->library;
is( ref($account_line_library),
'Koha::Library',
'Koha::Account::Line->library should return a Koha::Library' );
is(
$line->branchcode,
$account_line_library->branchcode,
'Koha::Account::Line->library should return the correct library'
);
# Test ON DELETE SET NULL
$library->delete;
my $found = Koha::Account::Lines->find( $line->accountlines_id );
ok( $found, "Koha::Account::Line not deleted when the linked library is deleted" );
is( $found->library, undef,
'Koha::Account::Line->library should return undef if linked library has been deleted'
);
$schema->storage->txn_rollback;
};
subtest 'is_credit() and is_debit() tests' => sub {
plan tests => 4;