From 8f82db2d535f69762c8d216e337d86815bc9cc65 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Mon, 10 May 2021 09:12:38 +0100 Subject: [PATCH] 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 --- t/db_dependent/Koha/Item/Transfer.t | 46 ++++++++++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/Koha/Item/Transfer.t b/t/db_dependent/Koha/Item/Transfer.t index 22b82be628..54b8208419 100755 --- a/t/db_dependent/Koha/Item/Transfer.t +++ b/t/db_dependent/Koha/Item/Transfer.t @@ -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; -- 2.31.1