Bug 24434: Add Unit Tests for relations

This patch adds unit tests for the newly introduced to_library (and also
add the missing test for the existing from_library).

Signed-off-by: Victor Grousset/tuxayo <victor@tuxayo.net>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
This commit is contained in:
Martin Renvoize 2021-05-10 09:12:38 +01:00 committed by Jonathan Druart
parent b031ec5845
commit fb413a87d1

View file

@ -24,7 +24,7 @@ use Koha::DateUtils;
use t::lib::TestBuilder;
use Test::More tests => 5;
use Test::More tests => 7;
use Test::Exception;
my $schema = Koha::Database->new->schema;
@ -52,6 +52,50 @@ subtest 'item relation tests' => sub {
$schema->storage->txn_rollback;
};
subtest 'from_library relation tests' => sub {
plan tests => 2;
$schema->storage->txn_begin;
my $library = $builder->build_object( { class => 'Koha::Libraries' } );
my $transfer = $builder->build_object(
{
class => 'Koha::Item::Transfers',
value => {
frombranch => $library->branchcode,
}
}
);
my $from_library = $transfer->from_library;
is( ref( $from_library ), 'Koha::Library', 'Koha::Item::Transfer->from_library should return a Koha::Library' );
is( $from_library->branchcode, $library->branchcode, 'Koha::Item::Transfer->from_library should return the correct library' );
$schema->storage->txn_rollback;
};
subtest 'to_library relation tests' => sub {
plan tests => 2;
$schema->storage->txn_begin;
my $library = $builder->build_object( { class => 'Koha::Libraries' } );
my $transfer = $builder->build_object(
{
class => 'Koha::Item::Transfers',
value => {
tobranch => $library->branchcode,
}
}
);
my $to_library = $transfer->to_library;
is( ref( $to_library ), 'Koha::Library', 'Koha::Item::Transfer->to_library should return a Koha::Library' );
is( $to_library->branchcode, $library->branchcode, 'Koha::Item::Transfer->to_library should return the correct library' );
$schema->storage->txn_rollback;
};
subtest 'transit tests' => sub {
plan tests => 7;